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, 22.06.2019 08:10
Technician a says that if a valve is open when a piston rises to the very top of a cylinder, the piston may actually strike the valve head and cause serious engine damage. technician b says if the camshaft is located in the engine block, then the engine is called an overhead valve engine, ohv engine, or an in-block camshaft. who is right? a. b only b. both a and b c. a only d. neither a nor b
Answers: 3
question
Computers and Technology, 22.06.2019 20:00
What side length would you specify if you were required to create a regular hexagonal plate that was composed of 33 cm(squared) of sheet metal? dimension the side length to 0.1 cm
Answers: 2
question
Computers and Technology, 23.06.2019 07:00
Why were most movies from the late 1890s until the early 1930s only filmed in black and white? there were only a few people who could afford the technology to produce color motion pictures back then. audiences did not want color motion pictures until later. the film used to make color motion pictures often overheated, which was a safety hazard, so it was generally not allowed. color films had to be hand-colored, frame by frame.
Answers: 3
question
Computers and Technology, 24.06.2019 00:30
Which boolean operator enables you to exclude a search term? a} not b} and c} or d} plus
Answers: 1
You know the right answer?
Virtual function to ENABLE the later selection of desired function in polymorphism

Creat...
Questions
Questions on the website: 13722362