#include <iostream>
using namespace std;
class Area_cl {
protected:
double height;
double width;
public:
Area_cl(double r, double s)
{
height = r;
width = s;
}
virtual double area() = 0;
};
class Rectangle :public Area_cl {
public:
Rectangle(double r, double s) :Area_cl(r, s)
{};
double area()
{
cout << "矩形的面积为:" << height*width << endl;
return 0;
}
};
class Isosceles :public Area_cl {
public:
Isosceles(double r, double s) :Area_cl(r, s)
{};
double area()
{
cout << "三角形的面积为:" << (height*width) / 2 << endl;
return 0;
}
};
int main()
{
Area_cl *p;
Rectangle t(10.0, 5.0);
Isosceles i(4.0, 6.0);
p = &t;
p->area();
p = &i;
p->area();
system("pause");
return 0;
}
6.12
最新推荐文章于 2021-06-03 10:44:49 发布