C programming A deck of cards problem Write the member funct

C++ programming! A deck of cards problem!

Write the member function implementations for the class dock, which simulates the standard dock of 52 playing cards, into the file dock.cpp. The private field card stack [52]: represents the 52 cards of n dock. The private field int deal_count: represents how many cards have been dealt from the dock The public member function void print_dock(): prints out the dock in order. The implementation is provided The default constructor dock(): simulates preparing a brand new dock of cards. So deal_count is initialized to O, and the stack of cards are initialized so that calling print_dock(): immediately after initialization outputs Ace of Clubs 2 of Clubs ... King of Clubs Ace of Diamonds ...King of Diamonds Ace of Hearts ... King of Hearts Ace of Spades ...King of Spades The public member function void shuffle(): shuffles the dock in a uniformly random order. We\'ve provided the implementation, since it requires a random numbers, a topic we won\'t cover. The public member function Card deal(): Simulates dealing a card. So deal() sould return the card \"at the top of the dock\", and the value of deal_count should be incremented by 1. Assort that deal_count is less than 52 The public member function int stack_size(): returns the current size of the dock. If no cards have been dealt, the size is 52. If all cards have been dealt, the size if 0. The public member function void gather_and_shuffle(): simulates gathering all the cards that have been dealt and them shuffling. So after gather_and_shuffle()is called, deal_count is set to 0 and the dock is shuffled

Solution

Hi Below is the code for Card Shuffling and Dealing and Printing . I am able to write these two part of the code only. You can use the same code to form logic for other part. #include #include #include #include using namespace std; int suits[4]={1, 2, 3, 4}; int faces[12]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; class Card { public: int face,suit; Card(int face,int suit) { this->face=face; this->suit=suit; } string toString() { string nameSuit; string nameFace; if (suit == 1) nameSuit = \"Hearts\"; else if(suit == 2) nameSuit = \"Diamonds\"; else if(suit == 3) nameSuit = \"Spades\"; else if (suit == 4) nameSuit = \"Clubs\"; if (face == 1) nameFace = \"Ace\"; else if(face == 10) nameFace = \"Jack\"; else if(face == 11) nameFace = \"Queen\"; else if(face == 12) nameFace = \"King\"; else { for (int i = 2; i < 10; i++) { nameFace = \"\" + i; } return nameFace+\" of \"+nameSuit; } }; class DeckOfCards { private: vector deck; int currentCard,index; public: DeckOfCards() /*create deck*/ { currentCard=1; for(int i=0;i<13;i++) for(int k=0;k<4;k++) { Card card(i,k); deck.push_back(card); currentCard++; } } void shuffle() /*shuffle the deck*/ { for(int i=0;i<52;i++) { index=rand()%52+1; Card holder=deck[index]; deck[index]=deck[i]; deck[i]=holder; } } Card dealCard() /*deal the shuffled cards*/ { Card temporary = deck[currentCard]; currentCard--; return temporary; } bool moreCards() { if(currentCard == 52) return false; else return true; } }; int main () /*main function*/ { DeckOfCards deck; deck.shuffle(); for( int i = 0; i < 52; i++) { cout<
C++ programming! A deck of cards problem! Write the member function implementations for the class dock, which simulates the standard dock of 52 playing cards, i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site