首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

麻烦大家帮小弟我看上这个哪里出错了

2012-09-22 
麻烦大家帮我看下这个哪里出错了。可能是构造函数不对,我不是很懂,执行结果都是0,没有人问,上这里来求助了,

麻烦大家帮我看下这个哪里出错了。
可能是构造函数不对,我不是很懂,执行结果都是0,没有人问,上这里来求助了,帮忙看下,谢谢

#include<iostream.h>
#define PI 3.1416

class Circle
{
protected:
double r;
public:
Circle()
{
r=0;
}
Circle(double a):r(a){}

double getCircleArea()
{
double area;
area=PI*r*r;
return area;
}
double getCircleLength()
{
double length;
length=2*PI*r;
return length;
}
};
class Cylinder:public Circle
{
protected:
double h;

public:
Cylinder()
{
h=0;
}

Cylinder(double b):h(b){}
double getCylinderArea()
{
double area1,area2,area;
area1=getCircleLength()*h;
area2=getCircleArea()*2;
area=area1+area2;
return area;
}
double getCylinderVolume()
{
double volume;
volume=getCircleArea()*h;
return volume;
}

};
void main()
{
Circle cir(3);
Cylinder cyl(4);
cout<<"圆柱的面积:"<<cyl.getCylinderArea()<<endl;
cout<<"圆柱的体积:"<<cyl.getCylinderVolume()<<endl;
}






[解决办法]
注意参数列表:
这样来吧:

C/C++ code
#include<iostream.h>#define PI 3.1416class Circle{protected:    double r;public:    Circle()    {        r=0;    }    Circle(double a)    {        r=a;    }        double getCircleArea()    {        double area;        cout << r <<endl;        area=PI*r*r;        return area;    }    double getCircleLength()    {        double length;        length=2*PI*r;        return length;    }};class Cylinder:public Circle{protected:    double h;    public:    Cylinder():Circle()    {        h=0;    }        Cylinder(double b):Circle(b)    {        h=b;    }    double getCylinderArea()    {        double area1,area2,area;        area1=getCircleLength()*h;        area2=getCircleArea()*2;        area=area1+area2;        return area;    }    double getCylinderVolume()    {        double volume;        volume=getCircleArea()*h;        return volume;    }    };void main(){    Circle cir(3);    Cylinder cyl(4);    cout<<"圆柱的面积:"<<cyl.getCylinderArea()<<endl;    cout<<"圆柱的体积:"<<cyl.getCylinderVolume()<<endl;}
[解决办法]
C/C++ code
Circle cir(3);    Cylinder cyl(4); 

热点排行
Bad Request.