#include<iostream>
#include <iostream>
using namespace std;
class shape
{
public:
virtual void getarea() = 0;
virtual void getperim() = 0;
virtual void set() = 0;
virtual void display() = 0;
};
class triangle :public shape
{
public:
double a,b,c,p;
double area, perim;
void set();
void getperim();
void getarea();
void display();
};
void triangle::set()
{
cout << "请输入三角形三条边长度" << endl;
cin >> a >> b >> c;
}
void triangle::getperim()
{
perim = a + b + c;
}
void triangle::getarea()
{
p = (a + b + c) / 2;
area = sqrt(p * (p - a) * (p - b) * (p - c));
}
void triangle::display()
{
cout << "三角形周长为" << perim << endl;
cout << "三角形面积为" << area << endl;
}
class circle :public shape
{
public:
double r;
double area, perim;
void set();
void getperim();
void getarea();
void display();
};
void circle::set()
{
cout << "请输入圆的半径" << endl;
cin >> r;
}
void circle::getperim()
{
perim = 2 * r * 3.14;
}
void circle::getarea()
{
area = r * r * 3.14;
}
void circle::display()
{
cout << "圆形形周长为" << perim << endl;
cout << "圆形形面积为" << area << endl;
}
int main()
{
shape* shape[2];
shape[0] = new triangle();
shape[1] = new circle();
for (int i = 0; i < 2; i++) {
shape[i]->set();
shape[i]->getarea();
shape[i]->getperim();
shape[i]->display();
}
return 0;
}