Question: Write the code by c++ and use pointers as well * design an Animal class, the class name is Animal Here are the requirements: In

Write the code by c++ and use pointers as well

* design an Animal class, the class name is Animal

Here are the requirements:

In this class, it has 2 private variables.

o myVoice

o animalName

In this class, it has 3 public functions

o The 1st one is the constructor

This is how it looks like: Animal(string, string);

Since the Animal constructor takes in 2 parameters, you will need to implement that independently. In other words, the implementation is outside of the Animal class scope

So you will need the scope resolution operator, the double colon ::, when your implementation is outside of the class.

Animal::Animal(string passedInName, string passedInVoice)

The content of the constructor is your job. Hint: To deal with the 2 parameters

o The 2nd one is the function for Animals to make some noise

void animalVoice();

When you pass the parameter into the constructor, the 2nd parameter, passedInVoice decides its voice

o The 3rd one is the function to get Animals name. i.e. dog, cat, bird

string getAnimalName();

Now, in the main() function, I can do this to test all the animals by different parameters. Similarly, I can test dogs, birds, frogs,.

o For example, if I type this: Animal animal1("cat", "meow~meow~"); cout << "Hello! I am a : " << animal1.getAnimalName() << endl; animal1.animalVoice(); This will print out onto your screen: Hello! I am a : cat meow~meow~

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!