# 编程题：多态--动物叫

/*

*/
#include <iostream>
using namespace std;

class animal   //抽象基类---动物类
{
public:
virtual void jiao()=0;  //纯虚函数
};
//将程序需要的其他成份写在下面，只提交begin到end部分的代码
//******************** begin ********************

//********************* end ********************
int main()
{
animal *p=NULL;  //指向基类的指针
dog  d;  //dog类对象
cat  c;  //cat类对象
p=&d;  //指向基类的指针指向派生类dog对象
p->jiao(); //输出wangwang
p=&c;  //指向基类的指针指向派生类cat对象
p->jiao(); //输出miaomiao
return 0;
}

wangwang

miaomiao

``````wangwang
miaomiao``````

``````#include"stdio.h"
int main( )
{ float x,y;

scanf("%f",&x);
if(x<1)
{y=x;
printf("%.2f\n",y);
}
else  if(x<10)
{y=2*x-1;
printf("%.2f\n",y);
}
else
{y=3*x-11;
printf("%.2f\n",y);
}
}
``````

``````
#include <iostream>;
#include <cmath>;
using namespace std;
class Point
{
private:
int x1,y1,x2,y2,h;
public:
Point(int X1,int Y1,int X2,int Y2,int H):x1(X1),y1(Y1),x2(X2),y2(Y2),h(H){}
int Width(){return fabs(y1-y2);}
int Long(){return fabs(x1-x2);}
int get_h(){return h;}

};
class underside: public Point//底面积类
{
public:
underside(int X1,int Y1,int X2,int Y2,int H):Point(X1,Y1,X2, Y2, H){}
int area(){return Long()*Width();}
};
class flank:public Point//侧面积类
{
public:
flank(int X1,int Y1,int X2,int Y2,int H):Point(X1,Y1,X2, Y2, H){}
int area()
{return Width()*get_h();}
};
class super_area :public underside,public flank//表面积类
{
public:
super_area(int X1,int Y1,int X2,int Y2,int H):flank( X1,Y1,X2,Y2,H),underside(X1,Y1,X2,Y2,H){}
int area();
};int super_area::area()
{
int s;
s=flank::area()*4+underside::area()*2;
cout<<"表面积为"<<s<<endl;
return 0;
}

int main()
{
super_area a(1,1,2,2,3);
a.area();
return 0;
}``````