返回列表 發帖
  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.     float x,y,z;
  11.     int a;
  12.     cout<<"請問您要計算哪一種種形狀的面積 <1>三角形 <2>圓形 <3>長方形 <4>梯形 :"<<endl;
  13.     cin>>a;
  14.     if(a==1)
  15.     tri(x,y);
  16.     if(a==2)
  17.     cir(x);
  18.     if(a==3)
  19.     rec(x,y);
  20.     if(a==4)
  21.     tra(x,y,z);
  22.     system("pause");
  23. }
  24.     float tri(float x,float y)
  25.     {
  26.     cout<<"請輸入三角形的底(公分): ";
  27.     cin>>x;
  28.     cout<<"請輸入三角形的高(公分): ";
  29.     cin>>y;  
  30.     cout<<"此三角形的面積為"<<x*y/2<<"平方公分!"<<endl;
  31.               }
  32.     float cir(float x)
  33.     {
  34.     cout<<"請輸入圓的半徑(公分): ";
  35.     cin>>x;
  36.     cout<<"此圓形的面積為"<<x*x*3.14<<"平方公分!"<<endl;
  37.               }

  38.     float rec(float x,float y)
  39.     {
  40.     cout<<"請輸入三角形的長(公分): ";
  41.     cin>>x;
  42.     cout<<"請輸入三角形的寬(公分): ";
  43.     cin>>y;  
  44.     cout<<"此長方形的面積為"<<x*y<<"平方公分!"<<endl;
  45.               }
  46.     float tra(float x,float y,float z)
  47.     {
  48.     cout<<"請輸入梯形的上底(公分): ";
  49.     cin>>x;
  50.     cout<<"請輸入梯形的下底(公分): ";
  51.     cin>>y;
  52.     cout<<"請輸入三角形的高(公分): ";
  53.     cin>>z;  
  54.     cout<<"此梯形的面積為"<<(x+y)*z/2<<"平方公分!"<<endl;
  55.               }
複製代碼

TOP

返回列表