Pre Release Solution MAY JUNE 2021
Pre Release Solution MAY JUNE 2021
Pre Release Solution MAY JUNE 2021
INTEGER Time[1:8] {9,11, 13, 15, 10, 12, 14, 16} //Time array indices 1 to 4 are for Bottom to top train
//Time array indices 5 to 8 are for Top to bottom train
INTEGER Tickets[1:8] {480, 480, 480, 480, 480, 480, 480, 640 }
//Tickets array indices 1 to 4 are for Bottom to top train
//Tickets array indices 5 to 8 are for Top to bottom train
INTEGER FreeTickets[1:8] {0, 0, 0, 0, 0, 0, 0, 0} // FreeTickets array indices 1 to 4 are for Bottom to top train
// FreeTickets array indices 5 to 8 are for Top to bottom train
REAL AmountPerTrain 0.0 // AmountPerTrain: To store amount for each single train
//CONSTANT declaration
INTEGER CONST GroupMin 10 //Minimum members in a group (used in Task 2)
INTEGER CONST GroupMax 80 //Maximum members in a group (used in Task 2)
INTEGER CONST TotalTrains 8 //Up + Down trains (used in Task 3)
REAL CONST RoundTripTicketCost 50.0 //Round trip ticket cost 25.0 + 25.0 =50.0 (used in Task 2)
REAL CONST OneWayTicketCost 25.0 //One-way ticket cost 25.0 (used in Task 3)
FOR Count 1 TO 4
OUTPUT “Departure time is ”, Time[Count], “:00 and”, Tickets[Count], “ ticket(s) still available in this train”
OUTPUT “Return time is ”, Time[Count + 4], “:00 and”, Tickets[Count + 4], “ ticket(s) still available in this train”
NEXT Count
TASK 1 OUTPUT:
//Note:
//Double slash is used to write single-line comments.
//A comment is an explanation or description of the source code of the program. It helps a developer to explain the
//logic of the code and improves program readability. At run-time, a comment is ignored by the compiler.
REPEAT
//Hour(Now): Returns current system hour (integer 0 through 23).
FOR Count 1 TO 4
OUTPUT “Departure time is ”, Time[Count], “:00 and”, Tickets[Count], “ ticket(s) still available in this train”
ELSE
OUTPUT “Train at departure time ”, Time[Count], “:00 is CLOSED”
ENDIF
// (Hour(Now) + 1): For example, if you didn‟t
//depart at 9:00 you couldn‟t return at 10:00
IF (Tickets[Count + 4] > 0 AND Time[Count + 4] > (Hour(Now) + 1) ) THEN
OUTPUT “Return time is ”, Time[Count + 4], “:00 and”, Tickets[Count + 4], “ ticket(s) still available in this train”
ELSE
OUTPUT “Train at return time ”, Time[Count + 4], “:00 is CLOSED”
ENDIF
NEXT Count
IF ( Hour(Now) >= 0 AND Hour(Now) < 15) THEN //Last train depart at exact 15:00, so tickets could be
//purchased only before 15:00.
{
REPEAT //Hour(Now): Returns current system hour (integer 0 through 23)
OUTPUT “You can purchase ticket(s) only on the day of journey and it must be return ticket”
Flag FALSE
REPEAT
{
IF Flag = TRUE THEN OUTPUT “Wrong number of tickets. Please try again.” ENDIF
OUTPUT “Tickets can be purchased for a single passenger or for a group of 10 to 80 passengers only”
OUTPUT “How many tickets would you like to buy?”
10 80
INPUT TicketsPurchased
Flag TRUE //Range Check
} //Because tickets can be purchased for a single passenger or a group.
CountOfTens DIV(TicketsPurchased, 10) // Calculation of free ticket for every tenth passenger.
// DIV( ): Integer division used to find the quotient after division. Example DIV(23,10) is 2.
Flag FALSE
OUTPUT “Select your Departure Train”
REPEAT
IF Flag = TRUE THEN OUTPUT “Wrong train selected. Please try again.” ENDIF
FOR Count 1 TO 4 //Hour(Now): Returns current system hour (integer 0 through 23)
ENDIF
NEXT Count
INPUT DepartTrain //Range Check
Flag TRUE
)
O LEVEL COMPUTER SCIENCE Page 6
Pre Release Solution May June 2021 (Pseudocode)
Course Code 2210/22 Wajid
Flag FALSE
REPEAT
IF Flag = TRUE THEN OUTPUT “Wrong train selected. Please try again.” ENDIF
FOR Count 5 TO 8 //Hour(Now): Returns current system hour (integer 0 through 23)
OUTPUT “Please enter ”, Count, “ for train at”, Time[Count], “:00. This train has ”, Tickets[Count], “tickets remaining”
ENDIF
NEXT Count
INPUT ReturnTrain
)
Tickets[ReturnTrain] Tickets[ReturnTrain] - TicketsPurchased
ELSE
ENDIF
O LEVEL COMPUTER SCIENCE Page 7
Pre Release Solution May June 2021 (Pseudocode)
Course Code 2210/22 Wajid
}
ENDIF
OUTPUT “Press E to end the day (only admin) or press any other key to continue”
INPUT Choice
REPEAT
OUTPUT “To end the day enter admin password or press N otherwise”
ENDIF
TASK 2 OUTPUT: (Test data: Group of 50, Departure at 9:00 and arrival at 10:00)
ELSE
25.0
OUTPUT “Total passengers in train at ” , Time[Count], “:00 ”, “were ”, Passengers
OUTPUT “Amount received for train at ”, Time[Count], “:00 ”, “was $”, AmountPerTrain
Flag FALSE
IF Passengers > Highest THEN
Highest Passengers
TrainID Count
Flag TRUE
MultiHigh 1
ENDIF
ENDIF
NEXT Count
IF MultiHigh = 1 THEN
OUTPUT “Train at ”, Time[TrainID], “ has the highest number of passengers today”
OUTPUT “Total number of passengers in this journey was”, Highest
ELSE
IF TotalPassengers > 0 THEN
OUTPUT MultiHigh, “ trains have same high number of passengers today”
ENDIF
ENDIF
TASK 3 OUTPUT: (Test data: Group of 50, Departure at 9:00 and arrival at 10:00)