- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- #include<cstring>
- using namespace std;
- void tri()
- {
- int x,y;
- cout<<"輸出下底";
- cin>>x;
- cout<<"輸出高";
- cin>>y;
- cout<<"三角形的面積為"<<x*y/2<<"cm2" ;
- }
- void cir()
- {
- int r;
- cout<<"輸出半徑";
- cin>>r;
- cout<<"圓形的面積為"<<r*r*3.14<<"cm2" ;
- }
- void rec()
- {
- int x, y;
- cout<<"輸出寬";
- cin>>x;
- cout<<"輸出高";
- cin>>y;
- cout<<"矩形的面積為"<<x*y<<"cm2" ;
- }
- void tra()
- {
- int x,y,z;
- cout<<"輸出下底";
- cin>>x;
- cout<<"輸出上底";
- cin>>z;
-
- cout<<"輸出高";
- cin>>y;
- cout<<"梯形的面積為"<<(z+x)*y/2<<"cm2";
- }
- int main()
- {
- int sha;
- cout<<"要計算哪一種形狀的面積 (1)三角形 (2) 圓形 (3)矩形 (4)梯形" ;
- cin>>sha;
- switch(sha){
- case 1:
- tri();
- break;
- case 2:
- cir();
- break;
- case 3:
- rec();
- break;
- case 4:
- tra();
- break;
-
-
- }
-
- system("pause");
- return 0;
-
-
- }
複製代碼 |