Pre Release Solution MAY JUNE 2021

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Pre Release Solution May June 2021 (Pseudocode)

Course Code 2210/22 Wajid

O LEVEL COMPUTER SCIENCE Page 1


Pre Release Solution May June 2021 (Pseudocode)
Course Code 2210/22 Wajid

//Initialization of suitable data structures (arrays)

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

//Variable declaration and intialization

INTEGER Count 0, Passengers 0

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)

//Screen display for the start of the day

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

// [Count + 4] to retrieve the return (top to bottom) trains data

O LEVEL COMPUTER SCIENCE Page 2


Pre Release Solution May June 2021 (Pseudocode)
Course Code 2210/22 Wajid

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.

O LEVEL COMPUTER SCIENCE Page 3


Pre Release Solution May June 2021 (Pseudocode)
Course Code 2210/22 Wajid

//Task 2 Variable declaration and intialization


CHAR Choice  „N‟
INTEGER CountOfTens  0, TicketsPurchased  0, DepartTrain  0, ReturnTrain 0
REAL Price  0.0
Flag variable is used as a signal
BOOLEAN Flag  FALSE in programming to let the
program know that a certain
STRING Password  “ ” // “ ”: Empty string condition has met.

REPEAT
//Hour(Now): Returns current system hour (integer 0 through 23).
FOR Count  1 TO 4

IF ( Tickets[Count] > 0 AND Time[Count] > Hour(Now) )THEN

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

O LEVEL COMPUTER SCIENCE Page 4


Pre Release Solution May June 2021 (Pseudocode)
Course Code 2210/22 Wajid

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 “Dear traveller, do you want to book your journey? (Y/N)”


INPUT Choice //Character Check
UNTIL (Choice = „Y‟ OR Choice = „N‟)
}
ELSE
{
OUTPUT “No more trains available today. Please come tomorrow”
Choice  „N‟
}
ENDIF

O LEVEL COMPUTER SCIENCE Page 5


Pre Release Solution May June 2021 (Pseudocode)
Course Code 2210/22 Wajid

IF Choice = „Y‟ THEN


{
OUTPUT “Please Purchase Ticket(s)”

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.

UNTIL ( (TicketsPurchased = 1) OR ( TicketsPurchased > = GroupMin AND TicketsPurchased < = GroupMax) )

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)

IF ( Tickets[Count] > = TicketsPurchased AND Time[Count] > Hour(Now) ) THEN


OUTPUT “Please enter ”, Count, “ for train at”, Time[Count], “:00. This train has ”, Tickets[Count], “tickets remaining”

ENDIF
NEXT Count
INPUT DepartTrain //Range Check
Flag  TRUE

UNTIL ( (DepartTrain >= 1 AND DepartTrain < = 4) AND

(Tickets[DepartTrain] > = TicketsPurchased ) AND ( Time[DepartTrain] > Hour(Now) )

)
O LEVEL COMPUTER SCIENCE Page 6
Pre Release Solution May June 2021 (Pseudocode)
Course Code 2210/22 Wajid

Tickets[DepartTrain]  Tickets[DepartTrain] – TicketsPurchased //Calculate and update remaining tickets


FreeTickets[DepartTrain]  FreeTickets[DepartTrain] + CountOfTens //Save free tickets for each train

Flag  FALSE

OUTPUT “Select your Return Train”

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)

IF ( Tickets[Count] > = TicketsPurchased AND Time[Count] > Hour(Now) + 1 )THEN

OUTPUT “Please enter ”, Count, “ for train at”, Time[Count], “:00. This train has ”, Tickets[Count], “tickets remaining”

ENDIF

NEXT Count

INPUT ReturnTrain

Flag  TRUE //Range Check

UNTIL ( (ReturnTrain > = 5 AND ReturnTrain < = 8) AND

(Tickets[ReturnTrain] > = TicketsPurchased ) AND Time[ReturnTrain] > (Hour(Now) + 1) )

)
Tickets[ReturnTrain]  Tickets[ReturnTrain] - TicketsPurchased

FreeTickets[ReturnTrain]  FreeTickets[ReturnTrain] + CountOfTens

Price  ( TicketsPurchased – CountOfTens ) * RoundTripTicketCost //CONSTANT RoundTripTicketCost  50.0

IF CountOfTens > 0 THEN

OUTPUT “Total Price is $” , TicketsPurchased * RoundTripTicketCost


OUTPUT “Discount is $”, CountOfTens * RoundTripTicketCost
OUTPUT “Pay the discounted price of $”, Price, “only and collect your tickets”

ELSE

OUTPUT “Please pay $”, Price, “and collect your ticket”

ENDIF
O LEVEL COMPUTER SCIENCE Page 7
Pre Release Solution May June 2021 (Pseudocode)
Course Code 2210/22 Wajid

}
ENDIF

Password  “” //Empty string to initialize Password

OUTPUT “Press E to end the day (only admin) or press any other key to continue”

INPUT Choice

IF Choice = „E‟ THEN

REPEAT

OUTPUT “To end the day enter admin password or press N otherwise”

INPUT Password // “abc123” is admin password.

UNTIL (Password = “abc123” OR Password= “N”)

ENDIF

UNTIL (Password = “abc123”)

O LEVEL COMPUTER SCIENCE Page 8


Pre Release Solution May June 2021 (Pseudocode)
Course Code 2210/22 Wajid

TASK 2 OUTPUT: (Test data: Group of 50, Departure at 9:00 and arrival at 10:00)

O LEVEL COMPUTER SCIENCE Page 9


Pre Release Solution May June 2021 (Pseudocode)
Course Code 2210/22 Wajid

//Task 3 Variable declaration and intialization


INTEGER Highest  0, TrainID  0, TotalPassengers  0, MultiHigh  0

REAL TotalMoney  0.0

FOR Count 1 TO TotalTrains // CONSTANT TotalTrains 8

IF Count < 8 THEN 8

Passengers  (480 - Tickets[Count])

ELSE

Passengers  (640 - Tickets[Count])

ENDIF //CONSTANT OneWayTicketCost  25.0

AmountPerTrain ( (Passengers – FreeTickets[Count]) * OneWayTicketCost )

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

IF Passengers = Highest AND Flag = FALSE THEN

MultiHigh  MultiHigh +1 //If multiple trains have same number of passengers

ENDIF

//Total passengers depart = Total passengers return

IF Count < = 4 THEN TotalPassengers  TotalPassengers + Passengers ENDIF

TotalMoney  TotalMoney + AmountPerTrain

NEXT Count

O LEVEL COMPUTER SCIENCE Page 10


Pre Release Solution May June 2021 (Pseudocode)
Course Code 2210/22 Wajid

OUTPUT “Total number of passengers for the day is ”, TotalPassengers


OUTPUT “Total amount of money taken for the day is $”, TotalMoney

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)

O LEVEL COMPUTER SCIENCE Page 11

You might also like