subject

Virtual function to ENABLE the later selection of desired function in polymorphism

Create an animal base class.

string animalName;

string sound

virtual animalSound() { cout << AnimalName << " says " << sound << endl;

Create 4 SETUP new derived classes based on animal, that OVERRIDE the virtual function, animalSound, with the specific animal noise,

and assign the animal name to the base animal name variable.

cat

dog

elephant

mouse

Declare instances of each of the 4 different animals. C1, D1, E1, M1.

Write a switch statement that prints out the animal noise, depending on which animal is chosen.

prompt the user for the type of animal, compare with switch statement, and print out animal sound.

Part 2 - Funciton

(Base and Derived classes should already be coded in part 1.

Create an animal base class.

string animalName;

string sound

virtual animalSound() { cout << AnimalName << " says " << sound << endl;

Create 4 new derived classes based on animal, that override the virtual function, animalSound, with the specific animal noise,

and assign the animal name to the base animal name variable.

cat

dog

elephant

mouse

Declare instances of each of the 4 different animals. C1, D1, E1, M1.

Write a function that has one parameter, a derived pointer

The function void polyNoise( baseClass * ptrBase ) { cout ptrBase->animalSound;}

//Note polymorphis - This one line of code should work for ALL/Any of the different derived classes.

Call the function 4 times, pass each animal derived pointer to it and the output should be the correct animal sound.

Part 3 - loop

(Base and Derived classes should already be coded in part 1.

Create an animal base class.

string animalName;

string sound

virtual animalSound() { cout << AnimalName << " says " << sound << endl;

Create 4 new derived classes based on animal, that override the virtual function, animalSound, with the specific animal noise,

and assign the animal name to the base animal name variable.

cat

dog

elephant

mouse

Declare instances of each of the 4 different animals. C1, D1, E1, M1.

Declare an array of 4 of type animal

animal * ptrBaseAnimal = new animal[4];

Declare instances of each of the 4 different animals. C1, D1, E1, M1.

Assign the derived address of each to on element in the base array.

Write a for loop to print out the animal noices

for ( int I = 0 ; I < 4 ; I++) {

ptrBaseAnimal[I]->animalSound;
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 00:30
Which one of the following is the most accurate definition of technology? a electronic tools that improve functionality b electronic tools that provide entertainment or practical value c any type of tool that serves a practical function d any type of tool that enhances communication
Answers: 1
question
Computers and Technology, 23.06.2019 16:00
Which analyst position analyzes information using mathematical models to business managers make decisions?
Answers: 1
question
Computers and Technology, 23.06.2019 17:30
Per the municipal solid waste report, what are the most common sources of waste (trash
Answers: 3
question
Computers and Technology, 25.06.2019 00:00
To remove text from a specific location and keep it to use again, you should select
Answers: 1
You know the right answer?
Virtual function to ENABLE the later selection of desired function in polymorphism

Creat...
Questions
question
English, 05.07.2019 07:30
question
World Languages, 05.07.2019 07:30
Questions on the website: 13722361