#include<iostream>
using namespace std;
class Shape{
public:
virtual double getArea(){
cout<<"Shape:"<<endl;
return -1;
}
virtual double example() = 0;
};
class Circle:public Shape{
public:
Circle(double _r){
_case = 1;
r = _r;
}
double getArea(){
cout<<"Circle:"<<endl;
return r*r*3.14;
}
private:
double r;
int _case;
};
class Square:public Shape{
public:
Square(double _len){
_case = 2;
len = _len;
}
double getArea(){
cout<<"Square:"<<endl;
return len*len;
}
private:
double len;
int _case;
};
void printArea(Shape *shape){
cout<<shape->getArea()<<endl;
}
void printArea(Shape &shape){
cout<<shape.getArea()<<endl;
}
int main()
{
Circle cir(2);
Square squ(4);
printArea(&cir);
printArea(cir);
printArea(&squ);
printArea(squ);
return 0;
}
#include <iostream>
using namespace std;
class Animal{
public :
Animal(int _v = 0,string s = " "){
speed = _v;
color = s;
}
virtual void eat(){
cout<<"Eat nothing"<<endl;
}
virtual void _move(){
cout<<"Move nothing"<<endl;;
}
virtual void sound(){
cout<<"Say nothing"<<endl;
}
virtual void show(){
cout<<"Show nothing"<<endl;
}
virtual ~Animal(){
cout<<"Del animal"<<endl;
}
protected:
int speed;
string color;
};
class Cat:public Animal{
public:
Cat(int v,string s):Animal(v,s){}
Cat():Animal(){}
~Cat(){
cout<<"Del cat"<<endl;
}
void sett(int v,string s){
speed = v;
color = s;
}
void show(){cout<<"I am a "<<color<<" cat."<<endl;}
void eat(){cout<<"I eat fishes"<<endl;}
void _move(){cout<<"I move at speed of"<<speed<<endl;}
void sound(){cout<<"miaomiao!"<<endl;}
};
class Dog:public Animal{
public:
Dog(int v,string s):Animal(v,s){}
Dog():Animal(){}
~Dog(){
cout<<"Del Dog"<<endl;
}
void sett(int v,string s){
speed = v;
color = s;
}
void show(){cout<<"I am a "<<color<<" dog."<<endl;}
void eat(){cout<<"I eat boons"<<endl;}
void _move(){cout<<"I move at speed of"<<speed<<endl;}
void sound(){cout<<"wangwang!"<<endl;}
};
class Bird:public Animal{
public:
Bird(int v,string s):Animal(v,s){}
Bird():Animal(){}
~Bird(){
cout<<"Del bird"<<endl;
}
void sett(int v,string s){
speed = v;
color = s;
}
void show(){cout<<"I am a "<<color<<" bird."<<endl;}
void eat(){cout<<"I eat rice"<<endl;}
void _move(){cout<<"I fly at speed of"<<speed<<endl;}
void sound(){cout<<"jiji!"<<endl;}
};
class Zoo{
public:
Zoo(int numbird,int numcat,int numdog){
numOfBird = numbird;
numOfCat = numcat;
numOfDog = numdog;
animals = new Animal*[3];
animals[0] = new Cat;
animals[1] = new Dog;
animals[2] = new Bird;
cout<<"Now we have "<<numOfCat<<" cats and "<<numOfDog<<" dogs and "<<numOfBird<<" birds."<<endl;
}
~Zoo(){
for(int i=0;i<3;i++)
delete animals[i];
delete animals;
}
void showNum(){
cout<<"Now we have "<<numOfCat<<" cats and "<<numOfDog<<" dogs and "<<numOfBird<<" birds."<<endl;
}
void setcat(int num,int v,string s){
cats[num].sett(v,s);
}
void setdog(int num,int v,string s){
dogs[num].sett(v,s);
}
void setbird(int num,int v,string s){
birds[num].sett(v,s);
}
void addcat(int v,string s){
numOfCat++;
cats[numOfCat].sett(v,s);
}
void adddog(int v,string s){
numOfCat++;
dogs[numOfDog].sett(v,s);
}
void addbird(int v,string s){
numOfCat++;
birds[numOfBird].sett(v,s);
}
void show(){
for(int i=1;i<=numOfCat;i++)
{
cats[i].show();
cats[i].sound();
}
for(int i=1;i<=numOfDog;i++)
{
dogs[i].show();
dogs[i].sound();
}
for(int i=1;i<=numOfBird;i++)
{
birds[i].show();
birds[i].sound();
}
}
void _express(Animal *ani){
ani->eat();
}
void kaiFan(){
for(int i=1;i<=numOfCat;i++)
_express(animals[0]);
for(int i=1;i<=numOfDog;i++)
_express(animals[1]);
for(int i=1;i<=numOfBird;i++)
_express(animals[2]);
}
void cutCat(int n){
numOfCat-=n;
cout<<"It is a pity that we lose "<<n<<" cats"<<endl;
}
void cutDog(int n){
numOfDog-=n;
cout<<"It is a pity that we lose "<<n<<" dogs"<<endl;
}
void cutBird(int n){
numOfBird-=n;
cout<<"It is a pity that we lose "<<n<<" birds"<<endl;
}
private:
Animal **animals;
Cat cats[505];
Dog dogs[505];
Bird birds[505];
static int numOfBird,numOfCat,numOfDog;
};
int Zoo::numOfCat = 0;
int Zoo::numOfDog = 0;
int Zoo::numOfBird = 0;
int main()
{
int numcat,numdog,numbird;
string s;int v;
cin>>numcat>>numdog>>numbird;
Zoo zoo(numcat,numdog,numbird);
return 0;
}