Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ programming C++ programming C++ programming Instruction 1, Homework-6 is going to be done based on a previous assignment(homework 5), and I uploaded the assignment

C++ programming

C++ programming

C++ programming

Instruction

1, Homework-6 is going to be done based on a previous assignment(homework 5), and I uploaded the assignment and its answer.

2, Follow the previous assignment(homework 5) and its answer and the instructions on homework6 --> to do the question on the homework-6.

3, Feel free to make any changes to the code(answer I uploaded) so you can do homework-6.

4, more instruction are on the uploaded files.

image text in transcribed

privious assignment(homework 5) and its answer is here

image text in transcribed

The code for homework 5(homework4)

#include #include #include #include #include #define SIZE 52 using namespace std; enum Suit //creating a data type that helps to store the value of suits { Unknown=0, Clubs=1, Diamonds=2, Hearts=3, Spades=4 }; class Card // creating a card class that hold the decription, suit,and decription of the card { Suit suit; // holds 4 types of suits int number; string description;//holds the name of the card public: Card() //creating a constructor { suit=Unknown; number=0; description.assign(""); } Suit getSuit() // get member function for suit that return suit type { return suit; } void setSuit(Suit s)// set member function for suit that assigns suit type { suit=s; } int getNumber() //get number member function type for getting the numbers on the card { return number; } void setNumber(int Number) //set member function to set the numbers on the card { number=Number; } string getDescription() { return description; } void setDescription(string Description) { description.assign(Description); } bool operator const Card& c) { if(suit return true; } else if(suit>c.suit) return false; else   { if(number == 1) return true; else if(c.number==1) return false; else   return (numbertrue:false; } } }; class Deck { Card deck[SIZE]; public: // building member functions to what will be performed using the 52 cards. void initialize(); void shuffle(); void deal(); void sort(Card hands[13][4]); void display(Card hands[13][4]); }; void Deck::initialize() //intializing card types by number of accurance in 4*13 deck { string des; char n[10]; int flag; for(int i=1;iif(i==1 || i==14 || i==27 || i==40) { des.assign("Ace"); flag=1; } else if(i==11 || i==24 || i==37 || i==50) { des.assign("Jack"); flag=1; } else if(i==12 || i==25 || i==38 || i==51) { des.assign("Queen"); flag=1; } else if(i==13 || i==26 || i==39 || i==52) { des.assign("King"); flag=1; } if(iSpades); deck[i-1].setNumber(i); if(flag==0) { itoa(deck[i-1].getNumber(),n,10); des.assign((string)n); } des.append(" of Spades"); deck[i-1].setDescription(des); } else if(i>13 && iHearts); deck[i-1].setNumber(i-13); if(flag==0) { itoa(deck[i-1].getNumber(),n,10); des.assign((string)n); } des.append(" of Hearts"); deck[i-1].setDescription(des); } else if(i>26 && iDiamonds); deck[i-1].setNumber(i-26); if(flag==0) { itoa(deck[i-1].getNumber(),n,10); des.assign((string)n); } des.append(" of Diamonds"); deck[i-1].setDescription(des); } else   { deck[i-1].setSuit(Clubs); deck[i-1].setNumber(i-39); if(flag==0) { itoa(deck[i-1].getNumber(),n,10); des.assign((string)n); } des.append(" of Clubs"); deck[i-1].setDescription(des); } } } void Deck::display(Card hands[13][4]) //building the hand for 4 people and handing them 13 cards each { Suit suit; int number; coutfor(int i=0;ifor(int j=0;jif(suit==1) coutelse if(suit==2) coutelse if(suit==3) coutelse   coutif(number==1) coutelse if(number==11) coutelse if(number==12) coutelse if(number==13) coutelse   coutvoid Deck::shuffle() //shuffling the cards by calling random class { Card temp; int r; srand(time(NULL)); for (int i=0;ivoid Deck::deal() { Card hands[13][4]; for(int i=0;ifor(int j=0;jvoid Deck::sort(Card hands[13][4]) // sorting the card in by suit and card type. 4 suits by 13 card type using bubble sort { Card temp; int k; for(int i=0;ifor(int j=1;jwhile(k>=0 && hands[k][i]int main() { Deck deck; //calling the deck class coutchar ch='S'; while(ch!='e' && ch!='E') { cout>ch; switch(ch) //creating a choice for the user { case 's': case 'S': deck.shuffle(); break; case 'd': case 'D': deck.deal(); break; case 'e': case 'E': coutbreak; default: cout  Homework 6-Game of Hearts Before writing any code, review the rules of the game, page 2, and 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 5, including your overloaded

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

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions

Question

LO23.2 Discuss the extent and sources of income inequality.

Answered: 1 week ago