一道C++编程各位大哥大姐帮帮小弟!!!!

2024-12-27 12:20:06
推荐回答(3个)
回答1:

#include

class shape
{ public:
virtual float GetArea()=0;
virtual float GetPerim()=0;
};

class Rectangle:public shape
{ private:
float lenght,widht,area,perim;

public:
Rectangle(float l,float w){ lenght=l;widht=w;}
float GetArea();
float GetPerim();
};

float Rectangle::GetArea()
{ return area=(lenght*widht);}

float Rectangle::GetPerim()
{ return perim=2*(lenght+widht);}

class Circle:public shape
{ private:
float radius,area,perim;

public:
Circle(float x){ radius=x;}
float GetArea(){return perim=3.14*2*radius;}
float GetPerim(){ return area=3.14*radius*radius;}
};

void main()
{ Rectangle a(20,40);
Circle b(3);
cout<<"矩形的面积是"< cout<<"矩形的周长是"< cout<<"圆的面积是"< cout<<"圆的周长是"<}
这个对么????

回答2:

??嘿嘿,有点诡异?~

回答3:

怎么帮?