Activity 20B Pseudocode
Activity 20B Pseudocode
-----------------------------------------------------------------------------------
-------------------------------------------------------------------------
DECLARE List : ARRAY OF STRING = ["Square", "Rectangle", "Triangle",
"Parallelogram", "Circle"]
DECLARE Shape : STRING
DECLARE side, length, width, base, height, radius, Area : REAL
ELSE
OUTPUT "Invalid shape entered"
ENDIF
-----------------------------------------------------------------------------------
-------------------------------------------------------------------------
Pseudocode using the procedural programming paradigm
-----------------------------------------------------------------------------------
-------------------------------------------------------------------------
GLOBAL shapes
GLOBAL area
DECLARE shapes : ARRAY OF STRING = ["Square", "Rectangle", "Triangle",
"Parallelogram", "Circle"]
DECLARE area : real
area = 0
PROCEDURE display_shapes()
OUTPUT "List of shapes: ", shapes
ENDPROCEDURE
PROCEDURE calculate_square()
DECLARE side : REAL
OUTPUT "Enter the length of the side of the square: "
INPUT side
area ← side * side
OUTPUT "The area of the square is: ", area
ENDPROCEDURE
PROCEDURE calculate_rectangle()
DECLARE length, width : REAL
OUTPUT "Enter the length of the rectangle: "
INPUT length
OUTPUT "Enter the width of the rectangle: "
INPUT width
area ← length * width
OUTPUT "The area of the rectangle is: ", area
ENDPROCEDURE
PROCEDURE calculate_triangle()
DECLARE base, height : REAL
OUTPUT "Enter the length of the base of the triangle: "
INPUT base
OUTPUT "Enter the height of the triangle: "
INPUT height
area ← 0.5 * base * height
OUTPUT "The area of the triangle is: ", area
ENDPROCEDURE
PROCEDURE calculate_parallelogram()
DECLARE base, height : REAL
OUTPUT "Enter the length of the base of the parallelogram: "
INPUT base
OUTPUT "Enter the height of the parallelogram: "
INPUT height
area ← base * height
OUTPUT "The area of the parallelogram is: ", area
ENDPROCEDURE
PROCEDURE calculate_circle()
DECLARE radius : REAL
OUTPUT "Enter the radius of the circle: "
INPUT radius
area ← 3.142 * radius * radius
OUTPUT "The area of the circle is: ", area
ENDPROCEDURE
PROCEDURE main()
DECLARE shape : STRING
CALL display_shapes()
OUTPUT "Enter the shape you want to calculate the area for from the list above:
"
INPUT shape
IF shape = "Square" THEN
CALL calculate_square()
ELSE IF shape = "Rectangle" THEN
CALL calculate_rectangle()
ELSE IF shape = "Triangle" THEN
CALL calculate_triangle()
ELSE IF shape = "Parallelogram" THEN
CALL calculate_parallelogram()
ELSE IF shape = "Circle" THEN
CALL calculate_circle()
ELSE
OUTPUT "Invalid shape entered"
ENDIF
ENDPROCEDURE
CALL main()