Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A student wrote this pseudocode to find the area of a floor in square metres and the number of paint tins needed. One tin covers square metres.
DECLARE Length : REAL
DECLARE Width : REAL
DECLARE Area : INTEGER
CONSTANT TinCover ← Length * 2
INPUT Length
INPUT Width
Area = Length * Width
OUTPUT Area is, AreaFind four errors and write the corrected pseudocode.
A variable is declared with its type: DECLARE Name : INTEGER. The five types are INTEGER, REAL, CHAR, STRING and BOOLEAN. A constant takes a literal: CONSTANT Name ← 5. Assignment is ←; = compares. DIV(A, B) is the whole part of , and MOD(A, B) is the remainder.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
The errors.
CONSTANT TinCover ← Length * 2 sets a constant from an expression. A constant takes only a literal, here 12.0.DECLARE Area : INTEGER is the wrong type. Length times width of two REAL values is REAL.Area = Length * Width uses =, which compares. Assignment is ←.OUTPUT Area is, Area has text without quotes. Text is a string literal: "Area is ".The corrected pseudocode. The constant goes at the top, where it is easy to find and change.
CONSTANT TinCover ← 12.0
DECLARE Length : REAL
DECLARE Width : REAL
DECLARE Area : REAL
INPUT Length
INPUT Width
Area ← Length * Width
OUTPUT "Area is ", Area
OUTPUT "Tins needed ", Area / TinCoverCheck. For a floor by metres, the area is square metres and the program outputs Tins needed 2.0.
Watch out. The exam marks each error and each correction. Name the line, say what is wrong, and write the corrected line.
Log in to join the discussion.
Loading…