源代码:
#include<iostream>
using namespace std;
class Cub
{
public:
void get_side();
void display();
private:
float length;
float width;
float height;
};
void Cub::get_side()
{
cin>> length;
cin>> width;
cin>> height;
}
void Cub::display()
{
cout<< "运算数据为:" <<endl;
cout<< "volume = " << length * width * height << endl;
cout<< "areas = " << 4 * (length * width) + 2 * (width * length) << endl;
}
int main()
{
Cub c1, c2, c3;
cout<< "请输入第一个长方体的数据:";
c1.get_side();
c1.display();
cout<< "请输入第二个长方体的数据:";
c2.get_side();
c2.display();
cout<< "请输入第三个长方体的数据:";
c3.get_side();
c3.display();
return 0;
}
截图:
收获:自己定义了类,体验了这个过程···而不是再照着代码敲,收获不小··
感想:以后一定要积极发博文!!!