P 1 Card
P 1 Card
A: DESCRIPTION:
The purpose of this project is to help you review C language basic control structures,
function, and array.
A deck of playing cards has four suits which are Spade (=’\6’), Heart(=’\3’),
Diamond(=’\4’), and Club(=’\5’). And each suit has 13 cards in the order of 2, 3,
…,9, 10, J, Q, K , A.
1. Ask the user for an integer as seed. As long as the seed is greater than 0, use the
pseudo-random number generator and the remainder operator to generate 52
distinct numbers from 0 to 51. These numbers will represent a deck of card and
let’s call it deck. (Now you have a one-dimensional array of size 52). To make
sure your program works, you may print the number when it is generated.
2. Write a function called printArray which returns nothing but accepts two
arguments, one is the array and the other is the size of the array. This function
will print the contents of the array in the format of 13 numbers per line and 5
spaces per number.
3. Modify 1 and write a function called generateCard which returns nothing but
accepts one argument which is the array variable that represents the deck of
card. This function will contain all the codes in 1 that generate the deck of
card.
4. Use a two dimensional array of 4x13 representing 4 hands of cards. Let’s call it
hands. Write a function called deal which accepts two arguments, one is the
card and the other is hands. This function distributes the card to the four parties.
Assume that the order of distribution is East, North, West, and South. You may
write the code in main program and then modify it into a function after it works.
6. Assuming that Spade will take the values from 0 to 12, Heart from 13 to 25,
Diamond from 26 to 38, and Club from 39 to 51. You are going to write a
function called printHands which will print the hand of each party similar to
the following.
NORTH
: A Q J 10 9 2
: J 8 2
:K
:A J 9
C: NOTES: You may make the following variables global (you figure out the proper
types):
deck[52];
hands[4][13];
handsOfCard[4][4][13];
SUITS[4]={6, 3, 4, 5};
D: Reasonable Time for this project: 2 weeks. (More details will be given in the
class.)