2013年11月1日 星期五
四種面積
#include<iostream>
#include<cstdlib>
using namespace std;
int Square()
{
int x,y;
cout<<"請輸入邊長"<<endl;
cin>>x;
y=x*x;
cout<<y<<endl;
system("pause");
}
int Rectangle()
{
int x,y,z;
cout<<"請輸入寬"<<endl;
cout<<"請輸入長"<<endl;
cin>>x>>y;
z=x*y;
cout<<z<<endl;
system("pause");
}
int Circle()
{
float x,y;
cout<<"請輸入半徑"<<endl;
cin>>x;
y=x*x*3.14;
cout<<y<<endl;
system("pause");
}
int Trapezoidal()
{
int x,y,z,a;
cout<<"請輸入上底"<<endl;
cout<<"請輸入下底"<<endl;
cout<<"請輸入高"<<endl;
cin>>x>>y>>z;
a=(x+y)*z/2;
cout<<a<<endl;
system("pause");
}
main()
{
int x;
cout<<"請選擇要計算面積的圖形"<<endl;
cout<<"1)正方形,2)長方形,3)圓形, 4)梯形"<<endl;
cin>>x;
switch(x)
{
case 1:
Square();
case 2:
Rectangle();
case 3:
Circle();
case 4:
Trapezoidal();
}
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言