Homework 6, Abstract Classes..
Short Description:
Write a program that will demonstrate abstract classes.
This assignment is worth 10 points.
Goals
When you finish this homework, you should have:
- Have built a simple hierarchy that includes
- Pure virtual functions.
- Abstract classes.
- Used ctor-initializers
- Used static member data and functions.
- Used const member data.
Formal Description
Please complete the following steps.
- Create a directory for this assignment.
- Start by building an abstract base class.
- We will build a basic animal class example.
- An animal has a unique id and a name..
- The id is a constant int , it should be based on a parameter to the constructor.
- The name is a string.
- An animal has the following methods
- MakeNoise, a pure virtual void function that prints the animal noise.
- Identify, a virtual void function that prints the name and the id number of the animal.
- GetName a virtual function that returns a string, the animal's name.
- SetName, a virtual void function that takes a string and sets the animal's name.
- ID, a virtual function that returns an integer.
- A default virtual destructor.
- A constructor that that takes an integer id and a string name.
- Call you class AnimalT
- In AnimailT.h make sure that
- You use a ctor initializer in your constructor.
- Declare the destructor to be default.
- MakeNoise must be pure virtual.
- In AnimalT.cpp
- Modify the supplied Makefile to build the abstract class.
- Build a main program.
- Build a concrete DogT class.
- This class should have the following members
- A static int representing the number created.
- This should be initialized to zero.
- It should be incremented each time an instance of the class is declared.
- A MakeNoise function that prints "Woof!"
- A Identify function that prints "A Dog" before calling the base class Identify function.
- A static function DogCount that returns the number of dogs that have been declared.
- Please make sure that you
- Use the override keyword when appropriate.
- Make your first dog have ID 1.
- Do not use static or virtual in your implementation file.
- Add DogT to your Makefile
- DogT.o should depend on DogT.h and AnimalT.h
- main should depend on DogT.o
- Modify your main to have a
DogTest
function
- Print the number of dogs before an instance is declared
- Declare a dog named "Rover".
- Call all dog functions.
- Print the number of dogs after rover id declared.
- My Files
- Derive a cat class based on the AnimalT
- Since cats have 9 lives, every cat adds 9 to the cat count.
- Cats say "Meow!"
- Cats are identified as "A Cat"
- Add the cat class to the Makefile.
- Add a catTest function that does a basic test of the cat class to main.
- Add A new function.
- Add a new virtual abstract function to the base class.
- It should return a vector of AnimalT *
- Called Reproduce
- Dogs always produce 4 offspring
- Names:
-
name
-son1
-
name
-son2
-
name
-daughter1
-
name
-daughter2
- Cats produce between 1 and 5 offspring.
- Use the naming scheme above, but alter the number to be correct.
- 50% chance for each gender
-
to_string
might be helpful here.
- Change main
Required Files
A single tar file containing the source code and makefile for this program.
Submission
Submit your tar file to the d2l assignment folder by the due date.