注册 登录
编程论坛 新人交流区

谁指点一下下面的程序,,,,好郁闷的...谢谢..

sinpa12 发布于 2007-11-16 02:09, 667 次点击

#include<iostream.h>
class cylinder{
public:
cylinder ( double x,double y);
double get_volume ( double x,double y);
void vol ( );
private:
double radius,height;
double volume;
};

double cylinder::cylinder ( double x,double y){
radius=x; height=y;
}
double cylinder::get_volume ( double x,double y)
{
return volume=3.14*x*x*y;
}
void cylinder::vol ( )
{
cout<<"volume="<<volume<<endl;
}
void main(){
cylinder ob (2.0,3.0);
ob.vol();
}

请把你们的高见写下来...

9 回复
#2
phb7112007-11-16 13:40
是错了还是咋地?
怎么没计算体积啊?
void main(){
cylinder ob (2.0,3.0);
ob.get_volume();
ob.vol();
}

#3
ou1082007-11-16 15:29

先要说明错误

#4
aresoft2007-11-16 16:09
回复:(sinpa12)谁指点一下下面的程序,,,,好郁闷的....
再看看吧
#5
t6543212007-11-16 16:21
请把你们的高见写下来...
我也郁闷了,你都没说啥回事呢?
#6
luntan20072007-11-16 17:01
没看懂
#7
xuweiy2007-11-16 17:03
回复:(sinpa12)谁指点一下下面的程序,,,,好郁闷的....
看不懂
#8
zhb_ice2007-11-16 18:18
double cylinder::cylinder ( double x,double y){
radius=x; height=y;
}


构造函数不能有返回值
cylinder::cylinder ( double x,double y){
radius=x;
height=y;
volume=3.14*x*x*y;
}
#9
antonine2007-11-16 20:28

#include<iostream>
using namespace std;

class cylinder
{
public:
cylinder ( double x,double y);
double get_volume ();
void vol ( );
private:
double radius,height;
double volume;
};

cylinder::cylinder ( double x,double y)
{
radius=x; height=y;
}
double cylinder::get_volume ()
{
return volume=3.14*radius*radius*height;
}
void cylinder::vol ( )
{
cout<<"volume="<<volume<<endl;
}
int main()
{
cylinder ob (2.0,3.0);
ob.get_volume();
ob.vol();

return 0;
}

#10
antonine2007-11-16 20:32
1. 构造函数没有返回值
2. 主函数中还没有运行get_volume()没有对体积进行计算
3. 你的get_volume()函数本身怎么还带参数啊
1