用c++编写由圆和高多重继承派生出圆锥类,在主函数中能够实现圆锥体积和表面积的计算

1个回答

  • #include

    #include

    #define N 3.1415

    using namespace std;

    class Height

    {

    private:

    float h;

    public:

    Height(float h):h(h)

    {}

    float getheight()

    {

    return h;

    }

    };

    class Circle

    {

    private:

    float radius;

    public:

    Circle(float r):radius(r)

    {}

    float getradius();

    float area();

    };

    float Circle::getradius()

    {

    return radius;

    }

    float Circle::area()

    {

    return N*radius*radius;

    }

    class cone:public Height,public Circle

    {

    private:

    float line;

    public:

    cone(float h,float r):Height(h),Circle(r)

    {}

    void getline();

    float surarea();

    float volume();

    void show();

    };

    void cone::getline()

    {

    float a=getradius();

    float b=getheight();

    line=sqrt(a*a+b*b);

    }

    float cone::surarea()

    {

    return area()+N*getradius()*line;

    }

    float cone::volume()

    {

    return area()*getheight()/3;

    }

    void cone::show()

    {

    cout