Design an algorithm to read a value from the keyboard which represents the name of a shape. Allowed shapes are circle, square, and triangle, any other shape name should result in an error message being displayed. For each shape the area of the is to be calculated and displayed so the program should prompt the user for any additional information needed to calculate the area based on the shape. For triangles, only right-angled triangles are allowed. The calculated area along with the input from the user should be displayed.
Draw the flowchart and write the pseudocode for the algorithm.
Input: "Enter Shape" //prompt the user
if Shape = Circle then
Input: "Enter R" // radius of circle
S = "\\pi R^2" // circle area
if Shape = Square then
Input: "Enter a" // side of square
S = "a^2" // square area
if Shape = right-angled Triangle then
Input: "Enter a, b" // sides of triangle
S = ab/2 // triangle area
else
Error
Output:
Shape, S
Comments
Leave a comment