Answer to Question #231992 in C++ for mahnoor

Question #231992

Write a probram with a mother class animal. Inside it define a name and an age variables, and set_value() function.Then create two bases variables Zebra and Dolphin which write a message telling the age, the name etc.



1
Expert's answer
2021-09-01T23:56:47-0400


#include <iostream>
#include <string>
using namespace std;


class Animal
{
	protected:
	 //Declaring the members of mother class Animal
	 string name;
	 int age;
	public:
	 void set_value (int a, string n)
	 {
		age = a;
		name = n;
	 }


};


class Zebra:public Animal{
public:
void displayZebraMessage()
{
cout<< "The zebra name is "<<name<<". The zebra is "<< age << " years old \n";}
};


class Dolphin: public Animal
{
public:


void displayDolphinMessage()
{
cout<< "The dolphin name is:  "<< name<< ". The dolphin is "<<age << "years old\n";}
};




int main ()
{


	
	Zebra zebra;
	Dolphin dolphin;
	string n1="Ana";
	string n2="Jin";


	zebra.set_value (5,n1);
	dolphin.set_value (2,n2);


	zebra.displayZebraMessage() ;
	dolphin.displayDolphinMessage() ;


	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS