#include <iostream>
using namespace std;
class Box
{
public:
void get_value();
void get_display();
private:
void get_volume();
void get_surface();
float width; float height;
float volume;
float surface;
};
void Box::get_value()
{
cout<<"请输入长,宽,高:";
cin>>lengh;
cin>>width;
cin>>height;
get_volume();
get_surface();
}
void Box::get_volume()
{
volume=lengh*width*height;
}
void Box::get_surface()
{
surface=2*(lengh*width+lengh*height+width*height);
}
void Box::get_display()
{
cout<<"The volume is: "<<volume<<endl;
cout<<"The surface is: "<<surface<<endl;
}
int main()
{
Box b1,b2,b3;
b1.get_value();
cout<<"For box1: "<<endl;
b1.get_display();
b2.get_value();
cout<<"For box2: "<<endl;
b2.get_display();
b3.get_value();
cout<<"For box3: "<<endl;
b3.get_display();
return 0;
}
长方柱类
最新推荐文章于 2018-10-17 21:51:12 发布