0% found this document useful (0 votes)
31 views2 pages

P 1 Card

This project involves writing a C program to simulate dealing cards from a deck to four players. The program will: 1. Generate a random deck of 52 unique cards and print it. 2. Deal the cards from the deck evenly to a 2D array representing each player's hand. 3. Print the players' hands showing the card values and suits. 4. Track each card dealt to each player using a 3D array and print the final hands. The program requires functions for generating the deck, dealing cards, and printing the various arrays. Global variables are suggested to store the deck, hands, and dealt card tracking array.

Uploaded by

momo303
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

P 1 Card

This project involves writing a C program to simulate dealing cards from a deck to four players. The program will: 1. Generate a random deck of 52 unique cards and print it. 2. Deal the cards from the deck evenly to a 2D array representing each player's hand. 3. Print the players' hands showing the card values and suits. 4. Track each card dealt to each player using a 3D array and print the final hands. The program requires functions for generating the deck, dealing cards, and printing the various arrays. Global variables are suggested to store the deck, hands, and dealt card tracking array.

Uploaded by

momo303
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CIS211-450: Project 1

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.

B: ASSIGNMENT: Write a C program according to the following steps:

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.

Now your main program should contain something like


while (seed > 0)
{
generateCard(card);
printArray(card, 52); //to check if card contains all unique numbers

}

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.

CIS211-450: Project 1 Page 1 of 2


5. Write a function called print2Array which returns nothing but accepts three
arguments: (1) two-dimension array which is hands, (2) the number of rows,
and (3) the number of columns. This function will print the contents of hands.

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

To do this, you will need to set up a 3-dimensional array of 4x4x13. The


first dimension will represent each party. Initially, all values are 0. The 2nd
and the 3rd dimensions will represent a particular card. The particular 0 will
changed to 1 if that card is held by a certain party. Eventually, there will be
total of 52 ‘1’s and 13’1’s for each party.

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.)

CIS211-450: Project 1 Page 2 of 2

You might also like