/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved
.* 文件名称:
* 作 者: 张培培
* 完成日期: 2011年 03月 09日
* 版 本 号:
* 对任务及求解方法的描述部分
* 输入描述:输入长方柱的长,宽,高
* 问题描述:利用成员函数输出长方柱的体积和表面积
* 程序输出: 输出长方体的体积和面积
* 程序头部的注释结束*
#include <iostream>
using namespace std;
class Box
{
public:
void get_value();
void display();
private:
float length;
float width;
float heigth;
};
void Box::get_value()
{
cout<<"请输入长方柱的长,宽,高: "<<endl;
cin>>length;
cin>>width;
cin>>heigth;
}
void Box::display()
{
cout<<"The value is: "<<length*width*heigth<<endl;
cout<<"The areas is: "<<2*(length+width+heigth)<<endl;
}
int main()
{
Box box1,box2,box3;
box1.get_value();
cout<<"The box1 is: ";
box1.display();
box2.get_value();
cout<<"The box2 is: ";
box2.display();
box3.get_value();
cout<<"The box3 is: ";
box3.display();
return 0;
}