作业帮 > 综合 > 作业

用c++编写图形的面积与体积的计算!

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/22 09:43:34
用c++编写图形的面积与体积的计算!
程序一开始运行.会弹出3个选项.【1】Areas of Shapes,【2】 Volumes of Solids,and 【3】Exit.当选择3的时候.程序结束退出.如果选【1】Areas of Shapes,这时程序会弹出子菜单square; rectangle; right-angled triangle; circle.当你选择其中一种图形时,又会弹出选项例如:选长方型,后会立刻出现问句.请输入长和宽!当输入完了长和宽后.程序可以准确的算出长方型的面积!其他图形以此类推.但是在子菜单要有一个返回上级菜单的选项,任何时候都可以返回上级菜单.,【2】 Volumes of Solids的子菜单是cube; sphere 要求和面积菜单一样无论什么时候都可以返回上级菜单且可以准确的算出正方体和球体的体积,程序要求不断循环运行直到使用者选择了"EXIT" 选项!
#include
#include
using namespace std;
//------------------------------------------------------------------------------
float AreaSquare();//正方形
float AreaRectangle();//长方形
float AreaRtriangle();//直角三角
float AreaCircle();//圆
float VolumeCube();//立方体
float VolumeSphere();//球体
void FlatArea(const char&,bool&);//平面图形面积
void ThreeDArea(const char&,bool&);//立体图形体积
const double PI=3.1415;
//------------------------------------------------------------------------------
int main()
{
char ch='3',ch2='5',ch3='3';
bool flag=1;//退出标记,为0退出或返回上级
coutW;
return L*W/2;
}
float AreaCircle()
{
unsigned R=0;
coutR;
return PI*R*R;
}
float VolumeCube()
{
unsigned L=0;
coutL;
return L*L*L;
}
float VolumeSphere()
{
unsigned R=0;
coutR;
return 4*PI*R*R*R/3;
}
void FlatArea(const char& ch,bool& flag)//平面图形面积
{
switch(ch)
{
case '1':cout