用class实现,,讲道理,你还是看书打好面向对象基础再说。。这种题真是基本中的基本。。。
#include <iostream>
using namespace std;
class Rectangle {
public:
Rectangle(double length, double width, double height) {
this->length = length;
this->width = width;
this->height = height;
}
double toVolume(void) {
this->volume = length * width * height;
return volume;
}
private:
double length;
double width;
double height;
double volume;
};
int main(void) {
double length, width, height;
cin >> length >> width >> height;
Rectangle* rectangle = new Rectangle(length, width, height);
double volume = rectangle->toVolume();
delete rectangle;
cout << volume << endl;
system("pause");
return 0;
}
#include
using namespace std;
class v{
public:
~v(){}
v(int a,int b,int c){
length=a;width=b;height=c;}
void showv(int a,int b,int c){
cout< }
private:
int length,width,height;
};
int main(){
int a,b,c,d,e,f,g,h,i;
cout cin>>a>>b>>c>>d>>e>>f>>g>>h>>i;
v z(a,b,c);
z.showv(a,b,c);
z.showv(d,e,f);
z.showv(g,h,i);
return 0;
}
我初学时大概会这么打
#include
int main()
{
float l,w,h; //定义长度l,宽度w,高度h为单精度浮点型
scanf("%f%f%f",&l,&w,&h); //输入三个值
printf("%lf",l*w*h); //输出体积
return 0;
}