用c++ 类编程

来源:百度知道 编辑:UC知道 时间:2024/06/08 18:08:11
使用成员函数重载设计一个求面积的类,包括圆,三角形和梯形。并设计一个输入成员函数和输出成员函数。

class CalSquare
{
private:
double m_area;
public:
void input(double r)
{m_area=3.14*r*r;}
void input(double bottom,double height)
{m_area=0.5*bottom*height;}
void input(double top,double bottom,double height)
{m_area=0.5*(top+bottom)*height;}
void output()
{cout<<m_area<<endl;}
};

class Shape
{
virtual float MJ( ) const;
};

class Circle : public Shape
{
Circle( );
Circle( float radius );

void SetRadius( float radius );
float GetRadius( ) const;

virtual float MJ const;

private:
float _radius;
};

class SJX: public Shape
{
//...
}; //...
class TX: public Shape
{
//...
}; // ...