Fall 2004

Clay Shields


front | classes | research | personal | contact

Project 3 - Guide Puppy Growth Prediction

Assigned: October 27, 2004
Design due: November 3, 2004
Program Source code due: November 10, 2004

Guide Puppy Growth Prediction


Now that the guide dog organization has some master programmers available, they want to try some more sophisticated techniques in raising their puppies.

Specifically, they suspect there is a relationship between how fast the puppies grew and eventual health problems as adult guides. All puppies are currently fed as a litter and they think that the larger pups are eating more and growing faster at the expense of the smaller pups. They think that the pups who eat more tend to be overweight as adults and they the smaller pups who eat less are more prone to infection.

They do have do have historical data from weighing the puppies periodically after they have been weaned to solid food going back to about 1992. They also know from veterinary experiments how much the dogs should weigh at different ages by sex, as shown below:

Puppies' Age
(in weeks)
Average Weight
of Male (grams)
Average Weight
of Female (grams)
4
2000
1800
5
2750
2500
6
3750
3450
7
5100
4550
8
6500
5750
9
7700
7200

What they would like you to do is write a program that will read files that have the data about individual puppies, and to write out a file that contains the same data, but with a record added at the end about whether the pup was more that 20% over the normal weight or under it for each date it was weighed. The input files have the format:

<Puppy name>
<Puppy Birthday>
<Sex>
<Color>
<Father's name>
<Mother's name>
<Date 1> <Weight 1>
<Date 2> <Weight 2>
<Date 3> <Weight 3>
<Date 4> <Weight 4>

The output file should have the format:

<Puppy name>
<Puppy Birthday>
<Sex>
<Color>
<Father's name>
<Mother's name>
<Date 1> <Weight 1> <status>
<Date 2> <Weight 2> <status>
<Date 3> <Weight 3> <status>
<Date 4> <Weight 4> <status>

where <status> is one of: Average, Overweight, Underweight, depending on if the pup is within 20% of average, or above or below that.

There is a small problem with the files, though. The volunteers who weighed the puppies don't come in regularly, so some of the weighings are off from when they should have been. Because the pups do grow so fast, you cannot just use the closest weekly weight. Instead, you will need to find out how many days old the pup was when it was weighed and then use linear interpolation between the weights by week and compare against that calculated value.

Here is a sample of what a data file might look like:

Benny
12/17/2003
Male
Black
Gordie
Francine
1/21/2004 2150
1/28/2004 3600
2/5/2004 5450
2/13/2004 6700

Here are two sample data files and their output:

kaiser
kaiser.out

francine
francine.out

And this is what my version of the program looks like when it runs, though it isn't too helpful:

gusun> growpup
This program parses puppy data files and labels the
puppies' weight as underweight, average, or overweight.

Please enter the input file name: kaiser
Please enter the output file name: kaiser.out

Hints and requirements


Since one goal of this project is to learn to use functions, you must include one call-by-value function and one call-by-reference function in your submission (if you don't know what those are yet, don't worry - we will get to them first thing next class).

The hard part of this project is reading the dates and computing how many days passed between them. To give you an idea how to do this, I outline the functions I use in my solution and hot to implement and test them. It is only a suggestion, and you may choose to do it differently. I certainly recommend you do not write the program all at once. Instead, write pieces and test each separately. This program seems big, but is really built from many small pieces, none of which is complicated on its own.

  • First, implement a function called something like DatesFromString that takes a string and three reference integers as arguments. The string will be the date read in the format in the file, and the three ints the values to be passed back for the day, week, and month from it. You will need to loop over the string, find the substrings for day, month, and year, and convert each substring into an int to return them. You can and should use the library call atoi to do this. The book has information on atoi in Section 12.3, page 778.
  • Now test the function by writing a small main that just takes input from the keyboard, passes it to DatesFromString, and outputs what was read as ints. Try many values to make sure it works.
  • Once that works, implement a function called DayOfYear that given a day, month, and year, returns an int that tells you which day of the year it is from 1 to 365 (or 366 for leap years). As part of this, you might want to write a function called DaysInMonth that given a month, returns how many days are in it.
  • Now test your function by extending the main you wrote above to figure out what day each date you enter is. You can verify your function works by hand, or by checking against a site like this.
  • Now write a function called DaysBetweenDates that takes two strings as an argument, each of which is formatted as shown in the example file, and returns an integer with the number of days between those dates. This function will need to call the others you have written above to figure out which day of the year each is and find the number of days between them. Remember, this doesn't have to be terribly complex, since it will never be more than about 8 or 9 weeks between dates.
  • Once again, write a small main that will take two dates as input then call the function above and output the results. You can verify this by hand or by checking against a site like this.
  • Now write a function called InterpolateWeight that gives you the average weight of a puppy based on its sex and how old it is in days. Write a small main program that allows you to give it input, and then test it by hand.
  • Finally, write a last main that uses all the pieces above to fulfill the assignment.

What to submit


Part 1 - Design Document

For the first part you are to submit a design document showing the algorithm you plan to implement. Do not submit a flowchart for this assignment. You should write it out neatly using a language which is similar to that from Homework 1 and has the following terms:
  1. input
  2. output
  3. calculate
  4. if condition, then statement
  5. if condition, then statement; otherwise, statement
  6. switch case* statement [case* statement]*
  7. while (condition) statement
  8. do statement while (condition)
  9. for (start;stop;increment) statement
  10. function <name> (parameters)
  11. start
  12. stop
If you need to group multiple statements together, say in an if statement, use
    begin
       statement
       ...
       statement
    end
You may refer to the functions you define by writing their name and putting the parameters it will use in parenthesis.
A copy of your algorithm is due in class. Be sure to keep a copy for yourself!

Part 2 - Program Source Code

Include the following header in your source code.

//
// Project 3
// 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 growpups.cc. To submit your program electronically, use the submit program like we did in Homework 2 and project 1, but with the command:

submit -a p3 -f growpups.cc

I will not be enabling the electronic submission until after the design documents are in, so don't try to submit too early.