Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

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

Step: 3

blur-text-image

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

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

1. What is your age? 45 or younger 4655 5665 6675 7685 86 or older

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago