#include<iostream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define pi 3.14
using namespace std;
void _1();
void _2();
void _3();
void _4();
void _5();
void _6();
int main()
{
cout<<"*******************************************"<<endl;
cout<<"*
图形面积与体积计算小程序
*"<<endl;
cout<<"*
以下是各种图形序号:
*"<<endl;
cout<<"*
1.三
角
形
*"<<endl;
cout<<"*
2.圆
形
*"<<endl;
cout<<"*
3.平
行
四
边 形
*"<<endl;
cout<<"*
4.梯
形
*"<<endl;
cout<<"*
5.圆
环
*"<<endl;
cout<<"*******************************************"<<endl;
char yn;
int i;
cout<<"请输入您所需求的图形号码:"<<endl;
cin>>i;
switch(i)
{
case 1:
cout<<"您所求的图形为三角形,请确认是否正确"<<endl;
cout<<"正确请输入'y'"<<endl;
cin>>yn;
if(yn=='y')
_1();
else
main();
break;
case 2:
cout<<"您所求的图形为圆形,请确认是否正确"<<endl;
cin>>yn;
if(yn=='y')
_2();
else
main();
break;
case 3:
cout<<"您所求的图形为平行四边形,请确认是否正确"<<endl;
cin>>yn;
if(yn=='y')
_3();
else
main();
break;
case 4:
cout<<"您所求的图形为梯形,请确认是否正确"<<endl;
cin>>yn;
if(yn=='y')
_4();
else
main();
break;
case 5:
cout<<"您所求的图形为圆环,请确认是否正确"<<endl;
cin>>yn;
if(yn=='y')
_5();
else
main();
break;
//case 6:
//
case 2:
default:cout<<"输入非法"<<endl;
}
}
void xuanze()
{
int i;
cin>>i;
switch(i)
{
case 1:_1();
break;
case 2:_2();
break;
case 3:_3();
break;
case 4:_4();
break;
case 5:_5();
break;
case 6:_6();
break;
default:
cout<<"请重新启动"<<endl;
}
//return 0;
}
void _1()
{
float a,b,c,s,area;
char j;
cout<<"请输入三角形的三条边长:"<<endl;
cin>>a>>b>>c;
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
cout<<"三角形的半周长s="<<s<<endl;
cout<<"三角形的面积area="<<area<<endl;
cout<<"是否继续计算?"<<endl;
cin>>j;
if(j=='y')
main();
else
_6();
}
void _2()
{
float r,area;
char j;
cout<<"请输入圆形的半径:"<<endl;
cin>>r;
area=r*r*pi;
cout<<"圆形的面积area="<<area<<endl;
cout<<"是否继续计算?"<<endl;
cin>>j;
if(j=='y')
main();
else
_6();
}
void _3()
{
float a,h,area;
char j;
cout<<"请输入平行四边形的高和底边长:"<<endl;
cin>>a>>h;
area=a*h;
cout<<"平行四边形的面积area="<<area<<endl;
cout<<"是否继续计算?"<<endl;
cin>>j;
if(j=='y')
main();
else
_6();
}
void _4()
{
float a,b,h,area;
char j;
cout<<"请输入梯形的上底,下底和高:"<<endl;
cin>>a>>b>>h;
area=(a+b)*h/2;
cout<<"梯形的面积area="<<area<<endl;
cout<<"是否继续计算?"<<endl;
cin>>j;
if(j=='y')
main();
else
_6();
}
void _5()
{
float R,r,area;
char j;
cout<<"R为外圆半径,r为内圆半径"<<endl;
cin>>R>>r;
area=pi*(R*R-r*r);
cout<<"圆环面积area="<<area<<endl;
cout<<"是否继续计算?"<<endl;
cin>>j;
if(j=='y')
main();
else
_6();
}
void _6()
{
exit(1);
}