Computer Science · Oct / Nov 2024 · Paper 22 · Question 12
0478
As printed in the paper
The question as text
A one-dimensional (1D) array vv¦§©ª contains the names of up to 20 rooms in a house. A two-dimensional (2D) array y¦z§yvz§©ª is used to store the length, width and area of each room. The position of any room’s data is the same in both arrays. For example, the data in index 5 of y¦z§yvz§©ª belongs to the room in index 5 of vv¦§©ª The variable ¦ïw stores the number of rooms for which data is to be input. There must be at least 3 rooms but no more than 20. Write a program that meets the following requirements: • allows the number of rooms for which data is required to be input, stored and validated • allows the name of the room and the length and width of the room, in metres, to be entered and stored • allows the area of each room to be calculated as length multiplied by width and stored as square metres rounded to two decimal places • calculates the average size of all the rooms by area, in square metres, rounded to two decimal places • finds the largest room and smallest room by area • outputs the names of all rooms with their dimensions and area • outputs the names of the largest room and smallest room by area • outputs the total area of the house and the average size of all the rooms by area. You must use pseudocode or program code and add comments to explain how your code works. You do not need to declare any arrays or variables; you may assume that this has already been done. All inputs and outputs must contain suitable messages.
Read automatically from the paper; the printed page above is exact.
Show the answer and mark scheme
Data Structures required with names as given in the scenario:
Arrays or lists Rooms[], Dimensions[]
Variables
Number
Requirements (techniques):
R1 Input and store number of rooms, the names of the rooms and their dimensions, including validation of number of rooms (input with prompts, (nested) iteration, use of variables, 1D and 2D arrays, validation). R2 Calculate and store the area of each room, the total area of the house and the average room area rounded to two decimal places. Find the smallest and largest rooms (calculation, totalling, rounding, finding maximum and minimum values, iteration).
R3 Output the results, including contents of the arrays and the calculated data (iteration, output).
Example 15-mark answer in pseudocode
// input and validation of number of rooms
REPEAT
OUTPUT "How many rooms are in your house (enter a number between 3 and 20 inclusive)?"
INPUT Number
IF Number < 3 OR Number > 20
THEN
OUTPUT "The number of rooms must be between 3 and 20 inclusive, please try again"
ENDIF
UNTIL Number >= 3 AND Number <= 20
// input of room names and dimensions – could be more than one loop
FOR InLoop ← 1 TO Number
OUTPUT "Enter the name of room ", InLoop
INPUT Rooms[InLoop]
OUTPUT "Enter the length of the room in metres" INPUT Dimensions[InLoop, 1]
OUTPUT "Enter the width of the room in metres" INPUT Dimensions[InLoop, 2]
Dimensions[InLoop, 3] ← ROUND(Dimensions[InLoop, 1] * Dimensions[InLoop, 2], 2)
NEXT InLoop
// calculates total area and average area – rounded values have been stored
TotArea ← 0
FOR Total ← 1 TO Number
TotArea ← TotArea + Dimensions[Total, 3]
NEXT Total
AvArea ← ROUND(TotArea / Number, 2)
// finding largest and smallest rooms
Larea ← 0
Sarea ← 100000
Lindex ← 1
Sindex ← 1
FOR Count ← 1 TO Number
IF Dimensions[Count, 3] > Larea
THEN
Larea ← Dimensions[Count, 3]
Lindex ← Count
ENDIF
IF Dimensions[Count, 3] < Sarea
THEN
Sarea ← Dimensions[Count, 3]
Sindex ← Count
ENDIF
NEXT Count
// outputting the results
FOR OutLoop ← 1 TO Number
OUTPUT "Room: ", Rooms[Outloop]
OUTPUT "Length: ", Dimensions[OutLoop, 1], " metres" OUTPUT "Width: ", Dimensions[OutLoop, 2], " metres" OUTPUT "Area: ", Dimensions[OutLoop, 3], " square metres"
Next OutLoop
OUTPUT "The largest room is: ", Rooms[Lindex]
OUTPUT "The smallest room is: ", Rooms[Sindex]
OUTPUT "The total area of the house is: ", TotArea, " square metres"
OUTPUT "The average area of the rooms is: ", AvArea, " square metres"
Marking Instructions in italics
AO2: Apply knowledge and understanding of the principles and concepts of computer science to a given context, including the analysis and design of computational or programming problems
1–3
4–6
7–9
Make a free account to save your answers and see your weak topics and ask the AI why a wrong answer is wrong.

