Task 1 Complete-1
Task 1 Complete-1
Storing the details for train times going up/down and train tickets
available for journey up/down using arrays
Page XX
Pre-Release May/June 2021
• Write a program to set up the screen display for the start of the day.
We will make use of 1D arrays to store the information relating to train timings, tickets, passengers and
money for all 8 train journeys.
For setting up the complete screen display, we’ll make use of additional pieces of information given in the
pre-release as well. This includes the following details:
• The train times are displayed on a large screen, together with the number of tickets still available
for each train.
Since we need to display the number of tickets as well, we should also calculate the seats available in each
train:
• Each train has six coaches with eighty seats available in each coach.
• The last train from the top of the mountain has two extra coaches on it.
The train timings and tickets for trains going up will be stored in the table for all 4 journeys like this:
1 coach = 80 seats
6 coaches = 80 x 6
6 coaches = 480 seats
Timings for trains Number of tickets
going up available for trains
going up
Page XX
Pre-Release May/June 2021
The train timings and tickets for trains going down will be stored in the table for all 4 journeys like this:
1 coach = 80 seats
2 coaches = 80 x 2
2 coaches = 160 seats
Page XX
Pre-Release May/June 2021
The screen display involves output of train timings and train tickets available. Therefore it will be
displayed/output using a FOR loop.
Firstly we will output the details for trains going up using a FOR loop like this:
Page XX
Pre-Release May/June 2021
Secondly we will output the details for trains going down using a FOR loop like this:
In this way, the timings and tickets of 4 trains going up and 4 trains coming back down will be taken
from their locations in the arrays (after being searched according to index value) and PRINTED/OUTPUT
separately.
Page XX
Pre-Release May/June 2021
To set up the actual display, we will output both the train timings and tickets available in a single line
unlike writing both outputs in separate lines like demonstrated above. Therefore the slight change in the
code would be:
Using the pieces of code given above, the display will be setup. It will look something like the following
example of display:
Screen display:
The following is a table of the train times and number of train tickets available:
The train departure times and tickets available for four journeys going up are:
Page XX
Pre-Release May/June 2021
• initialise suitable data structure(s) to total passengers for each train journey and total the money
taken for each train journey.
We will declare and initialise two arrays for passengers so that the number of every passenger can be
totalled and stored in 2 different arrays. 1 array for the passengers seated in trains going up and another
1 array for the passengers seated in trains going back down.
Similarly, we will declare and initialise two arrays for money earned so that the amount of money can be
totalled and stored in 2 different arrays. 1 array for the money earned from trains going up and another 1
array for the money earned from trains going back down.
• there are four journeys up and four journeys down every day.
In this manner, the money earned for each train journey going up will be stored in the array money_up in
the respective index value of that train (i.e. 1, 2, 3 or 4).
Similarly the money earned for each train journey going back down will be stored in the array
money_down in the respective index value of that train (i.e. 1, 2, 3 or 4).
As a result, all 8 journeys (4 going up and 4 coming back down) will be totalled and stored separately.
Page XX
Pre-Release May/June 2021
TASK 1 – Pseudocode:
BEGIN
DECLARE count 0 AS INTEGER
DECLARE time_up [1:4], time_down [1:4] AS INTEGER
DECLARE tickets_up [1:4], tickets_down [1:4] AS INTEGER
DECLARE passengers_up [1:4], passengers_down [1:4] AS INTEGER
DECLARE money_up [1:4], money_down [1:4] AS FLOAT
time_up[1] 0900
time_up[2] 1100
time_up[3] 1300
time_up[4] 1500
time_down[1] 1000
time_down[2] 1200
time_down[3] 1400
time_down[4] 1600
tickets_up[1] 480
tickets_up[2] 480
tickets_up[3] 480
tickets_up[4] 480
tickets_down[1] 480
tickets_down[2] 480
tickets_down[3] 480
tickets_down[4] 640
money_up[1] 0.0
money_up[2] 0.0
money_up[3] 0.0
money_up[4] 0.0
money_down[1] 0.0
money_down[2] 0.0
money_down[3] 0.0
money_down[4] 0.0
passengers_up[1] 0
passengers_up[2] 0
passengers_up[3] 0
passengers_up[4] 0
passengers_down[1] 0
passengers_down[2] 0
passengers_down[3] 0
passengers_down[4] 0
Page XX
Pre-Release May/June 2021
PRINT “The train departure times and tickets available for four journeys going up are:”
FOR count 1 TO 4
PRINT “Time: ”, time_up[count], “Tickets available: ”, tickets_up[count]
NEXT count
PRINT “The train departure times and tickets available for four journeys coming down are:”
FOR count 1 TO 4
PRINT “Time: ”, time_down[count], “Tickets available: ”, tickets_down[count]
NEXT count
END
TASK 1 – Efficiency:
• Use of ARRAYS to store train timings and number of train tickets available.
• Use of different ARRAYS to store and total the number of passengers and
money earned separately for each train journey.
• Initialization of all ARRAYS with pre-defined values.
• Use of FOR loops to output details of trains departure and arrival.
Page XX
Pre-Release May/June 2021
Page XX
Pre-Release May/June 2021
Page XX
Pre-Release May/June 2021
Page XX