Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Download the file Animal.h. It contains an Animal class that stores the name and age of an animal. Besides the appropriate constructors, getters, and setters

Download the file Animal.h. It contains an Animal class that stores the name and age of an animal. Besides the appropriate constructors, getters, and setters it has a function called feed() which prints out the message "Some food, please!".

Dogs are animals too, so we can extend the Animal class to produce a Dog class. We only need to change the constructors and destructors of the Dog class to print the appropriate messages and we need to change the feed() function to print a message saying "A bone, please!"

Your class should be stored in a file called Dog.h. Your solution will be tested with the file animals.cpp.

Animal.h:

#ifndef LA4_Animal_h #define LA4_Animal_h #include #include #include using namespace std; class Animal { string name; int age; public: Animal(){ cout << "Creating Generic Animal" << endl; name = "Generic Animal"; age = 0; } void display (const vector & list){ } string getName(){ return name; } void setName(string name){ this->name = name; } int getAge(){ return age; } void setAge(int age){ this->age = age; } ~Animal(){ cout << "Deleting Generic Animal" << endl; } void feed(){ cout << "Some food, please!" << endl; } }; #endif 

animals.cpp:

#include #include "Dog.h" using namespace std; int main(int argc, const char * argv[]) { Dog myDog = Dog("Snoopy", 4); cout << myDog.getName() << " is " << myDog.getAge() << endl; return 0; } 

Sample Output:

Creating Generic Animal Creating Dog Snoopy is 4 Deleting Dog Deleting Generic Animal

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

5. Discuss the key components of behavior modeling training.

Answered: 1 week ago

Question

4. Develop a self-directed learning module.

Answered: 1 week ago