Question: Using the program segment below, write a program that simulates a deck of cards. This program should: 1. Model a deck of 52 cards, 2.
Using the program segment below, write a program that simulates a deck of cards. This program should:
1. Model a deck of 52 cards,
2. Shuffle them using the random_shuffle() function.
3. Draw a random hand of 5 cards.
4. Sort the hand by suit,
5. Print this hand using C++ style I/O, each card on its own line.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Sample Output
If the program is invoked as follows:
./cards
A random sample output should appear as follows:
5 of
10 of
4 of
8 of
Ace of
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// randomDeck.c // #include
enum Suit { SPADES=0, HEARTS=1, DIAMONDS=2, CLUBS=3 };
typedef struct Card { Suit suit; int value; } Card;
string get_suit_code(Card& c); string get_card_name(Card& c); bool suit_order(const Card& lhs, const Card& rhs); int myrandom (int i) { return std::rand()%i;}
int main(int argc, char const *argv[]) { srand(unsigned (time(0)));
//array for card deck // Card deck[52];
//make deck int CounterIndex = 51; for (int i = 0; i < SuitNum; i++){ // suit for (int j = 0 ; j < FacesNum; j++){ //faces deck[CounterIndex].suit = static_cast
//Cards.push_back(card); // add card to vector //CardNum++;// raise card number for every card added to deck } } // hand // random_shuffle(&deck[0], &deck[52], myrandom); int arr[5] = {1,2,3,4,5}; // hand instead of deck for sort. pass card_order instead of myrandom
return 0; }
/*This function will be passed to the sort funtion. Hints on how to implement* this is in the specifications document.*/
bool suit_order(const Card& lhs, const Card& rhs) { // IMPLEMENT} string get_suit_code(Card& c) { switch (c.suit) { case SPADES: return "\u2660"; case HEARTS: return "\u2661"; case DIAMONDS: return "\u2662"; case CLUBS: return "\u2663"; default: return ""; } }
string get_card_name(Card& c) { // IMPLEMENT }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
