#include <string>
#include<iostream>
using namespace std;
#define PI 3.14159f
class Shape
{public:
virtual void set() = 0;
virtual float getarea() = 0;
};
class Circle :public Shape
{
private:
float r;
public:
void set()
{
cin >> r;
}
float getarea()
{
return PI * r * r;
}
};
class Square :public Shape
{
private:
float d;
public:
void set()
{
cin >> d;
}
float getarea()
{
return d*d;
}
};
class Rectangle :public Shape
{
private:
float l,h;
public:
void set()
{
cin >> l>>h;
}
float getarea()
{
return l * h;
}
};
class Trapezoid :public Shape
{
private:
float a,b,c;
public:
void set()
{
cin >> a>>b>>c;
}
float getarea()
{
return ((a + b) * c) / 2;
}
};
class Triangle :public Shape
{
private:
float a,b;
public:
void set()
{
cin >> a>>b;
}
float getarea()
{
return a*b/2;
}
};
void get(Shape& s)
{
s.set();
}
float getwork(Shape &s)
{
return s.getarea();
}
int main()
{
Circle c;
Square s;
Rectangle r;
Trapezoid t;
Triangle t1;
get(c);
get(s);
get(r);
get(t);
get(t1);
printf("%.3f\n", getwork(c) + getwork(s) + getwork(r) + getwork(t) + getwork(t1));
}
标签:set,23,getarea,void,float,Shape,打卡,public
From: https://www.cnblogs.com/gyg1222/p/17434406.html