/*
* 程序的版权和版本声明部分
* Copyright (c)2012, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称: object.cpp
* 作者:赵兰
* 完成日期: 2013 年3 月22日
* 版本号: v1.0
* 输入描述:无
* 问题描述:编写基于对象的程序,求3个长方柱(Bulk)的体积。数据成员包括长(length)、宽(width)、高(heigth)、体积,要求用成员函数实现下面的功能:
(1)由键盘输入3个长方柱的长、宽、高;
(2)计算长方柱的体积(volume)和表面积(areas);
(3)输出这3个长方柱的体积和表面积;
* 程序输出:如下
*/
#include <iostream>
using namespace std;
class Bulk
{
public: //成员函数
void get_value();
void display();
private: //数据成员
float length;
float width;
float heigh;
};
void Bulk::get_value() //在类外定义get_value函数
{
cout<<"请输入长,宽,高:"<<endl;
cin>>length;
cin>> width;
cin>>heigh;
}
void Bulk::display() //在类外定义display函数
{
cout<<"长方体的体积为:"<<length*width*heigh<<endl;
cout<<"长方体的表面积为:"<<2*(length*width+length*heigh+width*heigh)<<endl;
}
int main()
{
Bulk a1,a2,a3;
a1.get_value();
cout<<"第一个长方体的数据为:"<<endl;
a1.display();
a2.get_value();
cout<<"第二个长方体的数据为:"<<endl;
a2.display();
a3.get_value();
cout<<"第三个长方体的数据为:"<<endl;
a3.display();
return 0;
}