CSC Lab 7

Due at start of class on Nov. 10th



NAME:_______________________________________________________

PARTNER:____________________________________________________



Description of Poker hands



A popular card game is the game of poker. In one version of poker, each player is dealt a hand consisting of five cards. The highest ranking hand (after some intricate betting rules we will ignore and a draw which we will also ignore) wins the round. The poker hands rank as follows:



1. Straight Flush all cards in the hand are from the same suit and they are 5 consecutive cards in that suit. Note that the card rank is: A, K, Q, J, T,9,8,...,3,2.

(Ex: QH, JH, TH, 9H, 8H)



2. Four of a Kind the hand contains 4 cards of the same rank

(Ex: 3S, 3H, 2H, 3C, 3D)



3. Full House the hand consist of three cards of one rank and 2 cards of another rank.

(Ex: 9H, 9S, QD, QC, QH)



4. Flush all cards in the hand are from the same suit but the hand is not straight flush.

(Ex: TD, 8D, 7D, 6D, 5D)



5. Straight the cards in the hand have 5 consecutive ranks but they are not all from the same suit.

(Ex: 9H, 8S, 7C, 6C, 5S)



6. Three of a Kind the hand has three cards of the same rank but is not a full house.

(Ex: 5H, 5C, 5D, 7H, AS)



7. Two Pair the hand has two cards of one rank, two cards of a different rank but is not a full house.

(Ex: 5H, 5C, 9C, 9S, 3H)



8. One Pair the hand has two cards of the same rank but is not one of the above hands.

(Ex: 8C, 8H, AS, 9S, 3C)



9. Nothing the hand is not one of the above hands.

(Ex: 8H, TD, AC, 5H, JS)





Description of the Program on Disk



On your disk, there is a program poker.cpp which deals a poker hand after shuffling a deck of cards. Run this program several times to get a feel for the output form.



The program has three functions in it.



The function Deal5(Rank, Suit) creates a hand of five cards chosen randomly. The variables Rank and Suit are character arrays. Rank[i] is the rank of the ith card in the hand. Ranks are single letters with 'A' representing Ace, 'Q' representing Queen, etc. The five cards in the hand are returned in decreasing order by rank. The order of the ranks is Ace, King, Queen, Jack, Ten, Nine,..., Two. Ten is represented as 'T' and the ranks below ten are represented by the digits '9' through '2'. Suit[i] is the suit of the ith card in the hand. The suits are Spades, Hearts, Diamonds and Clubs and they are represented by their first letters. There is no ranking of suits.



The function TestCase(Rank, Suit) asks the user of the program to input a hand of five cards. It asks that the hand be input in decreasing order by rank but does not check if the input is correct. The call to this function is "commented out" in the program. You should use it to test your program.



The third function is Shuffle(Cards) and it is used by Deal5 to create the hand. Your main routine will not have to use it directly.





Program to Write



You are to modify the program on the disk so that it determines the rank of the hand that is dealt by Deal5. The ranks are on the first page of this handout. Some sample output is included in this description.



You must write one function for each of the first seven kinds of hands described on the previous page. The function should be a function that returns 1 (=True) or 0 (=False) depending on whether the hand is that kind of hand. For example, the function FourKind would return a 1 if the hand it is sent is four of a kind and a 0 if it is not. (We purposely left out the parameters to this function. You will have to decide what they are.)



You should put a if...else if...else structure in the main program which will use the functions you create and print the correct kind of hand.



To test your program, you should remove the two slashes in front of the TestCase call and put two slashes in front of the Deal5 call. This will allow you to put in any kind of hand and test your function for that kind of hand. You do not have to write all the functions before you begin testing. You could write once function and then test that kind of hand.



Here are example results:



AH

QH

TH

8H

4H

The rank of the hand is: Flush



TS

5H

5S

5D

5C

The rank of the hand is: Four of Kind



JH

TC

7S

6S

5S

The rank of the hand is: Nothing



TS

9H

8D

7S

6C

The rank of the hand is: Straight



JH

9S

8H

8D

3C

The rank of the hand is: One Pair