编写一个基于对象的程序,求长方形的体积

长方柱数据成员包括length、width、height,要求用成员函数实现以下功能:
1,输入3个长方体的长宽高;
2,计算长方柱的体积;
3,输出3个长方体的体积。
Input
1 2 3
3 3 3
10 10 10

Output
6
27
1000

#include
using namespace std;

class rectangle{
    public:
        //初始化 
        rectangle(){
            length = width = height = 0;
        }
        //输入数据 
        void input(){
            cin >> length >> width >> height;
        }
        //输出结果 
        void output(){
            volume = length * width * height;
            cout << volume << endl;
        }

    private:
        double length;
        double width;
        double height;
        double volume;
};

int main()
{
    rectangle a[3];
    for(int i = 0; i < 3; i++){
        a[i].input();
        a[i].output();
    }

    return 0;
}

你可能感兴趣的:(面向对象编程,对象)