Question: Structured Data 2 C++ language Write a program that uses an array of struct s to represent a card deck, where the card values are
Structured Data 2 C++ language
Write a program that uses an array of structs to represent a card deck, where the card values are represented by enumerated types for the suit and rank. Your program will use functions to create the card deck, print a single card, print the card deck, deal two cards, then determine which card is the winner.
Requirements
- Use the enumerated types and data structures defined below:
enum suits {HEARTS, DIAMONDS, SPADES, CLUBS}; enum ranks {TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE};
struct cards { suits suit; ranks rank; };
cards deck[52];
cards card1, card2;
- Create these functions according to the prototypes:
void createDeck(cards[]);
void printDeck(cards[]);
string cardName(cards); return a string containing the card name of the rank concatenated with the word "of" concatenated with the name of the suit.
cards deal(cards[]);
string winner(cards, cards);
- In main(), call the functions to:
- Create the deck
- Display the entire deck
- Randomly deal card 1
- Display card 1
- Randomly deal card 2
- Display card 2
- Display the winning card. (Ignore the suit for comparison. Ace is always high. If both ranks are the same, then display a tie.)
- Functions must pass parameters and return values as needed, using only local variables. Global variables are not allowed.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
