Project 2
Summer 2010
Due: Thu, Jul 29 @ 10 PM
10 points
In this project, you will use classes, inheritance, and polymorphism to implement software that stores information about different varieties of pets. For simplicity, we will assume that pets are one of two kinds, cat or dog. Apologies to bird lovers!
I have produced the documentation that you will need for this project:
P2 DocumentationAs the documentation indicates, you should implement the Pet class and derive two subclasses, Cat and Dog. All pets have a name and an age. Cats have a certain number of lives. Dogs have no special attributes, but the class implements a method for computing the dog's age in so-called dog years. Each class should have virtual methods that read and print the pet's information from and to a stream, respectively. Naturally, the set methods should perform range checks and throw an out_of_range exception if passed invalid values.
Storing a single type of pet is not very interesting, so also implement a Pets (plural) class that stores pointers to Pet objects in a C++ vector. Implement methods to read pets from a file, print the pets stored in the vector, and compute the total age of those pets.
Design your own input file that stores information about pets: their type, name, age, and, if applicable, lives. Fabricate data for a number of pets, noting that pets often have names that consist of two strings (e.g., Lady Chatterley ). Store the information in the file pets.dta. Two examples are:
cat 3 9 mr. whiskers dog 2 maddie
In the main function, write a simple driver program that reads pets from your data file, prints them to the console, and prints the total age of the pets. For cats, use their actual age, but for dogs, use their age in dog years. If the data file does not exist, then main should issue an appropriate message and exit.
Use stepwise refinement and incremental development. For example, implement the Pet class and test it thoroughly before implementing, say, the Cat class.
Instructions for Electronic Submission
At the top of the file main.cc (or the file containing the main function), place the following header comment, with the appropriate substitutions:
/* * COSC 072 Project 2 * Name: <your name> * ID: <GoCard ID> * E-mail: <e-mail address> * Instructor: Maloof * * In accordance with the class policies and Georgetown's Honor Code, * I certify that, with the exceptions of the class resources and those * items noted below, I have neither given nor received any assistance * on this project. */
You'll be submitting p2 exactly like you submitted hw1 and p1. If you need to include a message about your submission, then place the message in a file named README. Place the README file in the project's directory. Just zip it up and submit it via Blackboard.
Copyright © 2019 Mark Maloof. All Rights Reserved. This material may not be published, broadcast, rewritten, or redistributed.