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 [email protected] © Muzzammil Muttur – 2022 1 Pre Release Material © Muzzammil Muttur – 2022 2 © Muzzammil Muttur – 2022 3 QUESTION BREAKDOWN ● 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 SCENARIO ● 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 ASSUMPTIONS: ● 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 4 Processing Required © Muzzammil Muttur – 2022 5 TASK 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 TASK 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 6 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 © Muzzammil Muttur – 2022 7 TASK 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 8 Pseudocode Solutions © Muzzammil Muttur – 2022 9 TASK 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 10 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 11 TASK 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 12 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 13 TASK 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 14 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 15 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 16 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 17 OUTPUT"Number of accessible spaces used on day ",dayNumber,": ", parkingCount END IF END IF UNTIL choice = 4 © Muzzammil Muttur – 2022 18 USING CASE STRUCTURE 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 19 DATA VALIDATION 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 © Muzzammil Muttur – 2022 20 Potential Exam Questions Based on Past CIE Exam Papers © Muzzammil Muttur – 2022 21 1 (a) Write pseudocode for declaring a variable to be used. DECLARE VisitorName : STRING DECLARE dayNumber : INTEGER (b) Give an example of a constant you have used. AcessibleSpaces could have been used as a constant. It would then be declared and initialised at the start of the program. CONSTANT AcessibleSpaces : INTEGER AcessibleSpaces 5 2 List three variables in your solution and what they are used for. Variable 1: FreeLocationFound BOOLEAN data type It is a flag used to indicate if a free location has been found for the requested day. Variable 2: AccessibleSpaceNeeded CHAR data type It is used to store the answer to the question: “Is an accessible parking space needed? [Y/N]” Answer to the question is either ‘Y’ or ‘N’. Variable 3: dayNumber INTEGER data type It is used to store the user input for the day number when to make the booking (must be in the range 1 to 14 inclusive). 3 Give three examples of test data for day number (day on which to make parking space booking). Normal data: 1, 2, 5, 8, 10, 14 Abnormal data: 0, 15, three, $3.40 Borderline/Extreme data: 1, 14 (borderline and normal data); 0, 15 (borderline and abnormal data) 4 Describe the arrays you could have used in Task 1. Include the name, data type, use and sample data for each array. The two arrays used are: - Array 1: ParkingBookingName - Data type: STRING - SIZE: 280 - Used to store customer names when booking a parking space © Muzzammil Muttur – 2022 22 - Example: John Smith - Array 2: ParkingBookingCarNumber - Data type: STRING - SIZE: 280 - Used to store car license number when booking a parking space - Example: B1458 5 Show any validation check you have used in your solution REPEAT OUTPUT"Enter day number [1 to 14]: " INPUT dayNumber UNTIL dayNumber >= 1 AND dayNumber <= 14 6 Explain how your program checks that there is a free space (general parking space) for the day requested and identifies the slot number to be allocated. 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 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 7 Explain how your program for Task 3 calculates the statistics for the number of general parking spaces used over the 14-day period. Any programming statements used in your answer must be fully explained. parkingCount 0 FOR dayNumber 1 TO 14 startingArrayID ((dayNumber - 1) * 20) + 1 © Muzzammil Muttur – 2022 23 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 8 Comment on the efficiency of your design. The program has been made as efficient as possible with no block of code being uselessly repeated and duplicated. A single array of 280 locations has been used to store customer names for the whole 14-day period instead of 14 individual arrays. The program simply needs to move to the starting array location depending on the day chose. The same technique has been used to store customer license numbers. Additionally: you could be asked to write the pseudocode for Task 2 or Task 3 assuming that Task 1 or Task 2 have been completed. © Muzzammil Muttur – 2022 24 Program Code Microsoft Visual Basic Console Mode © Muzzammil Muttur – 2022 25 TASK 1 Module Module1 Sub Main() Dim dayNumber, startingArrayID As Integer Dim i, Count, choice As Integer Dim VisitorName, CarLicenseNumber As String Dim FreeLocationFound As Boolean Dim TotalAvailableParkingSlots As Integer Dim ParkingBookingName(280) As String Dim ParkingBookingCarNumber(280) As String For i = 1 To 280 ParkingBookingName(i) = "Free" ParkingBookingCarNumber(i) = "Free" Next Do Console.Clear() Console.WriteLine("Parking Space Booking System") Console.WriteLine("1. Make Booking") Console.WriteLine("2. Delete All Stored Data") Console.WriteLine("3. Exit") Console.WriteLine() Console.WriteLine("Enter your choice number: ") choice = Console.ReadLine If choice = 1 Then Do Console.WriteLine("Enter day number [1 to 14]: ") dayNumber = Console.ReadLine Loop Until dayNumber >= 1 And dayNumber <= 14 startingArrayID = ((dayNumber - 1) * 20) + 1 Count = 0 FreeLocationFound = False TotalAvailableParkingSlots = 20 Do If ParkingBookingName(startingArrayID + Count) = "Free" Then FreeLocationFound = True Else Count = Count + 1 End If Loop Until Count = TotalAvailableParkingSlots Or FreeLocationFound = True If FreeLocationFound = True Then Console.WriteLine("Enter visitor name: ") VisitorName = Console.ReadLine Console.WriteLine("Enter car license number: ") CarLicenseNumber = Console.ReadLine ParkingBookingName(startingArrayID + Count) = VisitorName © Muzzammil Muttur – 2022 26 ParkingBookingCarNumber(startingArrayID + Count) = CarLicenseNumber Console.WriteLine(startingArrayID + Count) Console.WriteLine("Parking space number booked: " , Count + 1) CONSOLE.READLINE() End If If FreeLocationFound = False Then Console.WriteLine("Sorry. No more free locations on selected day.") CONSOLE.READLINE() End If ElseIf choice = 2 Then For i = 1 To 280 ParkingBookingName(i) = "Free" ParkingBookingCarNumber(i) = "Free" Next End If Loop Until choice = 3 CONSOLE.READLINE() End Sub End Module © Muzzammil Muttur – 2022 27 TASK 2 Module Module1 Sub Main() Dim dayNumber, startingArrayID As Integer Dim i, Count, choice As Integer Dim VisitorName, CarLicenseNumber As String Dim FreeLocationFound As Boolean Dim parkingSlotNumber As Integer Dim AccessibleSpaceNeeded As Char Dim TotalAvailableParkingSpaces As Integer Dim ParkingBookingName(280) As String Dim ParkingBookingCarNumber(280) As String For i = 1 To 280 ParkingBookingName(i) = "Free" ParkingBookingCarNumber(i) = "Free" Next Do Console.Clear() Console.WriteLine("Parking Space Booking System") Console.WriteLine("1. Make Booking") Console.WriteLine("2. Delete All Stored Data") Console.WriteLine("3. Exit") Console.WriteLine() Console.WriteLine("Enter your choice number: ") choice = Console.ReadLine If choice = 1 Then Do Console.WriteLine("Enter day number [1 to 14]: ") dayNumber = Console.ReadLine Loop Until dayNumber >= 1 And dayNumber <= 14 startingArrayID = ((dayNumber - 1) * 20) + 1 Console.WriteLine("Do you need an accesible parking space? [Y/N]") AccessibleSpaceNeeded = Console.ReadLine FreeLocationFound = False If AccessibleSpaceNeeded = "Y" Then Count = 0 TotalAvailableParkingSpaces = 20 Do If ParkingBookingName(startingArrayID + Count) = "Free" Then FreeLocationFound = True Else Count = Count + 1 End If Loop Until Count = TotalAvailableParkingSpaces Or FreeLocationFound = True ElseIf AccessibleSpaceNeeded = "N" Then TotalAvailableParkingSpaces = 15 Count = 19 Do If ParkingBookingName(startingArrayID + Count) = "Free" Then FreeLocationFound = True Else © Muzzammil Muttur – 2022 28 Count = Count - 1 End If Loop Until Count = 5 Or FreeLocationFound = True End If If FreeLocationFound = True Then Console.WriteLine("Enter visitor name: ") VisitorName = Console.ReadLine Console.WriteLine("Enter car license number: ") CarLicenseNumber = Console.ReadLine ParkingBookingName(startingArrayID + Count) = VisitorName ParkingBookingCarNumber(startingArrayID + Count) = CarLicenseNumber Console.WriteLine(startingArrayID + Count) Console.WriteLine("Parking space number booked: " & Count + 1) CONSOLE.READLINE() End If If FreeLocationFound = False Then Console.WriteLine("Sorry. No more free locations on selected day.") CONSOLE.READLINE() End If ElseIf choice = 2 Then For i = 1 To 280 ParkingBookingName(i) = "Free" ParkingBookingCarNumber(i) = "Free" Next End If Loop Until choice = 3 CONSOLE.READLINE() End Sub End Module © Muzzammil Muttur – 2022 29 TASK 3 Module Module1 Sub Main() Dim dayNumber, startingArrayID As Integer Dim i, Count, choice, statisticsChoice, parkingCount As Integer Dim VisitorName, CarLicenseNumber As String Dim FreeLocationFound As Boolean Dim parkingSlotNumber As Integer Dim AccessibleSpaceNeeded As Char Dim TotalAvailableParkingSpaces As Integer Dim ParkingBookingName(280) As String Dim ParkingBookingCarNumber(280) As String For i = 1 To 280 ParkingBookingName(i) = "Free" ParkingBookingCarNumber(i) = "Free" Next Do Console.Clear() Console.WriteLine("Parking Space Booking System") Console.WriteLine("1. Make Booking") Console.WriteLine("2. Delete All Stored Data") Console.WriteLine("3. Show Statistics") Console.WriteLine("4. Exit") Console.WriteLine() Console.WriteLine("Enter your choice number: ") choice = Console.ReadLine If choice = 1 Then Do Console.WriteLine("Enter day number [1 to 14]: ") dayNumber = Console.ReadLine Loop Until dayNumber >= 1 And dayNumber <= 14 startingArrayID = ((dayNumber - 1) * 20) + 1 Console.WriteLine("Do you need an accesible parking space? [Y/N]") AccessibleSpaceNeeded = Console.ReadLine FreeLocationFound = False If AccessibleSpaceNeeded = "Y" Then Count = 0 TotalAvailableParkingSpaces = 20 Do If ParkingBookingName(startingArrayID + Count) = "Free" Then FreeLocationFound = True Else Count = Count + 1 End If Loop Until Count = TotalAvailableParkingSpaces Or FreeLocationFound = True ElseIf AccessibleSpaceNeeded = "N" Then TotalAvailableParkingSpaces = 15 Count = 19 Do If ParkingBookingName(startingArrayID + Count) = "Free" Then FreeLocationFound = True Else © Muzzammil Muttur – 2022 30 Count = Count - 1 End If Loop Until Count = 5 Or FreeLocationFound = True End If If FreeLocationFound = True Then Console.WriteLine("Enter visitor name: ") VisitorName = Console.ReadLine Console.WriteLine("Enter car license number: ") CarLicenseNumber = Console.ReadLine ParkingBookingName(startingArrayID + Count) = VisitorName ParkingBookingCarNumber(startingArrayID + Count) = CarLicenseNumber Console.WriteLine(startingArrayID + Count) Console.WriteLine("Parking space number booked: " & Count + 1) CONSOLE.READLINE() End If If FreeLocationFound = False Then Console.WriteLine("Sorry. No more free locations on selected day.") CONSOLE.READLINE() End If ElseIf choice = 2 Then For i = 1 To 280 ParkingBookingName(i) = "Free" ParkingBookingCarNumber(i) = "Free" Next 'show statistics ElseIf choice = 3 Then Console.Clear() Console.WriteLine("1 - Number of accessible spaces used on a specific day") Console.WriteLine("2 - Number of general spaces used on a specific day") Console.WriteLine("3 - Total number of parking spaces used on a specific day") Console.WriteLine("4 - Total number accessible spaces used on whole 14-day period") Console.WriteLine("5 - Total number general spaces used on whole 14-day period") Console.WriteLine("6 - Total number of parking spaces used on whole 14-day period") Console.WriteLine("7 - Back to main menu") Console.WriteLine() Console.WriteLine("Enter your choice number: ") statisticsChoice = Console.ReadLine If statisticsChoice = 1 Then Console.WriteLine("Enter day number [1-14]: ") dayNumber = Console.ReadLine startingArrayID = ((dayNumber - 1) * 20) + 1 parkingCount = 0 For i = 0 To 4 If ParkingBookingName(startingArrayID + i) <> "Free" Then parkingCount = parkingCount + 1 End If Next Console.Clear() Console.WriteLine("Number of accessible spaces used on day " & dayNumber & ": " & parkingCount) CONSOLE.READLINE() End If © Muzzammil Muttur – 2022 31 If statisticsChoice = 2 Then Console.WriteLine("Enter day number [1-14]: ") dayNumber = Console.ReadLine startingArrayID = ((dayNumber - 1) * 20) + 1 parkingCount = 0 For i = 5 To 19 If ParkingBookingName(startingArrayID + i) <> "Free" Then parkingCount = parkingCount + 1 End If Next Console.Clear() Console.WriteLine("Number of accessible spaces used on day " & dayNumber & ": " & parkingCount) CONSOLE.READLINE() End If If statisticsChoice = 3 Then Console.WriteLine("Enter day number [1-14]: ") dayNumber = Console.ReadLine startingArrayID = ((dayNumber - 1) * 20) + 1 parkingCount = 0 For i = 0 To 19 If ParkingBookingName(startingArrayID + i) <> "Free" Then parkingCount = parkingCount + 1 End If Next Console.Clear() Console.WriteLine("Number of accessible spaces used on day " & dayNumber & ": " & parkingCount) CONSOLE.READLINE() 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 Next Console.WriteLine("Number of accessible spaces used on day " & dayNumber & ": " & parkingCount) CONSOLE.READLINE() End If If statisticsChoice = 5 Then parkingCount = 0 For dayNumber = 1 To 14 startingArrayID = ((dayNumber - 1) * 20) + 1 © Muzzammil Muttur – 2022 32 For i = 5 To 19 If ParkingBookingName(startingArrayID + i) <> "Free" Then parkingCount = parkingCount + 1 End If Next Next Console.WriteLine("Number of accessible spaces used on day " & dayNumber & ": " & parkingCount) CONSOLE.READLINE() 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 Next Console.WriteLine("Number of accessible spaces used on day " & dayNumber & ": " & parkingCount) Console.ReadLine() End If End If Loop Until choice = 4 CONSOLE.READLINE() End Sub End Module © Muzzammil Muttur – 2022 33
Enter the password to open this PDF file:
-
-
-
-
-
-
-
-
-
-
-
-