Question 1 Report
A shop program is written in pseudocode. It accepts the prices of three items and calculates their mean price. The programmer has chosen a high-level language because the program may later need to be changed for a different shop. Assume that the three input values are 12, 15 and 9, in that order. The program uses an integer loop counter, while the result of the division may contain a fractional part.
total ← 0
FOR item ← 1 TO 3
INPUT price
total ← total + price
NEXT item
average ← __________
OUTPUT averageUse the trace table when answering part (b).
| item | price | total after addition |
|---|---|---|
| 1 | 12 | __________ |
| 2 | 15 | __________ |
| 3 | 9 | __________ |
(a) State two advantages of using a high-level language for this program. [2]
(b) Complete the trace table. [3]
(c) Give the most suitable data type for average. [2]
(d) Convert denary 25 to an 8-bit binary value. [2]
(e) State two characteristics of a compiler. [2]
(f) Explain why the pseudocode must be translated before it can be executed by the processor. [2]
(g) Complete the missing assignment statement. [2]
(a) A high-level language is easier for humans to read because it uses meaningful statements, and it is easier to write, maintain and modify [2]. It can also be translated for different processors.
(b)
| item | price | total after addition |
|---|---|---|
| 1 | 12 | 12 |
| 2 | 15 | 27 |
| 3 | 9 | 36 |
The total is an accumulator: each price is added to its current value [3].
(c) average should be a real/float [2], because division can produce a fractional result.
(d) \(25=16+8+1\), so the 8-bit binary value is 00011001 [2].
(e) A compiler translates the entire source program in one operation and produces object code or an executable file [2]. It can also report syntax errors.
(f) A processor can execute only machine-code instructions directly. Pseudocode/high-level source code must therefore be translated into machine code before execution [2].
(g) The missing assignment is average ← total / 3 [2]. With the trace values, \(36\div3=12\).
Everything you need to excel in your exams