Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Header files : 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};

image text in transcribed
image text in transcribed
Header files :
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

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

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

Objectives: 1) Use of static variables; 2) Using multiple dasses; 3) Operator overloading: 4) Overloading ostream; 5) Using friend functions; 6) Class aggregation. Project description: Write a C++ program to simulate a simple card game between two players. The game should proceed as follows: The 52 cards in a deck of cards are shuffled and each player draws three cards from the top of the deck. The remaining cards are placed in a pile face-down between the two players. Players then select one of the three cards in hand and simultaneously place the chosen card face-up on the game table. The player who places the highest ranking card on the table collects both cards and adds them to their pile (score). If both cards have the same value the hand is a draw and no points are accumulated. Following the completion of a hand, each player draws the top card from the deck to add to their hand. Play continues until all cards have been played. The winner is the player with the most points at game's end. You will use a standard deck of 52 cards where there are thirteen cards from each of four suits: hearts, spades, diamonds, and clubs. The thirteen cards in point order are the 2-10 numbered cards, the face cards (Jack, Queen, King) and the Ace card. Points are distributed as follows: Aces 15, face cards= 10, all other cards count as their numeric value. Requirements: 1. Your program must be split into 7 files. There will be 3 classes (each with separate interface and implementation files), and a driver file. The requirements for these are specified below a) The Cardclass This class represents an individual card Files must be named card.h and card.cpp Class must be named Card The interface (header file) is provided. i. You should implement the interface file in a.cpp implementation file ii. All data members must be of the type specified in the header file ii All member functions in the interface file must be implemented as declared However you have flexibility in how you choose to implement the body of each b) The Deck class-This is represents the deck of cards Files must be named deck.h and deck.cpp Class must be named Deck . The interface (header file) is provided i. ii. You should implement the interface file in a.cpp implementation file All data members must be of the type specified in the header file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 8th International Symposium Sstd 2003 Santorini Island Greece July 2003 Proceedings Lncs 2750

Authors: Thanasis Hadzilacos ,Yannis Manolopoulos ,John F. Roddick ,Yannis Theodoridis

2003rd Edition

3540405356, 978-3540405351

More Books

Students also viewed these Databases questions