The solution given here shows an example of how one might go about writing a C++ program that satisfies all of the requirements of assignment #4 and runs correctly.  In this solution I define a playing card as a separate structure (defined in Card.h) and define a few functions you can do with cards (in Card.cpp).  I use the Card structure to create 4 hands of cards.  Then various function take care of sorting a hand of cards, evaluating the points for a hand, and displaying a hand of cards.

 

Card.h – Header file contains the definition of a Card structure.  A Card structure represents a single playing card (its suit and rank).

Card.cpp – This source file contains functions for dealing with a single playing card.   We have functions to create a new card, display information about a cards suit and rank, and compare whether one card is less than another card.

EvaluateBridgeHand.cpp – This file implements the actual code to evaluate a bridge hand.  It uses the playing card struct defined in Card.h/cpp.  It has functions to display a players name and hand, to sort a hand (using the compareLessThan function for cards), and calculate the points for a hand using the bridge point evaluations described in the assignment.

CSci 152: Computer Programming II

Fall 2004

Programming Assignment #4

Programming Assignment #4 example solution

Example Solution