#include"iostream"
#include"math.h"
using namespace std;
class shape
{
public:
virtual int GetArea()=0;
virtual int GetPeri()=0;
virtual void print()=0;
};
class rectangle:virtual public shape
{
private:
int x,y;
public:
rectangle(int a,int b):x(a),y(b){}
int GetArea()
{
return (x*y);
}
int GetPeri()
{
return 2*x+2*y;
}
void print()
{
cout<<"矩形的面积:"<<GetArea()<<" "<<"矩形的周长:"<<GetPeri()<<endl;
}
};
class triangle:virtual public shape
{
private:
int x,y,z;
public:
triangle(int a,int b,int c):x(a),y(b),z(c){}
int GetArea()
{
int aa=(x+y+z)/2;
return sqrt(aa*(aa-x)*(aa-y)*(aa-z));
}
int GetPeri()
{
return x+y+z;
}
void print()
{
cout<<"三角形的面积:"<<GetArea()<<" "<<"三角形的周长:"<<GetPeri()<<endl;
}
};
class trapezoid:virtual public shape
{
private:
int x,y,z,zz;
public:
trapezoid(int a,int b,int c,int d):x(a),y(b),z(c),zz(d){}
int GetArea()
{
return (x+y)*z/2;
}
int GetPeri()
{
return x+y+2*zz;
}
void print()
{
cout<<"梯形的面积:"<<GetArea()<<" "<<"梯形的周长:"<<GetPeri()<<endl;
}
};
int main()
{
rectangle r1(2,3);
triangle t1(3,4,5);
trapezoid t2(2,3,4,5);
r1.print();
t1.print();
t2.print();
return 0;
}
我刚学C++,如果想自己输入数字,应该怎么改,麻烦看一下