C++设计一个立方体类,出现问题,请帮忙
#include<iostream>usingnamespacestd;classBox{public:Box(doublea);doublegetArea(){retu...
#include <iostream>
using namespace std;
class Box
{
public:
Box(double a);
double getArea(){ return 6*a*a; }
double getVolume(){ return a*a*a; }
void disp()
{
getVolume();
getArea();
cout<<"体积"<<volume<<",表面积"<<area<<endl;
}
private:
double a;
double volume;
double area;
};
int main( int argc, char *argv[] )
{
double a;
Box myBox( a );
cout<<"请输入立方体边长:"<<endl;
cin>>side;
}
cout <<"立方体表面积:"<< getArea() <<endl;
cout <<"立方体体积:"<< getVolume() <<endl;
return 0; 展开
using namespace std;
class Box
{
public:
Box(double a);
double getArea(){ return 6*a*a; }
double getVolume(){ return a*a*a; }
void disp()
{
getVolume();
getArea();
cout<<"体积"<<volume<<",表面积"<<area<<endl;
}
private:
double a;
double volume;
double area;
};
int main( int argc, char *argv[] )
{
double a;
Box myBox( a );
cout<<"请输入立方体边长:"<<endl;
cin>>side;
}
cout <<"立方体表面积:"<< getArea() <<endl;
cout <<"立方体体积:"<< getVolume() <<endl;
return 0; 展开
2个回答
展开全部
#include <iostream>
using namespace std;
class Box
{
public:
double a;//a是边长放在public
Box(double A){a=A;}
double getArea(){ return 6*a*a; }
double getVolume(){ return a*a*a; }
void disp();
private:
double volume;
double area;
};
void Box::disp()
{
cout<<"Volume:"<<Box::getVolume()<<",Area:"<<Box::getArea()<<endl;
}
int main( int argc, char *argv[] )
{
Box myBox(0);
cin>>myBox.a;
myBox.disp();
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询