Animal Kingdom
Question Description
Description
This assignment is an opportunity for you to practice using virtual functions. You are to implement 7 simple classes with 0 or 1 member variable:
- Animal (Grandparent)
- Mammal (Parent)
- Human (Grandkid)
- Cat (Grandkid)
- Bird (Parent)
- Owl (Grandkid)
- Duck (Grandkid)
- Mammal (Parent)
In your main.cpp, you will have the following code:
#include <iostream>
#include "animal.h"
using namespace std;
int main() {
Cat cat;
Human human("English");
Animal *animals[4];
animals[0] = new Duck;
animals[1] = new Owl;
animals[2] = &cat;
animals[3] = &human;
for (int i=0; i < 4; i++) {
animals[i]->make_sound();
}
delete animals[0];
delete animals[1];
return 0;
}
Expected Output
I quack
I hoot
I meow
I speak English
Given
You are given the following file:
lab15_0_animal_kingdom_main.cpp
What to Submit
Submit two files for this lab:
- animal.h
- animal.cpp
Tips
- For some of your classes, you will have a string member variable “sounds_made” to hold either “quack”, “hoot”, “meow”, or “speak”
- For the Human class, you will have a string member variable “language” which can hold the mother tongue language the human speaks.
- Not all classes will need to implement make_sound() function.
- Watch Video Lecture 15-4 for virtual function discussion.
Requirements
- Write as few lines of code possible, make use of the power of inheritance.
- Clear and concise comments and programming style.
Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."