Question
Create an object-oriented program that creates a deck of cards, shuffles them, and deals the specified number of cards to the player. See a sample
Create an object-oriented program that creates a deck of cards, shuffles them, and deals the specified number of cards to the player. See a sample of console screen shown below.
This program would contain multiple files, including two .h and three .cpp files as defined in Specifications below.
If you are using IDE to develop this program, name your project (and solution in VS2017) as Cards to hold all files created. If you prefer to g++ and an editor without an IDE, save all files in a folder or directory also called Cards.
Console
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
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started