Fall 2004

Clay Shields


front | classes | research | personal | contact

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:

  • W : Puppy in still breeding center
  • P : Puppy released prior to raising
  • R : Puppy released to raiser
  • I : Puppy failed guide school entrance exam
  • A : Puppy given to ATF to become a "sniffer" dog
  • G : Working guide
  • B : Breeding stock

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:

  • string getFatherName()
    Returns the name of the sire of the litter.
  • string getMotherName()
    Returns the name of the mother of the litter.
  • int getBirthDay()
    Returns what day of the month the puppies were born.
  • int getBirthMonth()
    Returns what month the puppies were born.
  • int getBirthYear()
    Returns what year the puppies were born;
  • void setupLitter()
    Read information about the litter and the puppies in it from the keyboard.
  • float getSuccessRate()
    Calculates the success rate of the puppies in the litter. The success rate is the percentage of puppies who became guide dogs or breeding stock.
  • void saveLitter(string)
    Saves the litter information to a file named whatever the string parameter says.
  • void loadLitter(string)
    Loads a litter from the file specified in the string provided.
  • void print()
    Prints information about the litter somewhat neatly to the screen.
  • int getLitterSize()
    Returns how many puppies are in the litter.
Even if you do not use all the methods yourself, you should test that they work. We will test your class using a main function of our construction. You should write a main that thoroughly tests your litter class before continuing.

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);
friend istream &operator>>(istream&, 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) {

  string ntd;
 
  if (p.neutered)
    ntd = "Neutered";
  else 
    ntd = "Intact";
  
  output << p.name << " " << p.id << " " << p.weight 
   << " " << p.color  << " " << p.sex << " " 
    << ntd << " " << p.status;
  return output;
}

// overload the input operator
istream &operator>>(istream &input, puppy &p){

  string ntd;

  input >> p.name >> p.id >> p.weight >> p.color >> p.sex >> ntd >> p.status;
  if (ntd == "Intact")
    p.neutered = false;
  else 
    p.neutered = true;

   return input;

}

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.

//
// Project 4
// Name: <your name>
// E-mail: <your e-mail address>
// COSC 071
//
// In accordance with the class policies and
// Georgetown's Honor Code, I certify
// that I have neither given nor received
// any assistance on this project with the
// exceptions of the lecture notes and those
// items noted below.
//
// Description: <Describe your program>
//

You will submit your source code using the submit program. Do not submit the compiled version! I don't speak binary very well.

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