Hands On C++: Project 11
Objectives
1. Practice using enumerations.
2. Gain experience defining enumeration operations.
Introduction
Your instructor will tell you which one of the following
projects to do.
Projects
11.1.
Extend your Gender enumeration with these operations:
-
Next(Gender value); that returns the enumerator
that follows value, wrapping around from the last
valid enumerator to the first valid enumerator
(i.e., returns FEMALE when value is UNKNOWN,
returns MALE when value is FEMALE, and
returns UNKNOWN when value is MALE.
-
Previous(Gender value); that returns the enumerator
that precedes value, wrapping around from the first
valid enumerator to the last valid enumerator
(i.e., returns FEMALE when value is MALE,
returns MALE when value is UNKNOWN, and
returns UNKNOWN when value is FEMALE.
Write a driver program that tests your functions.
11.2.
Build a Month enumeration.
Using it, create a Date
class that stores the month, day, and year for a date.
Test your class by writing a program that reads two dates,
and returns the number of days between those two dates
(don't forget to consider leap years).
11.3.
Extend the classes in enumGenerator.cpp to automatically
generate the Next() and Previous() functions
described in 11.1 for any enumeration.
11.4.
Build two enumerations:
-
Suit, containing the values Clubs, Diamonds,
Hearts and Spades; and
-
Rank, containing the values Ace, Two,
Three, Four, Five, Six,
Seven, Eight, Nine, Ten,
Jack, Queen, King.
Use these enumerations to design and build a PlayingCard class.
Using this class and vector, build a DeckOfCards class.
Provide the following operations:
-
a constructor that creates a 'new' (in-order) deck of cards;
-
a Shuffle() operation that arranges the PlayingCards
in a DeckOfCards in 'random' order;
-
a TopCard() operation that returns the "top" card in the
DeckOfCards() without removing it; and
-
a DealTopCard() operation that returns the "top" card in the
DeckOfCards() and removes it.
Use these classes to write a program that plays a simple card game,
such as "Go Fish."
Turn In:
A hard copy of this grade sheet,
attached to hard copies of
-
all source files you created for this project; and
-
the output from an execution of your executable program.
Don't forget to clean up your directory when you are all finished...
Back to the Lab Exercise
Back to This Lab's Home Page
Copyright 1998 by
Joel C. Adams. All rights reserved.