(MT-L) PreRelease MJ 2021 VB Code

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

Computer Science 2210

PRE-RELEASE MATERIAL May/June 2021 O-level(2210)


with Majid Tahir

PRE-RELEASE MATERIAL 2210/22 MJ-2021


Your preparation for the examination should include attempting the following practical tasks by
writing and testing a program or programs.

An electric mountain railway makes four return trips every day. In each trip the train goes up the
mountain and back down. The train leaves from the foot of the mountain at 09:00, 11:00, 13:00
and 15:00. The train returns from the top of the mountain at 10:00, 12:00, 14:00 and 16:00.
Each train has six coaches with eighty seats available in each coach. Passengers can only
purchase a return ticket; all tickets must be purchased on the day of travel. The cost is $25 for
the journey up and $25 for the journey down. Groups of between ten and eighty passengers
inclusive get a free ticket for every tenth passenger, provided they all travel together (every
tenth passenger travels free). Passengers must book their return train journey, as well as the
departure train journey, when they purchase their ticket.
Passengers can return on the next train down the mountain or a later train. The last train from
the top of the mountain has two extra coaches on it.
The train times are displayed on a large screen, together with the number of tickets still
available for each train. Every time a ticket is booked the display is updated. When a train is full,
the word ‘Closed’ is displayed instead of the number of tickets available.
Write and test a program or programs for the electric mountain railway.

Your program or programs must include appropriate prompts for the entry of data; data
must be validated on entry.
Error messages and other output need to be set out clearly and understandably.
All variables, constants and other identifiers must have meaningful names.

You will need to complete these three tasks. Each task must be fully tested.

Task 1 – Start of the day.


Write a program to set up the screen display for the start of the day. Initialise suitable data
structure(s) to total passengers for each train journey and total the money taken for each train
journey. Each train journey must be totalled separately. There are four journeys up and four
journeys down every day.

Task 2 – Purchasing tickets.


Tickets can be purchased for a single passenger or a group. When making a purchase, check
that the number of tickets for the required train journeys up and down the mountain is available.
If the tickets are available, calculate the total price including any group discount. Update the
screen display and the data for the totals.

Task 3 – End of the day.


Display the number of passengers that travelled on each train journey and the total money
taken for each train journey. Calculate and display the total number of passengers and the total
amount of money taken for the day. Find and display the train journey with the most passengers
that day.

www.majidtahir.com Contact: 03004003666 Email: [email protected] 1


Computer Science 2210
PRE-RELEASE MATERIAL May/June 2021 O-level(2210)
with Majid Tahir

Pre Release solution Complete VB-Code


Sub Main()
'TASK 1

Console.WriteLine("PRE-RELEASE MJ2021 SOLUTION IN VB")


Const OneWayTicket = 25

Dim TrainTimeUp() As String = {"9:00", "11:00", "13:00", "15:00"}


Dim totalupseats() = {480, 480, 480, 480}
Dim occupiedUpseat() = {0, 0, 0, 0}
Dim UPtrainmoney() = {0, 0, 0, 0}

Dim TrainTimeDown() As String = {"10:00", "12:00", "14:00", "16:00"}


Dim totaldownseats() = {480, 480, 480, 640}
Dim occupiedDownseat() = {0, 0, 0, 0}
Dim DOWNtrainmoney() = {0, 0, 0, 0}
Dim MaxPassangerTrain() = {0, 0, 0, 0}
Dim choice As Boolean
Dim numofpassanger, UpTrip, DownTrip, cost, discountedCost As Integer
Dim TwoWayTickets As Integer

Dim totalpassangers, totalamount As Integer 'For TASK3

Console.WriteLine("Welcome to TRAIN JOURNEY Display Screen")


For count = 0 To 3
Console.WriteLine("Train Num: " & count & " Train Time Up : " &
TrainTimeUp(count) & " Total seats Up : " & totalupseats(count) & " Ocuupied Seats : " &
occupiedUpseat(count))
Console.WriteLine("UpTrain Money = " & UPtrainmoney(count))
Console.WriteLine("Train Num: " & count & " Train Time Down : " &
TrainTimeDown(count) & " Total seats Down : " & totaldownseats(count) & " Ocuupied Seats
: " & occupiedDownseat(count))
Console.WriteLine("DownTrain Money = " & DOWNtrainmoney(count))
Console.WriteLine("----------------------------------------")
Next

'Task 2
Console.WriteLine("Do you want to Buy Tickets? True for yes and False for no")
choice = Console.ReadLine()

While choice <> False

Console.WriteLine("Enter number of passangers for trip")


numofpassanger = Console.ReadLine()

totalpassangers = totalpassangers + numofpassanger

Console.WriteLine("Enter Train to Journey Up [0,1,2,3] ")


UpTrip = Console.ReadLine()
occupiedUpseat(UpTrip) = occupiedUpseat(UpTrip) + numofpassanger
totalupseats(UpTrip) = totalupseats(UpTrip) - numofpassanger

Console.WriteLine("Enter Train number to Journey DOWN [0,1,2,3] ")

www.majidtahir.com Contact: 03004003666 Email: [email protected] 2


Computer Science 2210
PRE-RELEASE MATERIAL May/June 2021 O-level(2210)
with Majid Tahir

DownTrip = Console.ReadLine()
occupiedDownseat(DownTrip) = occupiedDownseat(DownTrip) + numofpassanger
totaldownseats(DownTrip) = totaldownseats(DownTrip) - numofpassanger

cost = numofpassanger * OneWayTicket

discountedCost = cost - (OneWayTicket * (numofpassanger \ 10)) 'Integer


Division for discount of every 10th Passanger
TwoWayTickets = discountedCost * 2 'You have to buy ticket for UpTrip and
DownTRin
UPtrainmoney(UpTrip) = UPtrainmoney(UpTrip) + discountedCost
DOWNtrainmoney(DownTrip) = DOWNtrainmoney(DownTrip) + discountedCost

totalamount = totalamount + UPtrainmoney(UpTrip) + DOWNtrainmoney(DownTrip)


'For Task3
Console.Clear()

For count = 0 To 3
Console.WriteLine("Train Num: " & count & " Train Time Up:" & TrainTimeUp(count) & "
Total seats Up:" & totalupseats(count) & " Ocuupied Seats: " & occupiedUpseat(count))
Console.WriteLine("UpTrain Money = " & UPtrainmoney(count))
Console.WriteLine("Train Num: " & count & " Train Time Down:" & TrainTimeDown(count)
& " Total seats Down:" & totaldownseats(count) & " Ocuupied Seats: " &
occupiedDownseat(count))
Console.WriteLine("DownTrain Money = " & DOWNtrainmoney(count))

If totalupseats(count) = 0 Then
Console.WriteLine(TrainTimeUp(count) & " : Train is FULL : Booking CLOSED")
Else
Console.WriteLine(TrainTimeUp(count) & " : Seats available : Booking OPEN")
End If
Console.WriteLine("----------------------------------------")

If totaldownseats(count) = 0 Then
Console.WriteLine(TrainTimeDown(count) & " : Train is FULL : Booking CLOSED")
Else
Console.WriteLine(TrainTimeDown(count) & " : Seats available : Booking OPEN")
End If
Console.WriteLine("----------------------------------------")

Next
Console.WriteLine("Do you want to buy more Tickets? True for yes and False for no")
choice = Console.ReadLine()

End While

'Task 3
Dim Maxtrainup As String
Dim Maxtraindown As String
Console.Clear
Console.WriteLine(" ------ END OF THE DAY ----------")
For count = 0 To 3
If occupiedUpseat(count) > MaxPassangerTrain(count) Then
MaxPassangerTrain(count) = MaxPassangerTrain(count) +
occupiedUpseat(count)
Maxtrainup = TrainTimeUp(count)

www.majidtahir.com Contact: 03004003666 Email: [email protected] 3


Computer Science 2210
PRE-RELEASE MATERIAL May/June 2021 O-level(2210)
with Majid Tahir

ElseIf occupiedDownseat(count) > MaxPassangerTrain(count) Then


MaxPassangerTrain(count) = MaxPassangerTrain(count) +
occupiedDownseat(count)
Maxtraindown = TrainTimeDown(count)

End If

Console.WriteLine("----------------------------------------")
Console.WriteLine("Train Num: " & count & " Train Time Up:" &
TrainTimeUp(count) & " Total seats Up:" & totalupseats(count) & " Ocuupied Seats: " &
occupiedUpseat(count))
Console.WriteLine("UpTrain Money = " & UPtrainmoney(count))
Console.WriteLine("Train Num: " & count & " Train Time Down:" &
TrainTimeDown(count) & " Total seats Down:" & totaldownseats(count) & " Ocuupied Seats: "
& occupiedDownseat(count))
Console.WriteLine("DownTrain Money = " & DOWNtrainmoney(count))
Console.WriteLine("----------------------------------------")

Next
Console.WriteLine("Total Money Earned TODAY: " & totalamount)
Console.WriteLine("Total Passangers travelled TODAY: " & totalpassangers)
Console.WriteLine("Maxtrain Passanger train Upwards = " & Maxtrainup)
Console.WriteLine("Maxtrain Passanger train Downwards = " & Maxtraindown)
Console.ReadKey()
End Sub
End Module

www.majidtahir.com Contact: 03004003666 Email: [email protected] 4

You might also like