/*
*copyright(c)2016,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:text.cpp
*作者:闫舒
*完成日期:2016年5月26日
*版本号:Code::Blocks 12.11
*
*问题描述:编写基于对象的程序,求三个长方体的体积;
*输入描述:输入三个长方体的长,宽,高;
*程序输出:输出三个长方体的体积和表面积。
*/
#include <iostream>
using namespace std;
class Bulk
{
public:
void getshuju();
void display();//shuchu
void getareas();
void getvolume();
private:
int lenght;
int width;
int height;
int areas;
int volume;
};
void Bulk::getshuju()
{
cout<<"please input lenght,width,height:"<<endl;
cin>>lenght>>width>>height;
getareas();
getvolume();
}
void Bulk::getareas()
{
areas=2*(lenght*width+lenght*height+width*height);
}
void Bulk::getvolume()
{
volume=lenght*width*height;
}
void Bulk::display()
{
cout<<"the areas is: "<<areas<<endl;
cout<<"the volume is: "<<volume<<endl;
}
int main()
{
Bulk a,b,c;
a.getshuju();
cout<<"a:"<<endl;
a.display();
b.getshuju();
cout<<"b:"<<endl;
b.display();
c.getshuju();
cout<<"c:"<<endl;
c.display();
return 0;
}
运行结果:
心得体会:
程序运行过程中出现了许多问题,包括许多个时尚的小错误,例如void 函数名后面没有加小括号等,在以后的学习中应该多练习。