注册 登录
编程论坛 VC++/MFC

用继乘求圆柱的表面积和体积

尹金魁2031 发布于 2013-06-09 01:26, 769 次点击
#include<iostream>
using namespace std;

class Circle
{
protected:
    float R,S,C;
public:
    Circle(float r,float s,float c)
    {
        R=r;
        S=s;
        C=c;
    }

    void display()
    {
        S= 3.14*R*R;
C=3.14*2.*R;
        cout<<S<<endl;
        cout<<C<<endl;
    }

};

class Height
{
public:
    float h;
void set_H()
{
    cin>>h;
}

Height()
{
    H=h;
}

protected:
    float H;
};

class Cylinder:public Circle ,public Height
{
public:
    Cylinder (float s3,float v,float s,float c,float h)//从这里有问题了
    {
        S3=s3;
        V=v;
        S=s;
        C=c;
        H=h;
    }

    void display()
    {
        S3=C+S;
        V=S*H;
        cout<<S3<<endl;
        cout<<V<<endl;
    }

protected:
   
float S3,V,S,C,H;
    };

void main()
{
Circle ci(2.0);
ci.display();
Height he(4.0);
Cylinder cy;
cy.display();
}
在Height类和Circle类中多重派生出Cylinder类,在Cylinder 类中求出圆柱的表面积和体积.求大师帮忙!
2 回复
#2
尹金魁20312013-06-10 07:52
本人已经会了,结贴去!
#3
邓士林2013-06-10 17:31
其实我觉得你应该去c++教室
1