/*
* 程序的版权和版本声明部分
* Copyright (c)2013, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称:score.cpp
* 作 者: 赵 洋
* 完成日期: 2013 年 03 月 15 日
* 版本号: v1.0
* 输入描述:长方体的高
* 问题描述:计算长方体的体积和表面积
* 输出:计算长方体的体积和表面积
*/
#include<iostream>
using namespace std;
class Box
{public:
void get_value();
float area();
float volume();
void display();
float length;
float width;
float height;
};
void Box::get_value()
{
cout<<"请输入长方柱的长,高,宽:";
cin>>length;
cin>>width;
cin>>height;
}
float Box::area()
{
return ((length*width+length*height+width*height)*2);
}
float Box::volume()
{
return (length*width*height);
}
void Box::display()
{
cout<<"volume of box is"<<volume()<<endl;
cout<<"area of box is"<<area()<<endl;
}
int main()
{
Box box1,box2,box3;
box1.get_value();
box1.display();
box2.get_value();
box2.display();
box3.get_value();
box3.display();
return 0;
}
运行结果: