A simple 2-player game: deal one face-up card to each player; highest rank wins, equal ranks tie. You’ll build Card and Deck classes in a single .cpp file and play multiple games, tracking player stats. If requested games exceed available cards, Deck::deal() must throw, and main must catch and report the error. Use a vector (not an array) to store cards.
- Classes
class CardwithCard(char rank, char suit),void display(),int compare(Card)(1 = win, 0 = tie, −1 = lose).class DeckwithDeck(),Card deal(),void display(),void shuffle(),bool isEmpty().
- Struct
struct Player { string name; int win, lose, tie; };Track stats for each player.
- Program flow
- Create deck
- Ask two names
- Ask how many games
- Display original (unshuffled) deck
- Shuffle
- Display shuffled deck
- Play N games, print winner/tie each game
- Print final stats
- Exception
- Throw in
Deck::deal()when deck is empty; catch inmain.
- Throw in
- File structure
- One source file (
war.cpp). Usestd::vector<Card>insideDeck.
- One source file (
g++ war.cpp -o war
./war