0% found this document useful (0 votes)
13 views3 pages

Activity 20B Pseudocode

The document presents two pseudocode implementations for calculating the area of various shapes: one using the imperative programming paradigm and the other using the procedural programming paradigm. Both versions include a list of shapes and prompt the user for dimensions based on the selected shape, calculating and displaying the area accordingly. The procedural version organizes the calculations into separate procedures for each shape, enhancing modularity.

Uploaded by

Ghetto Shoota
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Activity 20B Pseudocode

The document presents two pseudocode implementations for calculating the area of various shapes: one using the imperative programming paradigm and the other using the procedural programming paradigm. Both versions include a list of shapes and prompt the user for dimensions based on the selected shape, calculating and displaying the area accordingly. The procedural version organizes the calculations into separate procedures for each shape, enhancing modularity.

Uploaded by

Ghetto Shoota
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Pseudocode using the basic imperative programming paradigm

-----------------------------------------------------------------------------------
-------------------------------------------------------------------------
DECLARE List : ARRAY OF STRING = ["Square", "Rectangle", "Triangle",
"Parallelogram", "Circle"]
DECLARE Shape : STRING
DECLARE side, length, width, base, height, radius, Area : REAL

OUTPUT "List of shapes: ", List


INPUT Shape

IF Shape = "Square" THEN


OUTPUT "Enter the length of the side of the square: "
INPUT side
Area ← side * side
OUTPUT "The area of the square is: ", Area

ELSE IF Shape = "Rectangle" THEN


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

ELSE IF Shape = "Triangle" THEN


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

ELSE IF Shape = "Parallelogram" THEN


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

ELSE IF Shape = "Circle" THEN


OUTPUT "Enter the radius of the circle: "
INPUT radius
Area ← 3.142 * radius * radius
OUTPUT "The area of the circle is: ", Area

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()

You might also like