长方柱类
来源:互联网 发布:中岛美雪恩知 编辑:程序博客网 时间:2024/04/27 20:45
#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; }