Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Create a c++ class named Deck that will represent a deck of cards, which is composed of many PlayingCard objects. The private data field for

Create a c++ class named Deck that will represent a deck of cards, which is composed of many PlayingCard objects. The private data field for the class should be an array (or vector) of 52 cards. Re-use the PlayingCard class from Assignment 16. The constructor of the Deck class should initialize each card using the 2-arg constructor from the PlayingCard class. Certain features of the PlayingCard class may need to be moved to the Deck class.

Include a public method that will shuffle the deck. The shuffle method should randomly mix up the cards in the array by swapping the cards to different array positions. Do not use any other library functions besides random number generation. Use a loop that performs 1000 swaps of 2 randomly selected cards.

Include a public method that will draw a card from the deck and return it to the caller. You will need to keep track of which cards have been drawn (a copy is returned to the caller). Initialize a private counter variable to zero which will represent the next index to draw. For example, the first card to be drawn will be located at index 0 of the array and after 5 cards have been drawn the counter variable will be equal to 5. Keep in mind that if the deck is shuffled while cards have been drawn, only those array indices where cards remain should be shuffled. For example if 5 cards have been drawn then the shuffle method will only randomize the cards with indices 5 - 51.

Include a public method to reset the deck that is implemented by resetting the counter variable and shuffling the full deck.

Test the class from main by implementing a simple card game of your choosing. You may choose to use the game of War or something more interesting. Allow the user to play the game repeatedly and make sure to reset the deck before each new game.

Note that in future assignments we will develop additional classes that will work with the Deck and PlayingCard classes and we will also further improve and refine their functionality

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions