定义盒子的Box类,具有以下要求:
可设置盒子的形状;
可计算盒子的体积;
可计算盒子的表面积;
#include<iostream>
using namespace std;
class Box{
private:
float len,wid,hei;
public:
Box(float l,float w,float h){len=l;wid=w;hei=h;}
friend float getArea(Box b);
friend float getVolum(Box b);
};
float getArea(Box b){
float r=2*(b.len*b.wid+b.len*b.hei+b.wid*b.hei);
return r;
}
float getVolum(Box b){
float r=b.len*b.wid*b.hei;
return r;
}
void main(){
Box box(5,6,10);
cout<<"area:"<<getArea(box)<<endl;
cout<<"volum:"<<getVolum(box)<<endl;
}