V22.0002 - ASSIGNMENT
5Four friends are sitting at a table and decide to
play a game of poker using a standard 52-card deck. In poker, each player gets
dealt 5 cards, with Player #1 getting the 1st card, Player #2 getting the 2nd
card, Player #3 getting the 3rd card, Player #4 getting the 4th card, Player #1
getting the 5th cards, etc. until a total of 20 cards are dealt.
Use the random number generator in a C program to simulate the dealing of
these 20 cards to the 4 players. This assignment will focus on the use of
user-defined functions, for loops, switch statements, and your ability to
exactly match the format for printing the results as displayed below.
Player 1 Player 2 Player 3 Player 4
5 of Diamonds A of Clubs K of Spades 10 of Diamonds
10 of Spades 9 of Diamonds J of Diamonds 7 of Diamonds
J of Clubs 10 of Clubs 7 of Spades 5 of Clubs
Q of Hearts 3 of Diamonds A of Hearts 3 of Hearts
9 of Spades K of Diamonds 4 of Spades K of HeartsREQUIREMENTS:
- Create a user-defined function called PickCardValue which returns a random
number between 1 and 13 (1 is an Ace, 11 is a Jack, 12 is a Queen, and 13 is a
King ... 2 thru 10 obviously represent the card values 2 thru 10). The
function's prototype must look like this:
int PickCardValue (void);
- Create a user-defined function called PickCardSuit which returns a random
number between 1 and 4 (1 is Diamonds, 2 is Hearts, 3 is Spades, and 4 is
Clubs). The function's prototype must look like this:
- Your main function MUST include 2 switch statements (1 to handle
the printing of the card value, and 1 to handle the printing of the card
suit). Make sure your program does not print something like 12 of
Spades (this is why you need the switch statements).
- Your main function MUST contain 2 for loops, one nested within the
other. The outer for loop handles the round being dealt (Rounds 1 thru 5)
while the inner loop handles the player being dealt (Players 1 thru 4). Using
these repetition structures in this manner will allow you to deal cards in the
order described above. DO NOT HAVE YOUR PROGRAM DEAL 5 CONSECUTIVE CARDS TO
PLAYER #1, THEN 5 CONSECUTIVE CARDS TO PLAYER #2, ETC. ... THIS IS NOT
- You may need to use if/else statements to properly print the results in a
table as displayed in the above example. You will make use of the "\t" escape
sequence (to advance the cursor to next horizontal tab position) and the "\n"
escape sequence (to move the cursor to the beginning of the next line).
- THE OUTPUT OF YOUR PROGRAM MUST EXACTLY MATCH THE FORMAT IN THE EXAMPLE
- Note that your program may actually "deal" the same card more than once
(for example, the 3 of Diamonds may appear 2 or more times). This is OK.
- For debugging purposes, do not seed the random number generator with the
srand( time(NULL) ); statement until you are confident your
program is working properly.
You must an email copy of your .c file only to the grader (please make
sure it's sent as an attachment!)
Your email MUST have the following in the Subject line to ensure you are not
penalized for non or late submission!
INTROC:YOUR LAST NAME:YOUR FIRST NAME:HW#5
If it's late or you are allowed to resubmit, then follow the above with :LATE
or :RESUBMIT as is applicable.
The grader's email is: firstname.lastname@example.org.
Please do NOT ask the grader questions. Questions should be directed to
the list if general, or to me if more specific.