求立方体的体积、表面积(c++)
//求立方体的体积、表面积(c++)
#include <iostream>
#include <stdlib.h>
#define COST 20
using namespace std;
class tiji
{
private:
double length,width,height;
public:
tiji(){};
tiji(double l, double w, double h) //构造函数的形参,给私有变量赋值
{
length =l;
width =w;
height =h;
}
double changft_tiji()
{
//double v;
double v=length*width*height;
return v;
}
double biao_area()
{
double s;
s=2*(length*height+length*width+width*height);
return s;
}
double repaie()
{
double ss ;
ss = 2*(length*height+length*width+width*height)-length*width;
return ss;
}
void input(); //声明
};
void tiji::input()
{
cin>>length>>width>>height;
}
void menu()
{
cout<<“*********************************”<<endl;
cout<<” 1.求立方体的体积”<<endl;
cout<<” 2.求立方体的表面积”<<endl;
cout<<” 3.求立方体的装修造价”<<endl;
cout<<” 0.退出!”<<endl;
cout<<“*********************************”<<endl<<endl;
}
void _exit()
{
cout<<“*********************************”<<endl;
cout<<” 欢迎使用本程序”<<endl;
cout<<” 退出成功”<<endl;
cout<<” 谢谢!”<<endl;
cout<<“*********************************”<<endl<<endl;
}
int main ()
{
tiji B;
int c;
menu();
while(1)
{
cout<<“请输入长、宽、高的值:”;
B.input();
cout<<“请选择:”;
cin>>c;
switch(c)
{
case 1:
cout<<” 1.求立方体的体积”<<B.changft_tiji()<<endl;
break;
case 2:
cout<<” 2.求立方体的表面积”<<B.biao_area()<<endl;
break;
case 3:
cout<<” 3.求立方体的装修造价”<<B.repaie()*COST<<endl;
break;
case 0:
system(“cls”);//清屏
_exit();
exit(1);
break;
default:
cout<<“没有此项功能!”;
}
}
//B.changft_tiji(3,4,5)
//cout<<“长方体的体积为:”<<B.changft_tiji()<<endl;
//cout<<“长方体的表面积为:”<<B.biao_area()<<endl;
//cout<<“长方体的装修造价为:”<<B.repaie()*COST<<endl;
return 1;//1 代表真
}