I am trying to create a class name Dog with a string field for the Dog’s name. Create a class
Cat with a string field for the Cat’s name. Write a program that declares one Dog and one
Cat, and assign names to them.
But it not working
seeplus
this is the question
Create a class name Dog with a string field for the Dog’s name. Create a class
Cat with a string field for the Cat’s name. Write a program that declares one Dog and one
Cat, and assign names to them.
Declare a member function speak() for each of the class with different
implementation such as cout <<”A dog speaks.”<<endl; and cout <<”A cat
speaks.”<<endl;
Write two overloaded functions named speak(…). If you pass a Dog argument to
speak functions, the relevant speak function should display the Dog’s name and a
description of how dogs speak (for example, “Spot says woof”). If you pass a Cat
argument to speak functions, then it should display the Cat’s name and a
description of how cats speak (for example, “Tiger says meow”).
In your main program, instantiate a dog instance and a cat instance, try to activate
the member functions and the overloaded functions.
I am learning also ATM. but if you make a class called animal and put all the common stuff you want all animals to have like name, speak and owner lets say. You can inherit animal and have all the functionality without having to rewrite the same code in every class.