/*
【项目4 - 长方柱类】编写基于对象的程序,求3个长方柱(Bulk)的体积。
数据成员包括长(length)、宽(width)、高(heigth)、体积,要求设计成员函数实现下面的功能:
*(1)由键盘输入3个长方柱的长、宽、高;
*(2)计算长方柱的体积(volume)和表面积(areas);
*(3)输出这3个长方柱的体积和表面积;
*/
#include<iostream>
using namespace std;
class Bulk
{
public:
void ScIn( );
double Comput_v( );
double Comput_a( );
void Print( );
void Get_length(double);
private:
double length;
double width;
double heigth;
double volume;
double areas;
};
void Bulk::ScIn( )
{
cout<<"input the length,width,heigth: "<<endl;
cin>>length>>width>>heigth;
}
double Bulk::Comput_v( )
{
volume=length*width*heigth;
return volume;
}
double Bulk::Comput_a( )
{
areas=2*(heigth*width+heigth*length+length*width);
return areas;
}
void Bulk::Print( )
{
cout<<"the volume of this bulk is: "<<volume<<endl
<<"the areas of this bulk is: "<<areas<<endl;
}
void Bulk::Get_length(double x)
{
length=x;
}
int main( )
{
Bulk b1,b2,b3;
b1.ScIn( );
b1.Comput_v( );
b1.Comput_a( );
b1.Print( );
b2.ScIn( );
b2.Comput_v( );
b2.Comput_a( );
b2.Print( );
b3.ScIn( );
b3.Comput_v( );
b3.Comput_a( );
b3.Print( );
b3.Get_length(34.5);
b3.Comput_v( );
b3.Comput_a( );
b3.Print( );
return 0;
}
【项目4 - 长方柱类】编写基于对象的程序,求3个长方柱(Bulk)的体积。
数据成员包括长(length)、宽(width)、高(heigth)、体积,要求设计成员函数实现下面的功能:
*(1)由键盘输入3个长方柱的长、宽、高;
*(2)计算长方柱的体积(volume)和表面积(areas);
*(3)输出这3个长方柱的体积和表面积;
*/
#include<iostream>
using namespace std;
class Bulk
{
public:
void ScIn( );
double Comput_v( );
double Comput_a( );
void Print( );
void Get_length(double);
private:
double length;
double width;
double heigth;
double volume;
double areas;
};
void Bulk::ScIn( )
{
cout<<"input the length,width,heigth: "<<endl;
cin>>length>>width>>heigth;
}
double Bulk::Comput_v( )
{
volume=length*width*heigth;
return volume;
}
double Bulk::Comput_a( )
{
areas=2*(heigth*width+heigth*length+length*width);
return areas;
}
void Bulk::Print( )
{
cout<<"the volume of this bulk is: "<<volume<<endl
<<"the areas of this bulk is: "<<areas<<endl;
}
void Bulk::Get_length(double x)
{
length=x;
}
int main( )
{
Bulk b1,b2,b3;
b1.ScIn( );
b1.Comput_v( );
b1.Comput_a( );
b1.Print( );
b2.ScIn( );
b2.Comput_v( );
b2.Comput_a( );
b2.Print( );
b3.ScIn( );
b3.Comput_v( );
b3.Comput_a( );
b3.Print( );
b3.Get_length(34.5);
b3.Comput_v( );
b3.Comput_a( );
b3.Print( );
return 0;
}