Write a program with a mother class Animal | Write two child classes zebra and dolphin show the information of zebra and dolphin
Write a program with a mother class Animal.
Inside it define an age and a nmae and set_value function.
write two child classes zebra and dolphin show the information of zebra and dolphin
Then create two bases object Zebra & Dolphin which write a message telling the
age and the name and give some extra information (e.g place of orgin)
Hint:
zeb.set_data(10,n1);
dol.set_data(8,n2)
Program Source Code:
#include<iostream>
#include<string.h>
using namespace std;
class Animal{
protected:
int age;
char name[20];
public:
void set_data(int a, char n[]){
age = a;
strcpy(name, n);
}
};
class Zebra : public Animal{
public:
show_Z(){
cout<<"The zebra name is "<<name <<" and "<<" age is "<<age<<" | zebra comes from Kenya."<<endl;
}
};
class Dolphin : public Animal{
public:
show_D(){
cout<<"The dolphin name is "<<name <<" and "<<" age is "<<age<<"| Dolphin comes from Sri Lanka."<<endl;
}
};
main(){
Zebra Z;
Dolphin D;
char n1[10] = "Shero", n2[10] ="Pari";
Z.set_data(10,n1);
Z.show_Z();
D.set_data(5,n2);
D.show_D();
}
Output
Post a Comment