Question
#include using namespace std; class Animal { public: Animal(string n): name(n) {} virtual ~Animal() {} virtual void makeNoise() = 0; protected: string name; }; class
#include
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started