/*
* 程序的版权和版本声明部分
* Copyright (c)2013, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称:score.cpp
* 作 者:张浩
* 完成日期:2013年3月19日
* 版本号: v1.0
* 输入描述: 输入长方体的长、宽、高
* 问题描述:略
* 输出: 计算长方体的面积与体积
*/
#include<iostream>
using namespace std;
class Bluk
{
public:
void get_value();
void display();
private:
void get_volume();//求体积
void get_area();//求面积
float lengh;//长
float height;//高
float width;//宽
float volume;//体积
float area;//面积
};
void Bluk::get_value()
{
cout<<"请输入长方体的长、宽、高:"<<endl;
cin>>lengh;
cin>>width;
cin>>height;
get_volume();
get_area();
}
void Bluk::get_volume()
{
volume=lengh*height*width;
}
void Bluk::get_area()
{
area=2*(lengh*height+lengh*width+width*height);
}
void Bluk::display()
{
cout<<"这个长方体的体积为:"<<volume<<endl;
cout<<"这个长方体的面积为:"<<area<<endl;
}
int main()
{
Bluk b1,b2,b3;
cout<<"第一个长方体:"<<endl;
b1.get_value();
b1.display();
cout<<"第二个长方体:"<<endl;
b2.get_value();
b2.display();
cout<<"第三个长方体:"<<endl;
b3.get_value();
b3.display();
return 0;
}
运行结果:
心得体会:运行的结果还是和我想的差了点,感觉太麻烦了,如果那个亲有好的想法记得告诉我哦!