Question: Writ a C++ program to simulat a simpl card gam btwn two playrs. Th gam should procd as follows: Th 52 cards in a dck

Writ a C++ program to simulat a simpl card gam btwn two playrs. Th gam should procd as follows: Th 52 cards in a dck of cards ar shuffld and ach playr draws thr cards from th top of th dck. Th rmaining cards ar placd in a pil fac-down btwn th two playrs. Playrs thn slct on of th thr cards in hand and simultanously plac th chosn card fac-up on th gam tabl. Th playr who placs th highst ranking card on th tabl collcts both cards and adds thm to thir pil (scor). If both cards hav th sam valu th hand is a draw and no points ar accumulatd. Following th compltion of a hand, ach playr draws th top card from th dck to add to thir hand. Play continus until all cards hav bn playd. Th winnr is th playr with th most points at gams nd.

You will us a standard dck of 52 cards whr thr ar thirtn cards from ach of four suits: harts, spads, diamonds, and clubs. Th thirtn cards in point ordr ar th 2-10 numbrd cards, th fac cards (Jack, Qun, King), and th Ac card. Points ar distributd as follows: Ac=15, fac cards=10, all othr cards count as thir numric valu.

1. Your program must b split into 7 fils. Thr will b 3 classs (ach with sparat intrfac and implmntation fils), and a drivr fil. Th rquirmnts for ths ar spcifid blow:

1. Your program must b split into 7 fils. Thr will b 3 classs (ach with sparat intrfac and implmntation fils), and a drivr fil. Th rquirmnts for ths ar spcifid blow:

A.Th Card class This class rprsnts an individual card

Fils must b namd card.h and card.cpp

Class must b namd Card

Th intrfac (hadr fil) is providd. ( Blow **** )

You should implmnt th intrfac fil in a .cpp implmntation fil

All data mmbrs must b of th typ spcifid in th hadr fil

All mmbr functions in th intrfac fil must b implmntd as dclard Howvr you hav flxibility in how you choos to implmnt ach

B.Th Dck class This is rprsnts th dck of cards

Fils must b namd dck.h and dck.cpp

Class must b namd Dck

Th intrfac (hadr fil) is providd. ( Blow **** )

You should implmnt th intrfac fil in a .cpp implmntation fil

All data mmbrs must b of th typ spcifid in th hadr fil

All mmbr functions in th intrfac fil must b implmntd as dclard Howvr you hav flxibility in how you choos to implmnt ach

C) A drivr, or clint, fil

Must b namd proj4.cpp

Must contain th lin srand(1000); as th first lin of th main function

Must instantiat th card dck and th playrs, and control th gam play, printing out th hand, scors, outcom (winnr, losr, draw), and final winnr and scor as shown in th sampl output.

Output for this program must clarly and natly show that th program works and that it works corrctly. Your output should:

Display th ntir dck of cards at th bginning of th gam, and aftr it has bn shuffld

For ach hand, show th cards and scor of ach playr bfor th play, th card ach playr plays, and th cards and scor of ach playr aftr th play (but bfor th nxt card is drawn)

At th nd show th winnr of th gam and th winning scor.

Blow is a sampl output of a gams start and som lat gam hands as th gam nds

2. Sampl output: a) Display of dck both bfor and aftr shuffling, and play of first coupl of hands. Individual cards ar output as card, suit, valu. xampl: 8 [8] is th 8 of spads which is worth 8 points; K [10] is th King of harts with valu 10. Not: dpnding on how you implmnt dck shuffling, th cards playd may, or may not, match thos blow.

Writ a C++ program to simulat a simpl card gam btwn two

b) Last fw hands of th gam. Not: Th dck is xhaustd aftr hand 23. Play continus until payrs ar out of cards.

playrs. Th gam should procd as follows: Th 52 cards in a

*** if this dosnt work Us H for Harts, C for Clubs, D for Diamonds, and S for Spads.***

Not: You can us th following statmnts to print suit symbols:

cout

cout

cout

cout

*** do not modifiy Hadr Fils !! ****

/* Card.h */

#ifndef CARD_H

#define CARD_H

#include

using std::ostream;

// Enum type that represents the card suits

enum suit {clubs, hearts, spades, diamonds};

class Card{

public:

//default constructor - required

Card();

//constructor that takes a card's face (represented an integer) and suit

// card face example: Ace=0, 2=1, 3=2, ... Q=11, K=12 or some other ordering

Card (int face, suit st);

// overload the

friend ostream& operator

// compare and return true if *this has a lesser point value than cd, false otherwise

bool operator

// compare and return true if *this has a larger point value than cd, false otherwise

bool operator > (const Card& cd) const;

// compare and return true if *this has the same point value as cd, false otherwise

bool operator== (const Card& cd) const;

// return the point value of the card: Ace: 15, Faces: 10, Numbers: the number

int getPointValue() const;

private:

suit cardSuit; // card's suit

int cardFace; // card's face

int pointValue; // card's point value (derived from face)

};

#endif

/* Deck.h ******* . */

#ifndef DECK_H

#define DECK_H

#include

#include "card.h"

using std::ostream;

class Deck{

public:

// default constructor

Deck();

// Remove the top card from the deck and return it.

Card dealCard();

// Shuffle the cards in the deck

void Shuffle();

// return true if there are no more cards in the deck, false otherwise

bool isEmpty();

//overload

friend ostream& operator

private:

static const int numCards = 52; // # of cards in a deck

Card theDeck[numCards]; // the array holding the cards

int topCard; // the index of the deck's top card

};

#endif

/* Player.h */

#ifndef PLAYER_H

#define PLAYER_H

#include

#include

#include "deck.h"

#include "card.h"

using std::ostream;

using std::string;

class Player{

public:

static const int Max_Cards = 3; // # of cards a player can have in a hand

// constructor - player's name defaults to "unknown" if not supplied

Player(string name="unknown");

// Simulates player removing one card from hand and playing it - returns the card

// You may use whatever strategy you'd like here: choose a card randomly,

// choose the card with the largest value, choose the first card, or other approaches

Card playCard();

// draw top card from the deck

void drawCard(Deck& dk);

// add the point value of the card to the player's score

void addScore(Card acard);

// return the score the player has earned so far

int getScore() const;

// return the name of the player

string getName() const;

// return true if the player's hand is out of cards

bool emptyHand() const;

// overload the

friend std::ostream& operator

private:

string name; // the player's name

int score; // the player's score

Card hand[Max_Cards]; // array holding the cards currently in the player's hand

bool hasPlayed[Max_Cards]; // hasPlayed[i] indicates that hand[i] (i.e., ith card in player's hand)

// has been played

};

#endif

he origina (+[10] Q [10] has J [10] eck the foTowing 10 [10] cards 9#69] 8[8] 7 [7] The deck after shuffling top of deck listed first layer 1's hand: 4. [4] 6 [6] 6[6] with score 0 layer 2's hand: J. [10] 7 [7] K [10] with score 0 l ayer 1 played car d : 6 [6] layer 2 played card: J. [10] layer 2 wins this hand layer 1's hand: 4[4] 6t6] layer 2' s hand: with SCOre [?] K. [10] with score 16 layer layer 1's 2's hand: hand: 4 [4] 54'[5] 6 ? [6] 5 [5] with score 0 [?] K [10] with score 16 layer 1 played card: 6 [6] Player 2 played card: [?] layer 2 wins this hand layer 1's hand: 4[4] layer 2's hand: 5 [5] 5 [5] with score 0 KVL101 with score 29 he origina (+[10] Q [10] has J [10] eck the foTowing 10 [10] cards 9#69] 8[8] 7 [7] The deck after shuffling top of deck listed first layer 1's hand: 4. [4] 6 [6] 6[6] with score 0 layer 2's hand: J. [10] 7 [7] K [10] with score 0 l ayer 1 played car d : 6 [6] layer 2 played card: J. [10] layer 2 wins this hand layer 1's hand: 4[4] 6t6] layer 2' s hand: with SCOre [?] K. [10] with score 16 layer layer 1's 2's hand: hand: 4 [4] 54'[5] 6 ? [6] 5 [5] with score 0 [?] K [10] with score 16 layer 1 played card: 6 [6] Player 2 played card: [?] layer 2 wins this hand layer 1's hand: 4[4] layer 2's hand: 5 [5] 5 [5] with score 0 KVL101 with score 29

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!