如何为此创建伪代码? 开发应用程序来计算面积和几何形状的周长。首先要求用户输入代表形状为 的字母。我们用C表示圆,R表示矩形,S表示方形。 用户选择形状后,程序会相应地提示适当的形状尺寸 。例如,如果用户选择了一个正方形,该程序将要求一方。如果它是一个圆圈,程序将要求半径。如果 它是一个矩形,它会询问长度和宽度。 收到适当的尺寸后,程序将计算所需形状的面积和周长,并将其打印在屏幕上。再次,代码 将要求另一封信。如果用户输入'Q',则程序终止。 这个程序必须使用模块来实现。 该方案的运行将是这样的:用于计算几何形状的面积和周长的应用程序
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>
#include <conio>
using namespace std;
int main()
{
//clear the screen.
//clrscr();
//declare variable type int
char shape = 'N'; //none
int area, perimeter;
while(shape != 'Q')
{
cout<<"Please Enter Shape (C: Circle, S: Square, R: Rectangle Q:quit) >"<<endl;
//get shape choice
cin>>shape;
if(shape == 'C')
{
int radius;
//Circle, radius
}
else if(shape == 'S')
{
int side;
//Input the side
cout<<"Please enter the side of the square >"<<endl;
//Square, side
cin>>side;
//calculate perimeter and save it in 'peri'
perimeter=4*side;
//show the output 'perimeter'
cout<<"Perimeter of square is "<<perimeter<<endl;
}
else if(shape == 'R')
{
int width,length;
//Rectangle, width,length
}
}
return(0);
}
堆栈溢出不会为你做你的工作。请告诉我们你已经尝试过什么,失败等等。 –
这是我迄今为止所做的,但不知道如何使用模块。 – user2880024
好吧,“模块”是一个非常通用的术语,没有上下文,很难知道究竟是什么意思。但是我会假设你需要编写单独的类? –