返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. float tri(float,float);
  5. float cir(float);
  6. float rec(float,float);
  7. float tra(float,float,float);
  8. int main()
  9. {
  10.     int fuck;
  11.     float x,y,z;
  12.     cout<<"請問您要計算哪一種種形狀的面積 <1>三角形 <2>圓形 <3>長方形 <4>梯形 :"<<endl;
  13.     cin>>fuck;
  14.     if(fuck==1)
  15.        tri(x,y);
  16.     else if(fuck==2)   
  17.        cir(x);
  18.     else if(fuck==3)   
  19.        rec(x,y);
  20.     else if(fuck==4)   
  21.        tra(x,y,z);
  22.     else
  23.     {
  24.        cout<<"輸入錯誤!"<<endl;
  25.     }                  
  26.     system("pause");  
  27.     return 0;   
  28. }
  29. float tri(float a, float b)     
  30. {
  31.     cout<<"請輸入三角形的底(公分): ";
  32.     cin>>a;
  33.     cout<<"請輸入三角形的高(公分): ";
  34.     cin>>b;  
  35.     cout<<"此三角形的面積為"<<a*b/2<<"平方公分!"<<endl;  
  36. }
  37. float cir(float a)     
  38. {
  39.     cout<<"請輸入圓形的半徑(公分): ";
  40.     cin>>a;
  41.     cout<<"此圓形的面積為"<<a*a*3.14<<"平方公分!"<<endl;  
  42. }
  43. float rec(float a, float b)     
  44. {
  45.     cout<<"請輸入長方形的長(公分): ";
  46.     cin>>a;
  47.     cout<<"請輸入長方形的寬(公分): ";
  48.     cin>>b;  
  49.     cout<<"此長方形的面積為"<<a*b<<"平方公分!"<<endl;  
  50. }
  51. float tra(float a, float b, float c)     
  52. {
  53.     cout<<"請輸入梯形的上底(公分): ";
  54.     cin>>a;
  55.     cout<<"請輸入梯形的下底(公分): ";
  56.     cin>>b;
  57.     cout<<"請輸入梯形的高(公分): ";
  58.     cin>>c;  
  59.     cout<<"此梯形的面積為"<<(a+b)*c/2<<"平方公分!"<<endl;  
  60. }
複製代碼

TOP

返回列表