的面积和周长,我想制定如下方案,并正在寻求建议:计算几何形状
开发一个应用,计算面积和周长 几何形状。首先要求用户输入代表形状为 的字母。我们用C代表圆,R代表矩形,S代表方形。
用户选择形状后,程序会相应地提示相应的形状的适当的 尺寸。例如,如果用户选择了一个正方形,该程序将要求一方。如果它是一个圆圈,程序将要求半径。如果 它是一个矩形,它会询问长度和宽度。 收到适当的尺寸后,程序将计算所需形状的面积和周长,并将其打印在屏幕上。再次,代码 将要求另一封信。如果用户输入'Q',则程序终止。 这个程序必须使用模块来实现。
One run of the program will look like this:
Please Enter Shape (C: Circle, S: Square, R: Rectangle Q:quit) >S
Please enter the side of the square > 8
The area is 64 and the perimeter is 32
Please Enter Shape (C: Circle, S: Square, R: Rectangle Q:quit) >R
Please enter the width of the rectangle > 5
Please enter the length of the rectangle > 7
The area is 35 and the perimeter is 24
Please Enter Shape (C: Circle, S: Square, R: Rectangle Q:quit) >Q
#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type int
int a,peri;
//Input the side and save it in 'a'
cout<<"Enter the side of square"<<endl;
cin>>a;
//calculate perimeter and save it in 'peri'
peri=4*a;
//show the output 'peri'
cout<<"Perimeter of square is "<<peri;
//get character
getch();
}
这在C或C++中看起来如何?
你熟悉的'while'和'之开关语句?这些对你做这个家庭作业是有用的。 – Floris
switch语句不太好,这只是练习题。 – user2880024
嗨!请看看我如何编辑你的文章,使其更加平易近人。关于这个问题本身,这个广场看起来是一个好的开始。尝试实施询问用户现在想要的形状,如果有任何问题提出挑战,请告诉我们。 –