1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include <iostream>
#include <string>
using namespace std;
class animal{
public:
virtual void name(){cout<<"This animal is a : "<<type;};
virtual void phy(){cout<<"The animal's height and weight are as follows: "<<endl<<"Hieght: "<<height<<"\t"<<"Weight: "<<weight<<endl;}
virtual void config(){cout<<"Enter a new height (using standard units): "; cin>>height; cout<<"\nEnter a new weight (using standard units): ";cin>>weight; cout<<"Here are the new height and weight values:"<<endl<<height<<weight<<endl;}
virtual void convert(){ metric_height = height * 2.8; metric_weight = weight / 2.2; }
animal(string a="NULL", int b=0, int c=0){type=a; height=b; metric_height=b; weight=c; metric_weight=c;}
string type;
int height,weight,metric_height,metric_weight;
};
class lion: public animal{
public:
void name(){cout<<"This animal is a : "<<type;};
void phy(){cout<<"The animal's height and weight are as follows: "<<endl<<"Hieght: "<<height<<"\t"<<"Weight: "<<weight<<endl;}
void config(){cout<<"Enter a new height (using standard units): "; cin>>height; cout<<"\nEnter a new weight (using standard units): ";cin>>weight; cout<<"Here are the new height and weight values:"<<endl<<height<<weight<<endl;}
void convert(){ metric_height = height * 2.8; metric_weight = weight / 2.2; }
lion(string inType, int firstInt, int secondInt):animal(inType, firstInt, secondInt){};
};
class dog: public animal{
public:
void name(){cout<<"This animal is a : "<<type;};
void phy(){cout<<"The animal's height and weight are as follows: "<<endl<<"Hieght: "<<height<<"\t"<<"Weight: "<<weight<<endl;}
void config(){cout<<"Enter a new height (using standard units): "; cin>>height; cout<<"\nEnter a new weight (using standard units): ";cin>>weight; cout<<"Here are the new height and weight values:"<<endl<<height<<weight<<endl;}
void convert(){ metric_height = height * 2.8; metric_weight = weight / 2.2; }
dog(string inType, int firstInt, int secondInt): animal(inType, firstInt, secondInt){};
};
int main(){
lion a("lion",45,300);
dog b("dog",60,120);
animal *obj[2]={&a,&b};
system("COLOR 1F");
return 0;
}
|