© Muzzammil Muttur – 2022 1 CIE O Level November 2022 – Paper 2 Solutions for Pre-Release Material ©Muzzammil Muttur – July 2022 Please feel free to distribute this document. No modifications allowed to this document without prior permission. Thank you to email all your suggestions, comments and feedback. Muzzammil Muttur 5 493 1972 Facebook Page: @mmuttur learnatedutech@gmail.com © Muzzammil Muttur – 2022 2 Pre Release Material © Muzzammil Muttur – 2022 3 © Muzzammil Muttur – 2022 4 Q UESTION B REAKDOWN ● Visitor car park has 20 spaces ● Car park spaces are numbered 1 to 20 ● Booking can be made visitors up to 2 weeks in advance ● To make a booking: visitor must provide license number of car and customer name ● The next available parking space (beginning at space 1) is allocated and given data is stored ● System needs to record car park bookings ● Program work for a period of two weeks S CENARIO ● person comes for visitor parking space booking ● user is shown a menu with three options: make a parking place booking, delete and reset all data structures (arrays) or exit the system ● person provides car license number and name ● system checks if there are free spaces for that day ● if there are free spaces for required day, then give next free space (starting from number 1) to customer and store data needed A SSUMPTIONS : ● a parking space is booked for a whole day ● a customer books one parking slot at a time ● no document is checked for accessible parking space © Muzzammil Muttur – 2022 5 Processing Required © Muzzammil Muttur – 2022 6 T ASK 1 use arrays to store required data arrays to store car license numbers and names of visitors who have booked car parking spaces arrays must have enough spaces for a static period of two weeks a visitor can request a parking space for any day within the two-week period system must check that there are free spaces on the day requested visitor enter their name and car license number for making booking data will be stored in data structures (arrays) parking space will be given for next available space for the day requested if there are no free parking spaces for the day requested, the visitor is informed that booking cannot be done visitor must be told the number of their parking space for that day at the end of the two-week period, all data is to be deleted and system must be ready for the next two week period T ASK 2 ask user if accessible space is needed answer to be recorded as Y/N if accessible space is to be given, then allocate the first free space (starting from if no accessible space is to be given, then give the first free space as from space 20 (general spaces) and keep decrementing until parking space 6 is booked © Muzzammil Muttur – 2022 7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 © Muzzammil Muttur – 2022 8 T ASK 3 calculate statistics based on the array used to store parking space booking use a counter to access the array for the different days show the user a menu to choose between the different statistics that can be generated choice 1 : display the number of accessible spaces used on a specific day (count number of elements not set to “Free” for spaces 1 to 5) choice 2 : display the number of general spaces used on a specific day (count number of elements not set to “Free” for spaces 6 to 20) choice 3 : display total number of spaces used on a specific day choice 4 : display total number of accessible spaces used for the whole 14-day period (count number of elements not set to “Free” for spaces 1 to 5 for each of the 14 days) choice 5 : display total number of general spaces used for the whole 14-day period (count number of elements not set to “Free” for spaces 6 to 20 for each of the 14 days) choice 6 : display total number of spaces used for the whole 14-day period (count number of elements not set to “Free”) © Muzzammil Muttur – 2022 9 Pseudocode Solutions © Muzzammil Muttur – 2022 10 T ASK 1 DECLARE dayNumber, startingArrayID : INTEGER DECLARE i, Count, choice : INTEGER DECLARE VisitorName, CarLicenseNumber : STRING DECLARE FreeLocationFound : BOOLEAN DECLARE TotalAvailableParkingSlots : INTEGER DECLARE ParkingBookingName[280] : STRING DECLARE ParkingBookingCarNumber[280] : STRING //initialize both arrays FOR i 1 To 280 ParkingBookingName[i] "Free" ParkingBookingCarNumber[i] "Free" Next i DO OUTPUT "Parking Space Booking System" OUTPUT "1. Make Booking" OUTPUT "2. Delete All Stored Data" OUTPUT "3. Exit" OUTPUT "Enter your choice number: " INPUT choice IF choice = 1 THEN REPEAT OUTPUT "Enter day number [1 to 14]: " INPUT dayNumber UNTIL dayNumber >= 1 AND dayNumber <= 14 startingArrayID ((dayNumber - 1) * 20) + 1 Count 0 FreeLocationFound FALSE TotalAvailableParkingSlots 20 REPEAT IF ParkingBookingName [startingArrayID + Count] = "Free" THEN FreeLocationFound TRUE ELSE Count Count + 1 END IF UNTIL Count = TotalAvailableParkingSlots OR FreeLocationFound = TRUE IF FreeLocationFound = TRUE THEN OUTPUT "Enter visitor name: " INPUT VisitorName OUTPUT “ Enter car license number: " INPUT CarLicenseNumber ParkingBookingName[startingArrayID + Count] VisitorName ParkingBookingCarNumber[startingArrayID + Count] CarLicenseNumber End If © Muzzammil Muttur – 2022 11 If FreeLocationFound = False Then OUTPUT "Sorry. No more free locations on selected day." End If //delete all data over the last two weeks period ELSEIF choice = 2 THEN FOR i = 1 TO 280 ParkingBookingName[i] "Free" ParkingBookingCarNumber[i] "Free" NEXT i END IF UNTIL choice = 3 © Muzzammil Muttur – 2022 12 T ASK 2 DECLARE dayNumber, startingArrayID : INTEGER DECLARE i, Count, choice As INTEGER DECLARE VisitorName, CarLicenseNumber : STRING DECLARE FreeLocationFound : BOOLEAN DECLARE parkingSlotNumber : INTEGER DECLARE AccessibleSpaceNeeded : CHAR DECLARE TotalAvailableParkingSpaces : INTEGER DECLARE ParkingBookingName[280] : STRING DECLARE ParkingBookingCarNumber[280] : STRING FOR i 1 TO 280 ParkingBookingName[i] "Free" ParkingBookingCarNumber[i] "Free" NEXT i Do OUTPUT "Parking Space Booking System" OUTPUT "1. Make Booking" OUTPUT "2. Delete All Stored Data" OUTPUT "3. Exit" OUTPUT "Enter your choice number: " INPUT choice IF choice = 1 THEN REPEAT OUTPUT "Enter day number [1 to 14]: " INPUT dayNumber UNTIL dayNumber >= 1 AND dayNumber <= 14 startingArrayID ((dayNumber - 1) * 20) + 1 OUTPUT "Do you need an accesible parking space? [Y/N]" INPUT AccessibleSpaceNeeded FreeLocationFound FALSE IF AccessibleSpaceNeeded = "Y" THEN Count 0 TotalAvailableParkingSpaces 20 REPEAT IF ParkingBookingName [startingArrayID + Count] = "Free" THEN FreeLocationFound TRUE ELSE Count Count + 1 END IF UNTIL Count = TotalAvailableParkingSpaces OR FreeLocationFound = TRUE © Muzzammil Muttur – 2022 13 ELSEIF AccessibleSpaceNeeded = "N" THEN TotalAvailableParkingSpaces 15 Count 19 REPEAT IF ParkingBookingName [startingArrayID + Count] = "Free" THEN FreeLocationFound TRUE ELSE Count Count - 1 END IF UNTIL Count = 5 OR FreeLocationFound = TRUE END IF IF FreeLocationFound = TRUE THEN OUTPUT "Enter visitor name: " INPUT VisitorName OUTPUT "Enter car license number: " INPUT CarLicenseNumber ParkingBookingName [startingArrayID + Count] VisitorName ParkingBookingCarNumber [startingArrayID + Count] CarLicenseNumber OUTPUT "Parking space number booked: " , Count + 1 END IF IF FreeLocationFound = FALSE THEN OUTPUT "Sorry. No more free locations on selected day." END IF ELSEIF choice = 2 THEN FOR i 1 TO 280 ParkingBookingName[i] "Free" ParkingBookingCarNumber[i] "Free" NEXT END IF UNTIL choice = 3 © Muzzammil Muttur – 2022 14 T ASK 3 DECLARE dayNumber, startingArrayID : INTEGER DECLARE i, Count, choice, statisticsChoice, parkingCount : INTEGER DECLARE VisitorName, CarLicenseNumber : STRING DECLARE FreeLocationFound : BOOLEAN DECLARE parkingSlotNumber : INTEGER DECLARE AccessibleSpaceNeeded : CHAR DECLARE TotalAvailableParkingSpaces : INTEGER DECLARE ParkingBookingName[280] : STRING DECLARE ParkingBookingCarNumber[280]: STRING FOR i 1 TO 280 ParkingBookingName[i] "Free" ParkingBookingCarNumber[i] "Free" NEXT i REPEAT OUTPUT"Parking Space Booking System" OUTPUT"1. Make Booking" OUTPUT"2. Delete All Stored Data" OUTPUT"3. Show Statistics" OUTPUT"4. Exit" OUTPUT"Enter your choice number: " INPUT choice IF choice = 1 THEN REPEAT OUTPUT"Enter day number [1 to 14]: " INPUT dayNumber UNTIL dayNumber >= 1 AND dayNumber <= 14 startingArrayID = ((dayNumber - 1) * 20) + 1 OUTPUT "Do you need an accesible parking space? [Y/N]" INPUT AccessibleSpaceNeeded FreeLocationFound FALSE IF AccessibleSpaceNeeded = "Y" THEN Count 0 TotalAvailableParkingSpaces 20 REPEAT IF ParkingBookingName[startingArrayID + Count] "Free" THEN FreeLocationFound True ELSE Count = Count + 1 END IF © Muzzammil Muttur – 2022 15 UNTIL Count = TotalAvailableParkingSpaces OR FreeLocationFound = TRUE ELSEIF AccessibleSpaceNeeded = "N" THEN TotalAvailableParkingSpaces 15 Count 19 REPEAT IF ParkingBookingName[startingArrayID + Count] = "Free" THEN FreeLocationFound True ELSE Count Count - 1 END IF UNTIL Count = 5 OR FreeLocationFound = TRUE END IF IF FreeLocationFound = TRUE THEN OUTPUT"Enter visitor name: " INPUT VisitorName OUTPUT"Enter car license number: " INPUT CarLicenseNumber ParkingBookingName[startingArrayID + Count] VisitorName ParkingBookingCarNumber[startingArrayID + Count] CarLicenseNumber OUTPUTstartingArrayID + Count OUTPUT "Parking space number booked: " , Count + 1 END IF IF FreeLocationFound = FALSE THEN OUTPUT "Sorry. No more free locations on selected day." END IF ELSEIF choice = 2 THEN FOR i 1 TO 280 ParkingBookingName[i] "Free" ParkingBookingCarNumber[i] "Free" NEXT i 'show statistics ELSEIF choice = 3 THEN OUTPUT "1 - Number of accessible spaces used on a specific day" OUTPUT "2 - Number of general spaces used on a specific day" OUTPUT "3 - Total number of parking spaces used on a specific day" OUTPUT "4 - Total number accessible spaces used on whole 14-day period" OUTPUT "5 - Total number general spaces used on whole 14-day period" OUTPUT "6 - Total number of parking spaces used on whole 14-day period" OUTPUT "7 - Back to main menu" © Muzzammil Muttur – 2022 16 OUTPUT"Enter your choice number: " INPUT statisticsChoice IF statisticsChoice = 1 THEN OUTPUT"Enter day number [1-14]: " INPUT dayNumber startingArrayID ((dayNumber - 1) * 20) + 1 parkingCount 0 FOR i 0 TO 4 IF ParkingBookingName[startingArrayID + i] <> "Free" THEN parkingCount parkingCount + 1 END IF NEXT i OUTPUT"Number of accessible spaces used on day ",dayNumber, ": ", parkingCount END IF IF statisticsChoice = 2 THEN OUTPUT"Enter day number [1-14]: " INPUT dayNumber startingArrayID ((dayNumber - 1) * 20) + 1 parkingCount 0 FOR i 5 TO 19 IF ParkingBookingName[startingArrayID + i] <> "Free" THEN parkingCount parkingCount + 1 END IF NEXT i OUTPUT "Number of accessible spaces used on day ",dayNumber,": " ,parkingCount END IF IF statisticsChoice = 3 THEN OUTPUT"Enter day number [1-14]: " INPUT dayNumber startingArrayID ((dayNumber - 1) * 20) + 1 parkingCount 0 FOR i 0 TO 19 IF ParkingBookingName[startingArrayID + i] <> "Free" THEN parkingCount parkingCount + 1 END IF NEXT i OUTPUT "Number of accessible spaces used on day ",dayNumber,": " ,parkingCount © Muzzammil Muttur – 2022 17 END IF IF statisticsChoice = 4 THEN parkingCount 0 FOR dayNumber = 1 TO 14 startingArrayID ((dayNumber - 1) * 20) + 1 FOR i 0 TO 4 IF ParkingBookingName[startingArrayID + i] <> "Free" THEN parkingCount = parkingCount + 1 END IF NEXT i NEXT dayNumber OUTPUT "Number of accessible spaces used on day ",dayNumber,": ",parkingCount END IF IF statisticsChoice = 5 THEN parkingCount 0 FOR dayNumber 1 TO 14 startingArrayID ((dayNumber - 1) * 20) + 1 FOR i 5 TO 19 IF ParkingBookingName[startingArrayID + i] <> "Free" THEN parkingCount parkingCount + 1 END IF NEXT i NEXT dayNumber OUTPUT"Number of accessible spaces used on day ",dayNumber,": ", parkingCount END IF IF statisticsChoice = 6 THEN parkingCount 0 FOR dayNumber = 1 TO 14 startingArrayID ((dayNumber - 1) * 20) + 1 FOR i 0 TO 19 IF ParkingBookingName[startingArrayID + i] <> "Free" THEN parkingCount parkingCount + 1 END IF NEXT i NEXT dayNumber © Muzzammil Muttur – 2022 18 OUTPUT"Number of accessible spaces used on day ",dayNumber,": ", parkingCount END IF END IF UNTIL choice = 4 © Muzzammil Muttur – 2022 19 U SING CASE S TRUCTURE CASE structure could have been used to implement the different menu options. A subroutine is then called for each menu option. The following menu is displayed for Task 3. Parking Space Booking System 1. Make Booking 2. Delete All Stored Data 3. Show Statistics 4. Exit Enter your choice number: REPEAT OUTPUT "Parking Space Booking System" OUTPUT "1. Make Booking" OUTPUT "2. Delete All Stored Data" OUTPUT "3. Show Statistics" OUTPUT "4. Exit" OUTPUT "Enter your choice number: " INPUT choice CASE menuChoice OF 1 : makeBooking () 2 : DeleteAllData() 3 : ShowStatisticsMenu() 4 : exitProgram() OTHERWISE Output ”Enter a number between 1 and 4.” ENDCASE Until Choice >= 1 and Choice <= 4 © Muzzammil Muttur – 2022 20 D ATA V ALIDATION Validating data input could be done using a Repeat...Until loop as follows: The following data input: OUTPUT"Enter day number [1 to 14]: " INPUT dayNumber Is validated as follows: REPEAT OUTPUT"Enter day number [1 to 14]: " INPUT dayNumber UNTIL dayNumber >= 1 AND dayNumber <= 14