Program 2 - Bridge Hand Evaluator

This is a programming assignment found on p. 47 of "Data Abstraction and Problem Solving with C++: Walls and Mirrors", Second Edition, by Carrano, Helman, and Veroff, published in 1998 by Addison Wesley Longman, Inc.


Write a program that sorts and evaluates bridge hands.

The input is a sequence of lines, with each line representing a bridge hand. Each line is a stream of character pairs that represent playing cards. For example,

  2C QD TC AD 6C 3D TD 3H 5H 7H AS JH KH
represents the 2 of clubs, queen of diamonds, 10 of clubs, ace of diamonds, and so on. Each pair consists of a rank followed by a suit, where rank is A, 2, ..., 9, T, J, Q, or K, and suit is C, D, H, or S. You can assume each input line represents exactly 13 cards and is error-free. Input is terminated by an end of file.

For each line of input, form a hand of 13 cards. Display each hand in a readable form arranged both by suits and by rank within suit (aces are high). Then evaluate the hand by using the following standard bridge values:

For example, for the previous sample input line, the program should produce the output
CLUBS       T    6    2
DIAMONDS    A    Q    T    3
HEARTS      K    J    7    5    3
Points = 16  
because there are 2 aces, 1 king, 1 queen, 1 jack, 1 singleton, no doubletons, and no long suits. (The singleton ace of spades counts as both an ace and a singleton.)

Your are free to design the program as you wish, with or without classes. There are some natural ways to use classes, so this might be a good time to try to design a class on your own.

Code Submission

To submit your code, we'll be using submit2440. The syntax for submitting this program will be:

~jtw/bin/submit2440 prog2 bridge.C

Note that if you create a class as part of the assignment you may have additional files on the submit command line.