求立方体的体积、表面积(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 代表真
}

原文链接: https://www.cnblogs.com/duanqibo/p/11110323.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    求立方体的体积、表面积(c++)

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/298022

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月15日 下午7:12
下一篇 2023年2月15日 下午7:12

相关推荐