C++问题,为什么没有错误,运行结果却不对
//4-5类与对象#include<iostream.h>classBox{public:voidInit(doubleL,doubleW,doubleH);double...
//4-5 类与对象
#include <iostream.h>
class Box
{
public:
void Init(double L,double W,double H);
double Vol();
private:
double length,width,heighth;
};
void Box::Init(double L,double W,double H)
{
length=L;
width=W;
heighth=H;
}
double Box::Vol()
{
return length*width*heighth;
}
void main()
{
Box cube;
double a,b,c;
cout<<"请输如立方体的长宽高"<<endl;
cin>>a,b,c;
cube.Init(a,b,c);
cout<<"The vol of the cube is"<<cube.Vol()<<endl;
} 展开
#include <iostream.h>
class Box
{
public:
void Init(double L,double W,double H);
double Vol();
private:
double length,width,heighth;
};
void Box::Init(double L,double W,double H)
{
length=L;
width=W;
heighth=H;
}
double Box::Vol()
{
return length*width*heighth;
}
void main()
{
Box cube;
double a,b,c;
cout<<"请输如立方体的长宽高"<<endl;
cin>>a,b,c;
cube.Init(a,b,c);
cout<<"The vol of the cube is"<<cube.Vol()<<endl;
} 展开
2个回答
展开全部
把MAIN函数改成下面就对了:
void main()
{
Box cube;
double a=0,b=0,c=0; //注意这里最好初始化
cout<<"请输如立方体的长宽高"<<endl;
cin>>a>>b>>c; //注意这里的写法,原文是cin>>a,b,c;不对!
cube.Init(a,b,c);
cout<<"The vol of the cube is "<<cube.Vol()<<endl;
}
void main()
{
Box cube;
double a=0,b=0,c=0; //注意这里最好初始化
cout<<"请输如立方体的长宽高"<<endl;
cin>>a>>b>>c; //注意这里的写法,原文是cin>>a,b,c;不对!
cube.Init(a,b,c);
cout<<"The vol of the cube is "<<cube.Vol()<<endl;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream.h>
class Box
{
public:
void Init(double L,double W,double H);
double Vol();
private:
double length,width,heighth;
};
void Box::Init(double L,double W,double H)
{
length=L;
width=W;
heighth=H;
}
double Box::Vol()
{
return length*width*heighth;
}
void main()
{
Box cube;
double a,b,c;
cout<<"请输如立方体的长宽高"<<endl;
cin>>a>>b>>c;//问题在这,后面两个变量没输上值
cube.Init(a,b,c);
cout<<"The vol of the cube is"<<cube.Vol()<<endl;
}
class Box
{
public:
void Init(double L,double W,double H);
double Vol();
private:
double length,width,heighth;
};
void Box::Init(double L,double W,double H)
{
length=L;
width=W;
heighth=H;
}
double Box::Vol()
{
return length*width*heighth;
}
void main()
{
Box cube;
double a,b,c;
cout<<"请输如立方体的长宽高"<<endl;
cin>>a>>b>>c;//问题在这,后面两个变量没输上值
cube.Init(a,b,c);
cout<<"The vol of the cube is"<<cube.Vol()<<endl;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询