DeckOfCards

1

SCIT
School of Computing and Information Technology
Faculty of Engineering & Information Sciences
CSCI124 – Applied Programming – July 2017 Session
Assignment 2 (80 marks)
1. Due: TBA
2. Daily penalty: minus 20% per day (maximum 3 days)
3. Please zip all your program files in a folder called “YourName_A2” and submit
via the Moodle system
4. All file names given in this assignment MUST be respected
6. This assignment is worth 12% of the total marks of this subject.
Background
To become familiar with program designs dealing with
– Applications on arrays using pointer arithmetic.
– The use of void* for generic design
– Sorting and searching
– Dynamic allocations
Problem
A deck of cards may be used for playing a variety of card games, with varying elements
of skill and chance, some of which are played for money. No matter what sort of card
games, the basic principle is always the same, shuffle the cards, distribute the cards and
arrange for the cards. These are the objective of this assignment.

The following shows a sample of familiar playing cards used by most of the people:
2
Different countries may have different naming of card values. For example, the French
people name the Jack, Queen and King as Valet, Dame and Roi
respectively.
They call the suits Spades, Hearts, Diamonds and Clubs as Pigues,
Coeurs, Carreaux and Trèfles respectively. If you wish to hear my Singapore
accent of French pronunciation of these 4 words, feel free to see me ?
When you buy a pack of playing cards, you always see that they are arranged in order;
firstly the cards are arranged based on the colors and among the colors, they are arrange
based on the card values (we usually call them the ranks of the cards).
After shuffling the cards, you then distribute the cards to the players. Each player

usually
holds the same number of cards depending on the game. We usually call it a hand (of
cards). When players receive the cards, they usually like to re-arrange the cards in order,
firstly by colors and then by rank.
For example, the bridge game has 4 players, and each player has 13 cards. Here are the
arrangements of cards of the players:
3
Everyone has his (her) way of arranging the cards, this is less important to this
assignment as long as you fix your way of arranging.
Let us now illustrate what you have to do for this Assignment. In order to cater for the
need of various conventions of naming the cards by different countries, we propose the
following structure definition of a playing card:
struct Card
{
Char * color;
RankType rank;
};
A deck of playing cards is an array of structure Card’s and it is not necessary 52 cards,;
for example French Tarot card game has 78 cards!!
Important to note
You should treat the array of Card as Card*. All storages used for the arrays
should be dynamically created; and delete them when they are no longer needed.
When accessing to an element of the array, you should access it via a pointer, i.e. by
dereferencing this pointer. Using the notation, for example cardArray [k] or
*(cardArray + k) accessing to the k
th element of the array cardArray is not
allowed.
The color is one of the following four C-strings (array of characters)
4