Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using c++ Specifications Use a Card class to store the rank and suit for each card. In addition, use a member function, get_str(), to get

image text in transcribed

using c++ Specifications

  • Use a Card class to store the rank and suit for each card. In addition, use a member function, get_str(), to get a string representation for each card such as Ace of Spades, 2 of Spades, etc.
  • Use a Deck class to store the 52 cards in a standard playing deck (one card for each rank and suit):

ranks: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace

suits: Clubs, Diamonds, Hearts, Spades

To store 52 cards, use a member, deck, which is a vector of Card. To save your time in design this class, its default constructor is provided as following:

Deck::Deck() { vector ranks = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" }; vector suits = { "Clubs", "Diamonds", "Hearts", "Spades" }; for (string rank : ranks) { for (string suit : suits) { deck.push_back(Card(rank, suit)); } } }

This class should also include a member function, shuffle(), that shuffles the deck, a member function, count(), that counts the number of cards in the deck, and a member function, deal_card(), that deals a card from the deck, which should reduce the count of the cards in the deck by 1.

Hint 1: See Chapter 6 for how to use vector class, which is very similar to an array (a built-in construct) with no pre-allocated size and can grow and shrink dynamically.

Hint 2: To shuffle the cards, you can use rand() and srand() functions. Because some cards may be already dealt to the user, be sure the random number generated is based on the deck's current size.

  • Store the Card and Deck classes in separate header and implementation files. That is, there should be Card.h, Card.cpp, Deck.h, and Deck.cpp in your Cards (project) folder.
  • When the program (i.e., main.cpp) starts, it should get a new deck of cards, shuffle them, and display a message that indicates the total number of cards in the deck.
  • The program should prompt the user for the desired number of cards. Then, it should deal the user the desired number of cards and display a message that indicates the number of cards left in the deck as shown in the above Console screen.
Card Dealer I have shuffled a deck of 52 cards. How many cards would you like?: 7 Here are your cards: Jack of Hearts Jack of Diamonds 2 of Diamonds 6 of Spades Jack of Spades 6 of Hearts King of Diamonds There are 45 cards left in the deck. Good luck

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

Big Data With Hadoop MapReduce A Classroom Approach

Authors: Rathinaraja Jeyaraj ,Ganeshkumar Pugalendhi ,Anand Paul

1st Edition

1774634848, 978-1774634844

More Books

Students also viewed these Databases questions

Question

1. Identify and control your anxieties

Answered: 1 week ago