Hi. Im trying to write a simple deck of cards program. I am having difficulty in expressing my integer deck into a printable form. The deck is generated as this:
00102030405060708090100110120011121314151617181911011111210212223242526272829210211212203132333435363738393103113123
The leading numbers assign to suits and the following number assign to card rank. Basically how can I convert this to print in the form:
Card 1: Ace of spades
Card 2: 2 of spades
Card 3: 3 of spades
etc;
Could I use if statements and BREAKS to change the ints into strings? Perhaps a char value for suit would be better..
Any suggestions? Any help would be appreciated. I will post the question to give you a better idea of my though process. Please just help me in the right direction I am not looking for answers.
Write and compile a C++ program to simulate a deck of cards. A card is a C++ struct with both a suit (1 through 4) and a rank (1 through 13). A class CCardDeck provides the required functionality of a deck, as shown below. This class also includes a more involved member function to shuffle a deck. There are many ways to shuffle a deck. One approach is to divide a deck into two smaller decks. From here, the original deck is recreated by taking a few (random number of) cards at a time, from each of the two smaller decks, and placing them on the original deck. As an added note, the main function must also initialize the random number generator (srand(time(NULL)) where time(...) is in the <time.h> file).
A sketch of a possible interface of the CCardDeck class is given as follows, that is
public:
constructor (initialize a deck with the 4 × 13 = 52 cards of a standard deck) insert top card (add a given card to the top of a deck)
remove top card (remove the top card from a deck and return it)
get number of cards(return the current number of cards in a deck)
print (function to print, to the screen, all of the cards in a deck)
shuffle (shuffle the current deck, as described above)
private:
card type array (an array to hold a pile of cards, maximum of 52 cards)
Feel free to add any functions to these classes that you think you need.
Test your program using the script given below (code this in the main function), namely
Create a deck
Print the deck
Remove the top 3 cards
Print the deck
Put back the 3 cards into the deck Print the deck
Shuffle the deck
Print the deck
Shuffle the deck
Print the deck