Question: #include using namespace std; class Animal { public: Animal(string n): name(n) {} virtual ~Animal() {} virtual void makeNoise() = 0; protected: string name; }; class

#include using namespace std;

class Animal { public: Animal(string n): name(n) {} virtual ~Animal() {} virtual void makeNoise() = 0; protected: string name; };

class Dog: public Animal { public: Dog(string n): Animal(n) {} void makeNoise() override { cout << name << " says woof!" << endl; } };

class Cat: public Animal { public: Cat(string n): Animal(n) {} void makeNoise() override { cout << name << " says meow!" << endl; } };

int main () { Dog myDog("Lassie"); myDog.makeNoise(); Cat myCat("Bella"); myCat.makeNoise(); return 0; }

-------------------------------------------------------

in main () add an array of four animals, two dogs and two cats. then use a for loop to call the makeNoise () function for each array element.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!