Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

It is C++ assignment, my homework 2 is as below and please add homework 3 into homework 2. please explain ur code too. Thanks //card.h

It is C++ assignment, my homework 2 is as below and please add homework 3 into homework 2. please explain ur code too. Thanks

image text in transcribed

image text in transcribed

//card.h

#include  #include  using namespace std; #ifndef DECK_OF_CARD_CARD_H #define DECK_OF_CARD_CARD_H enum Suit { SPADE, HEART, DIAMOND, CLUB }; class Card { private: int number; Suit suit; string description; //This function sets the suit of the card void setSuit(string s) { const char *suitString = s.c_str(); if (stricmp(suitString, "Spade") == 0) { suit = SPADE; } else if (stricmp(suitString, "Heart") == 0) { suit = HEART; } else if (stricmp(suitString, "Diamond") == 0) { suit = DIAMOND; } else if (stricmp(suitString, "Club") == 0) { suit = CLUB; } } void setNumber(int n) { number = n; } public: Card(string su, int n) { setNumber(n); setSuit(su); description = getSuit() + " " + getNumber(); } string getNumber() { if (number > 1 && number other) { //If two suits are equal, compare the card if (suit == other.suit) { int thisNumber = number; int otherNumber = other.number; //If either of the cards have //an ace, then make its value 14 //because ace is of the greatest value //but its number is 1 if (number == 1) { thisNumber = 14; } if (otherNumber == 1) { otherNumber = 14; } return thisNumber other.suit; } } }; #endif //DECK_OF_CARD_CARD_H 

//Deck.h

#include  #include "Card.h" class Deck { private: //Array of card pointers Card *deck[52]; public: //Constructor to initialize the cards Deck() { srand(time(NULL)); //Create an array of suit string suits[] = {"Club", "Diamond", "Heart", "Spade"}; //For each suit, create 13 cards and add them to the deck for (int i = 0; i  

//Player.h

#include "Card.h" class Player { private: //Hand of cards Card *hand[13]; string name; //variable to store the actual number of cards in the hand int numCards; public: Player(string name) { //set the name this->name = name; //Initialize all the cards to null for (int i = 0; i card) { //If the number of cards doesn't exceed 13, if (numCards card; numCards++; } } int clubTwo() { //Search for club two in the hand for (int i = 0; i getDescription() == "Club 2") { return i; } } //If we couldn't find the card, return -1 return -1; } //Function to display the hand void display() { cout cout getDescription()  

//Main.cpp

#include  #include "Player.h" #include "Deck.h" int main() { //Create a deck Deck deck; //Shuffle it deck.shuffle(); //Get the deck of cards Card **deckOfCards = deck.getDeck(); //Create four players Player players[] = {Player("Lady Gaga"), Player("Albert Einstein"), Player("Muhammed Ali"), Player("Diego Maradona")}; //Ask the user if they want to shuffle the deck or deal or end string choice; while (choice != "e" || choice != "E") { cout cin >> choice; //If the user chose to shuffle, shuffle the deck if (choice == "s" || choice == "S") { deck.shuffle(); } else if (choice == "d" || choice == "D") { int clubTwoPlayerIndex = 0; int clubTwoIndex = 0; //For each card, deal it to an alternate player for (int i = 0; i cout cout  

Homework 3 - Game of Hearts Before writing any code, play a few games at playhearts-online.com Write a program that plays the card game of Hearts. Your program should build on your code for homework 2, including your sort and shuffle functions. Add members to your Card and Deck classes as needed. Create a new Player class with these member variables: Card hand[13] -stores cards dealt to player boolean played[13] playedlil is true if hand[i] has been played, otherwise false int points total number of points player has accumulated so far String name - name of player Player has these member functions: void displayHand() - displays descriptions of cards in hand on console void addCard() - adds a card to hand during deal Card playCard(Suit lead, boolean leader)-returns the Card played - if leader is false, card must be in the lead suit Add constructors, get and set functions, and other members as needed. Keep your main program simple. Most of your logic should be in member functions of classes See the following pages for sample display and rules of the game. Challenge (optional - 1 bonus point) When one player takes all 13 hearts and the queen of spades, instead of losing 26 points, that player scores zero and each opponent scores 26 points. This is called 'shooting the moon'. Implement 'shooting the moon' in your program. Challenge (optional -1 bonus point) Make your program smart enough so that any one of the computer players beats the TA two out of three hands. You must follow two rules: You cannot rig the deal. Shuffle and deal must be random. Players cannot see each other's hands. Players are aware only of their own cards. Homework 3 - Game of Hearts Before writing any code, play a few games at playhearts-online.com Write a program that plays the card game of Hearts. Your program should build on your code for homework 2, including your sort and shuffle functions. Add members to your Card and Deck classes as needed. Create a new Player class with these member variables: Card hand[13] -stores cards dealt to player boolean played[13] playedlil is true if hand[i] has been played, otherwise false int points total number of points player has accumulated so far String name - name of player Player has these member functions: void displayHand() - displays descriptions of cards in hand on console void addCard() - adds a card to hand during deal Card playCard(Suit lead, boolean leader)-returns the Card played - if leader is false, card must be in the lead suit Add constructors, get and set functions, and other members as needed. Keep your main program simple. Most of your logic should be in member functions of classes See the following pages for sample display and rules of the game. Challenge (optional - 1 bonus point) When one player takes all 13 hearts and the queen of spades, instead of losing 26 points, that player scores zero and each opponent scores 26 points. This is called 'shooting the moon'. Implement 'shooting the moon' in your program. Challenge (optional -1 bonus point) Make your program smart enough so that any one of the computer players beats the TA two out of three hands. You must follow two rules: You cannot rig the deal. Shuffle and deal must be random. Players cannot see each other's hands. Players are aware only of their own cards

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

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago