求帮忙C++程序,大佬们求答案?

  1. 需要求解3个长方体,请编程实现一个基于对象的程序。数据成员有length(长)、width(宽)、height(高)。要求用成员函数实现以下功能: a) 由键盘输入3个长方体的长、宽、高 b) 计算3个长方体的体积。 c) 输出3个长方体的体积。 请编写程序,上机运行。

用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;
}