- #include<iostream>
- #include<cstdlib>
- using namespace std;
- float tri(float,float);
- float cir(float);
- float rec(float,float);
- float tra(float,float,float);
- int main()
- {
- float x,y,z;
- int a;
- cout<<"請問您要計算哪一種種形狀的面積 <1>三角形 <2>圓形 <3>長方形 <4>梯形 :"<<endl;
- cin>>a;
- if(a==1)
- tri(x,y);
- if(a==2)
- cir(x);
- if(a==3)
- rec(x,y);
- if(a==4)
- tra(x,y,z);
- system("pause");
- }
- float tri(float x,float y)
- {
- cout<<"請輸入三角形的底(公分): ";
- cin>>x;
- cout<<"請輸入三角形的高(公分): ";
- cin>>y;
- cout<<"此三角形的面積為"<<x*y/2<<"平方公分!"<<endl;
- }
- float cir(float x)
- {
- cout<<"請輸入圓的半徑(公分): ";
- cin>>x;
- cout<<"此圓形的面積為"<<x*x*3.14<<"平方公分!"<<endl;
- }
- float rec(float x,float y)
- {
- cout<<"請輸入三角形的長(公分): ";
- cin>>x;
- cout<<"請輸入三角形的寬(公分): ";
- cin>>y;
- cout<<"此長方形的面積為"<<x*y<<"平方公分!"<<endl;
- }
- float tra(float x,float y,float z)
- {
- cout<<"請輸入梯形的上底(公分): ";
- cin>>x;
- cout<<"請輸入梯形的下底(公分): ";
- cin>>y;
- cout<<"請輸入三角形的高(公分): ";
- cin>>z;
- cout<<"此梯形的面積為"<<(x+y)*z/2<<"平方公分!"<<endl;
- }
複製代碼 |