- #include<iostream>
- using namespace std;
- float form(float);
- float form(float, float);
- float form(float, float, float);
- int main()
- {
- float x, y ,z ;
- int a;
- cout<<"請問您要算哪一種圖形的面積? (1)圓形(2)三角形(3)梯形"<<endl;
- cin>>a;
- switch(a)
- {
- case 1:
- form(x);
- break;
- case 2:
- form(x,y);
- break;
- case 3:
- form(x,y,z);
- break;
- default:
- cout<<"來亂的?";
- break;
- }
- system("pause");
- return 0;
- }
- float form(float x)
- {
- cout<<"請輸入圓的半徑: ";
- cin>>x;
- cout<<"圓面積為: "<<x*x*3.14<<"平方公分"<<endl;
- }
- float form(float x, float y)
- {
- cout<<"請輸入三角形的底: ";
- cin>>x;
- cout<<"請輸入三角形的高: ";
- cin>>y;
- cout<<"三角形的面積為: "<<x*y/2<<"平方公分"<<endl;
- }
- float form(float x, float y ,float z)
- {
- cout<<"請輸入梯形的上底: ";
- cin>>x;
- cout<<"請輸入梯形的下底: ";
- cin>>y;
- cout<<"請輸入梯形的高: ";
- cin>>z;
- cout<<"梯形的面積為: "<<(x+y)*z/2<<"平方公分"<<endl;
- }
複製代碼 |