/*
*Copyright (c) 2014, 烟台大学计算机学院
*All rights reserved.
*文件名称:text.cpp
*作者:陈栋梁
*完成日期:2015年 3 月 17 日
*版本号:v1.0
*
*/
#include <iostream>
using namespace std;
class Bulk
{
public:
void get_value();
void display();
private:
void get_volume();
void get_area();
float lengh;
float width;
float height;
float volume;
float area;
};
void Bulk::get_value()
{
cout<<"输入长宽高:";
cin>>lengh;
cin>>width;
cin>>height;
get_volume();
get_area();
}
void Bulk::get_volume()
{
volume=lengh*width*height;
}
void Bulk::get_area()
{
area=2*(lengh*width+lengh*height+width*height);
}
void Bulk::display()
{
cout<<"体积为:"<<volume<<endl;
cout<<"表面积为 "<<area<<endl;
}
int main()
{
Bulk b1,b2,b3;
b1.get_value();
cout<<"For bulk1: "<<endl;
b1.display();
b2.get_value();
cout<<"For bulk2: "<<endl;
b2.display();
b3.get_value();
cout<<"For bulk3: "<<endl;
b3.display();
return 0;
}
运行结果: