- #include<iostream>
- #include<cstdlib>
- using namespace std;
- double area(double num1)
- {
- return num1*num1;
- }
- double area(double num2,double num3)
- {
- return (num2*num3)/2;
- }
- double area(double num4,double num5,double num6)
- {
- return (num4+num5)*num6/2;}
- int main()
- {
- int num=0,num1=0,num2=0,num3=0,num4=0,num5=0,num6=0;
- cout<<"請輸入形狀(1)正方形(2)三角形(3)梯形"<<endl;
- cin>>num;
- if(num==1)
- {
- cout<<"請輸入正方形的lenth"<<endl;
- cin>>num1;
- cout<<area(num1)<<endl;
- }
- else if(num==2)
- {
- cout<<"請輸入三角形的Bottom height" <<endl;
- cout<<"Bottom :";
- cin>>num2;
- cout<<endl;
- cout<<"height:";
- cin>>num3;
- cout<<endl;
- cout<<area(num2,num3)<<endl;
- }
- else if(num==3)
- {
- cout<<"請輸入梯形的上底,下底,高"<<endl;
- cout<<"上底:";
- cin>>num4;
- cout<<endl;
- cout<<"下底:";
- cin>>num5;
- cout<<endl;
- cout<<"高:";
- cin>>num6;
- cout<<endl;
- cout<<area(num4,num5,num6)<<endl;
- }
- system("pause");
- return 0;
- }
複製代碼 |