#include <iostream>
#include <iomanip>
using namespace std;
class Shape
{
public:
virtual double area() const = 0;
};
class Circle:public Shape
{
private :
double r;
public :
Circle(double rr):r(rr){}
virtual double area() const
{
double s=3.1415926*r*r;
return s;
}
};
class Square:public Shape
{
private :
double l;
public :
Square(double ll):l(ll){}
virtual double area() const
{
double s=l*l;
return s;
}
};
class Rectangle:public Shape
{
private :
double w;
double h;
public :
Rectangle(double ww,double hh):w(ww),h(hh){}
virtual double area() const
{
double s=h*w;
return s;
}
};
class Trapezoid:public Shape
{
private :
double w1;
double w2;
double h;
public :
Trapezoid(double ww1,double ww2,double hh):w1(ww1),w2(ww2),h(hh){}
virtual
第十四周 oj 利用虚函数-计算图形面积
最新推荐文章于 2023-10-28 21:06:56 发布
博主在oj平台上完成了一道利用虚函数计算图形面积的题目,虽然初次运行结果正确,但在提交时因误用C语言导致提交失败,意识到自己的粗心大意。
摘要由CSDN通过智能技术生成