#include <iostream>
#include<cmath>
using namespace std;
class graphical
{
protected:
float perm;
float area;
public:
virtual void get_perm()=0;
virtual void get_area()=0;
};
class rectangele : public graphical
{
private:
float length;
float wide;
public:
rectangele(float l,float w)
{
length=l;
wide=w;
}
void get_perm()
{
perm= 2*(length+wide);
cout<<perm<<endl;
}
void get_area()
{
area= length*wide;
cout<<area<<endl;
}
};
class circle : public graphical
{
private:
float radius;
public:
circle(float r)
{
radius=r;
}
void get_perm()
{
perm= 2*M_PI*radius;
cout<<perm<<endl;
}
void get_area()
{
area= M_PI*radius*radius;
cout<<area<<endl;
}
};
class triangle: public graphical
{
private:
float a,b,c;
public:
triangle(float x,float y,float z)
{
a=x;
b=y;
c=z;
}
void get_perm()
{
perm= a+b+c;
cout<<perm<<endl;
}
void get_area()
{
float s=(a+b+c)/2;
area= sqrt(s*(s-a)*(s-b)*(s-c));
cout<<area<<endl;
}
};
void perm_area(graphical& s)
{
s.get_perm();
s.get_area();
return ;
}
int main()
{
rectangele r(5,6);
circle c(4);
triangle t(3,4,5);
perm_area(r);
perm_area(c);
perm_area(t);
return 0;
}
08-31
1904
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-29
479
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)