纯虚函数
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include
using namespace std;
const double PI=3.1415926;
class Shape
{
public:
virtual double Area()=0;
};
class Triangle:public Shape
{
private:
double d,h;
public:
Triangle(double di,double gao)
{
d=di;
h=gao;
}
double Area()
{
cout<<"三角形面积为:";
return d*h*1/2;
}
};
class Circle:public Shape
{
private:
double r;
public:
Circle(double radius)
{
r=radius;
}
double Area()
{
cout<<"圆面积为:";
return PI*r*r;
}
};
class Ractangle:public Shape
{
private:
double a,b;
public:
Ractangle(double chang,double kuang)
{
a=chang;
b=kuang;
}
double Area()
{
cout<<"矩形面积为:";
return a*b;
}
};
void main()
{
Shape *p;
double a,b;
cout<<"请输入三角形底边和高:";
cin>>a>>b;
Triangle t(a,b);
p=&t;
cout< cout<<"请输入圆的半径:"; cin>>a; Circle c(a); p=&c; cout< cout<<"请输入矩形两边长:"; cin>>a>>b; Ractangle r(a,b); p=&r; cout< }