Fall 2004 |
Clay Shields |
Project 4 - Guide Puppy Litter Tracker
Program Source code due: November 8, 2004 |
The Guide Dog Organization (GDO, Inc.) has been very pleased with
the new tools that yo uave produced for them. The puppy weight
program was a success, allowing them to identify problems with
their feeding program. What they would like to do now is track entire litters of puppies at the same time, so that they can identify which of their breeding stock produce healthy, successful guides. This project will have two parts. Part 1:
Your first task will be to design a "puppy" class that can be used
to keep track of individuals. The information you should track
about each puppy is: its name; an ID that is five characters long
string; its weight at birth (in kilograms); what color it is (where
the possibilities for Labrador Retrievers are black, brindle,
brown, or yellow); what sex it is; whether the puppy has been
neutered or not; and a single-character status code indicating the puppy's
current status. This code can be one of the following choices:
You should write a complete class specification, including constructors and destructors; accessors and observers; overloaded input and output operators; and a method that can be called to read puppy information from the keyboard and do error checking to make sure the values are correct. Be aware that even if you do not use all the functionality you create, we may test it ourselves when grading.You should write a main that thoroughly tests your puppy class before continuing. Part 2: Once you have completed the puppy class, you will then create a litter class that has the following methods, as well as a constructor and destructor:
Last part: Write a main function that provides a menu to access information about a litter. It should at least allow a litter to be read from the keyboard; displayed; saved to a file; read from a file; and to show the current success rate of the litter. A sample run of a program that does this is shown here. A sample save file for a litter is here. Update: I did not get the chance in class to describe how to overload the >> or << operators to output your puppy class, so, as a start until class on Monday, I will refer you to chapter 11, page 707 of the text, and show you how I did it for my puppy class. First, add lines to the class definition before both the public and private sections that reads:
friend ostream &operator<<(ostream&, puppy); The friend keyword makes it so that the << and >> operators are able to view the private data elements of the puppy class. After that you can define the overloaded operator to do what you want. Here is what my operator definitions looked like:
ostream &operator<<(ostream &output, puppy p) { Notice that though I store the neutered private data member as a bool, I chose to output a string that is human readable instead of a 1 or 0, and then convert it back to a bool when I read the string in. We will go over this first thing on Monday. What to submit
Include the following header in your source code.
//
You will submit your To submit your program, make sure there is a copy of the source code on your account on gusun. You may name your program what you like - let's assume that it is called litter.cc. To submit your program electronically, use the submit program like we did in Homework 2 and project 1, 2, and 3 but with the command: submit -a p4 -f litter.cc
|