Fig. 1 shows an expression tree from a cinema booking program. The program calculates the number of free seats left after online bookings and then gives eac...

Assessment: Computer Science 4CP0 | Paper 2 Mock 01 | Written Paper 2 Subject: Computer Science - 4CP0

Question 1 Report

Fig. 1 shows an expression tree from a cinema booking program. The program calculates the number of free seats left after online bookings and then gives each booking a row number. Table 1 is a small test data set from one screen. The programmer must use operators that preserve whole seat numbers. A row contains 12 seats, numbered from 1 to 12. The code editor will display an error if a word is used instead of a number in an arithmetic calculation.

-*+rows12onlinedeskfreeSeats© EAGLE BEACON GLOBAL

Table 1

Screenrowsonline bookingsdesk bookings
293817
5146423
783114

(a) Identify the order in which the two types of operator at the top of Fig. 1 are evaluated. [3]
(b) Use Table 1 to calculate the value of freeSeats for Screen 2. [4]
(c) Complete the pseudocode used to find a seat's row number.
rowNumber ← (seatNumber - 1) ___ 12 + 1 [5]
(d) Write an algorithm using arithmetic and relational operators that displays VALID only when seatNumber is from 1 to rows * 12, inclusive. [8]

Answer Details

(a) Multiplication is evaluated first [2]. Then the additions and subtraction are evaluated according to the brackets represented by the expression tree [1]. Thus the calculation is \((rows\times12)-(online+desk)\).

(b) For Screen 2:

\[9\times12=108\] [1]
\[38+17=55\] [1]
\[108-55=53\] [1]
So freeSeats is 53 seats [1].

(c) Use DIV [5]: rowNumber ← (seatNumber - 1) DIV 12 + 1. Subtracting 1 makes seats 1 to 12 become values 0 to 11; integer division by 12 identifies the zero-based row; adding 1 restores normal row numbering.

(d) A correct algorithm is:

IF seatNumber >= 1 AND seatNumber <= rows * 12 THEN
  DISPLAY "VALID"
ENDIF

The first comparison rejects values below seat 1, and the second includes the final seat in the screen [4]. The display statement is required [2], as is a correct completed control structure [2].

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning