/*
*Copyright(c)2016,烟台大学计算机与控制工程学院
*All right reserved.
*文件名称:my.cpp
*作 者:张瀚文
*完成日期:2016年4月6日
*版 本 号:v1.0
*
*问题描述:编写给予对象的程序,求3个长方柱(Bulk)的体积。数据成员包括长(length)、宽(width)、高(length)
体积(volume),要求设计成员函数实现下面功能 :
1.由键盘输入3个长方柱的长宽高;
2.计算长方柱的体积(volume)和表面积(area);
3.输出这三个长方柱的体积和面积
*输入描述:三个长方珠的长、宽、高
*程序输出:3个长方柱的体积和表面积
*/
#include<iostream>
using namespace std;
class Bulk
{
public:
void get_data(double x,double y,double z)
{
length=x;
width=y;
heigth=z;
}
void m_volume()
{
cout<<"the volume is:"<<length*width*heigth<<endl;
}
void m_s()
{
cout<<"the surface is:"<<2*(length*width+length*heigth+width*heigth)<<endl;
}
private:
double length,width,heigth;
};
int main()
{
Bulk b[3];
int i;
double x,y,z;
cout<<"please input 3 bulks of their 'length' 'width' and 'heigth' :"<<endl;
for(i=0;i<3;i++)
{ cin>>x>>y>>z;
b[i].get_data(x,y,z);
}
for(i=0;i<3;i++)
{
b[i].m_volume();
b[i].m_s();
}
return 0;
*Copyright(c)2016,烟台大学计算机与控制工程学院
*All right reserved.
*文件名称:my.cpp
*作 者:张瀚文
*完成日期:2016年4月6日
*版 本 号:v1.0
*
*问题描述:编写给予对象的程序,求3个长方柱(Bulk)的体积。数据成员包括长(length)、宽(width)、高(length)
体积(volume),要求设计成员函数实现下面功能 :
1.由键盘输入3个长方柱的长宽高;
2.计算长方柱的体积(volume)和表面积(area);
3.输出这三个长方柱的体积和面积
*输入描述:三个长方珠的长、宽、高
*程序输出:3个长方柱的体积和表面积
*/
#include<iostream>
using namespace std;
class Bulk
{
public:
void get_data(double x,double y,double z)
{
length=x;
width=y;
heigth=z;
}
void m_volume()
{
cout<<"the volume is:"<<length*width*heigth<<endl;
}
void m_s()
{
cout<<"the surface is:"<<2*(length*width+length*heigth+width*heigth)<<endl;
}
private:
double length,width,heigth;
};
int main()
{
Bulk b[3];
int i;
double x,y,z;
cout<<"please input 3 bulks of their 'length' 'width' and 'heigth' :"<<endl;
for(i=0;i<3;i++)
{ cin>>x>>y>>z;
b[i].get_data(x,y,z);
}
for(i=0;i<3;i++)
{
b[i].m_volume();
b[i].m_s();
}
return 0;
}