盒子的运算(表面积,体积)
第一个小程序代码#include <iostream.h>
class box
{
double len,wid,hei;
public:
box (double l=0,double w=0,double h=0)
{cout <<"长方体:";}
void setdate(double a,double b,double c)
{len=a;wid=b;hei=c;}
void sqare ()
{cout<<"面积是 :
"<<2*(len*wid+len*hei+hei*wid)<<endl;}
void volume()
{cout <<"体积是:"<<len*wid*hei<<endl<< endl;}
};
void main ()
{
box d2;
double len,wid,hei;
char s='y',x;
while(s=='y')
{cout<<"是否继续计算: (y/n)
";
cin>> s;
if (s=='y')
{
cout<<"请输入长、宽、高: ";
cin >>len>>wid>>hei;
d2.setdate(len,wid,hei);
cout <<"计算体积请按v;面积s:";
cin >>x;
switch (x)
{case 'v':
d2.volume ();break;
case 's':
d2.sqare();
default :
cout<<"输入有误,请重新输入: "<<endl;
}
}
}
}