Published by Patrick Mutisya · 14 days ago
Implement and write pseudocode from a given design presented as either a program flowchart or structured English.
IF, THEN, ELSE, FOR, WHILE, END IF, etc.READ, WRITE (or OUTPUT).A flowchart uses symbols to represent actions, decisions, loops, and start/end points. The conversion process is:
IF … THEN … ELSE … END IF construct.WHILE or FOR structures.Design: Compute the sum \$S = 1 + 2 + \dots + n\$ where \$n\$ is entered by the user.
READ n
sum ← 0
i ← 1
WHILE i ≤ n DO
sum ← sum + i
i ← i + 1
END WHILE
WRITE "The sum is ", sum
Structured English is a semi‑formal description using English words mixed with programming keywords. To convert:
READ.WRITE (or OUTPUT).IF … THEN … ELSE … END IF.WHILE or FOR loops.Get three numbers A, B and C.
If A > B then
If A > C then
Display A as the maximum.
Else
Display C as the maximum.
End if
Else
If B > C then
Display B as the maximum.
Else
Display C as the maximum.
End if
End if
READ A, B, C
IF A > B THEN
IF A > C THEN
WRITE "Maximum is ", A
ELSE
WRITE "Maximum is ", C
END IF
ELSE
IF B > C THEN
WRITE "Maximum is ", B
ELSE
WRITE "Maximum is ", C
END IF
END IF
IF, WHILE, and FOR must have a matching END IF, END WHILE, or END FOR.i ≤ n vs i < n).| Design Element | Flowchart Symbol | Structured English Cue | Pseudocode Equivalent |
|---|---|---|---|
| Start / End | Oval | “Begin”, “End” | None (implicit) |
| Process / Assignment | Rectangle | “Set”, “Assign” | variable ← expression |
| Decision / Condition | Diamond | “If … then … else …” | IF condition THEN … ELSE … END IF |
| Loop (repeat) | Diamond with back‑arrow | “Repeat … until …” | WHILE condition DO … END WHILE |
| Input / Output | Parallelogram | “Get …”, “Display …” | READ … / WRITE … |
Get a list of marks.
Set total to 0.
For each mark in the list do
Add mark to total.
End for.
Calculate average = total / number of marks.
Display average.
READ x
IF x > 0 THEN
WRITE "Positive"
ELSE IF x = 0 THEN
WRITE "Zero"
END IF