【文件属性】:
文件名称:《面向对象程序设计C++》试卷
文件大小:58KB
文件格式:DOC
更新时间:2016-06-27 13:42:18
期末考试必备
#include
using namespace std;
class base
{ public:
virtual float area() const
{ return 0; }
};
class triangle: public base
{ protected:
float bian,height;
public:
triangle(float a=0, float h=0) { bian=a; height=h; }
virtual float area() const
{ return bian*height/2; }
};
class square: public base
{ protected:
float bian;
public:
square(float a=0) { bian=a; }
virtual float area() const
{ return bian*bian; }
};
class circle: public base
{ protected:
float radius;
public:
circle(float r=0) { radius=r; }
virtual float area() const
{ return 3.14*radius*radius; }
};
int main()
{ triangle t(3,4); square s(5); circle c(2);
base *p;
p=&t; cout<<"triangle's area:"<area()<area()<area()<