#include <iostream>
using namespace std;
class Bullk
{
public:
void data();
void display();
private:
double length;
double width;
double height;
};
void Bullk::data()
{
cout<<"请输入长宽高:";
cin>>length;
cin>>width;
cin>>height;
}
void Bullk::display()
{
cout<<"体积是: "<<length*width*height<<endl;
cout<<"面积是: "<<2*(length*width+length*height+width*height)<<endl;
}
int main()
{
Bullk b1,b2,b3;
b1.data();
cout<<"第一个长方体: "<<endl;
b1.display();
b2.data();
cout<<"第二个长方体: "<<endl;
b2.display();
b3.data();
cout<<"第三个长方体: "<<endl;
b3.display();
return 0;
}
运行结果:
心得体会:开始编的时候定义了好多函数,后来看完老师的精简了不少