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





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM