Computer Science 145.002
Introduction to Computing for Engineers
Fall 2008 / Programming Assignment 4
“Functions”
Due: 7:30 AM, Thursday, October9, 2008

In this programming assignment, you will break a large programming problem into smaller self-contained functions, each of which will solve a particular task as part of the overall programming effort. Your program will repeatedly simulate the dealing of five cards from a standard 52-card deck, as long as the resulting five-card hand isn't a full house (i.e., three cards of one rank and two of another). When that happens, the program terminates, telling the user how many hands were dealt.

For each hand dealt, a random number generator will be used to generate five distinct values between 1 and 52. Values from 1 to 13 represent the "Hearts" cards from the Ace through the King; values from 14 to 26 represent the "Diamonds" cards from the Ace through the King; values from 27 to 39 represent the "Spades" cards from the Ace through the King; and values from 40 to 52 represent the "Clubs" cards from the Ace through the King.

As each hand is "dealt", the previous cards are examined to ensure that no duplicates occur. Once all five cards for a hand are dealt, the entire hand is analyzed to see if it constitutes a full house (e.g., three Aces and two Fours, etc.). A count is kept of how many hands are dealt, and this count is output when a full house hand is finally dealt. A sample execution session for this program is illustrated at right.

There are twelve functions in this program, and the prototypes and function headers have already been written. In addition, the code and comment sections for five of the functions (includingmain) are included. A soft copy of the code as it currently exists is available on the course Web page at The twelve functions are described below:

  • Themainfunction (already written) coordinates the repeated dealing of the cards, until a full house hand is dealt.
  • ThedealCardfunction produces a random number between 1 and 52, representing a card from the 52-card deck.
  • ThegenerateRandomNumberfunction (already written) uses library functions instdlib.handtime.hto generate a random integer value that is between two specified integer values.
  • The four overloadedcheckForDuplicatefunctions determine whether the integer value representing the newly dealt card is equal to the value associated with one of the previously dealt cards.
  • ThedisplayHandfunction outputs the contents of the five-card hand that was dealt, specifying the rank and suit of each card in the hand.
  • ThedisplayOneCardfunction outputs two characters, representing the rank and suit of the card corresponding to a parameterized integer value (e.g., K♥ represents the King of Hearts, corresponding to integer value 13).
  • Therankfunction (already written) calculates the single character corresponding to the rank of the card being evaluated. It uses 'K' for King, 'Q' for Queen, 'J' for Jack, 'T' for 10, '9' for 9, and so on, down to 'A' for Ace.
  • Thesuitfunction (already written) calculates the single character corresponding to the suit of the card being evaluated. It uses '♥' for Hearts, '♦' for Diamonds, '♣' for Spades, and '♠' for Clubs.
  • ThecontainsFullHousefunction determines whether three of the five cards in the dealt hand have the same rank, while the other two cards have a different (but equal) rank (e.g., three Aces and two 4's, three 7's and two Jacks, etc.).

Your assignment is to write the remaining seven functions so the program will yield the kind of output illustrated above. You also must write descriptive comments of the program as a whole (including your name), and of the individual functions that you write.Name your project PA4_Lastname where Lastname is your last name (e.g., Mary Miller’s project would be PA4_Miller). Don’t forget to include adequate explanatory comments in your code.

Zip-compress the entire project folder and place the zipped folder on your Moodledropboxby 7:30 AMon Thursday, October 9, 2008.