User interface language: English | Español

Date May 2018 Marks available 4 Reference code 18M.1.HL.TZ0.15
Level HL Paper 1 Time zone no time zone
Command term Construct Question number 15 Adapted from N/A

Question

A transport authority is investigating how many people use a certain direct train route.

At the end of each day, the total number of passengers who travelled on this route is stored in a collection, PASSENGERS.

The first item was written to the collection on Monday 1st May 2017.

The next items, collected on Tuesday and Wednesday, were added like this:

Data for 30 complete weeks was added to the collection.

Construct pseudocode that will read PASSENGERS into the two-dimensional array, 2D_ARRAY.

[4]
a.

Construct the pseudocode for the procedure total, that takes as input a column number of this two-dimensional array and returns the sum of the elements in that column.

[4]
b.

The transport authority wishes to know how many passengers, on average, travel on each day of the week.

Using the procedure total construct the pseudocode to output the day of the week with the highest average number of passengers, and the value of this average.

You should make use of the sub procedure convert() which converts the numbers 0 to 6 into days of the week, for example convert(1) will return “Tuesday”.

[3]
c.

The transport authority stores details about the ticket prices in a one-dimensional array, FEES, where FEES[0] contains the price of a ticket for Monday to Friday, while FEES[1] contains the price of a ticket for Saturday and Sunday.

The procedure salesCalculate() takes as input the column and row indices that define two specific days during the 30 weeks, and outputs the total amount of money generated from ticket sales between those two days (inclusive).

Construct, in pseudocode, the procedure salesCalculate().

[7]
d.

Markscheme

Award [4] as follows.

Example answer 1:
Assumes that an array of sufficient size is declared (2D_ARRAY[][]) and PASSENGERS contains valid data for all 7 days in each of 30 weeks.

PASSENGERS.resetNext()
N = 0
loop while PASSENGERS.hasNext()
//accept not PASSENGERS.isEMPTY()
//accept N<PASSENGERS.length()
WEEK = N div 7
DAY = N mod 7
2D_ARRAY[WEEK][DAY] = PASSENGERS.getData() // PASSENGERS.getNext()
N=N+1
end loop

Award [1] for while loop.
Award [1] for correct calculation of row index(WEEK).
Award [1] for correct calculation of column index(DAY).
Award [1] for correct array subscripts.
Award [1] for correct use of collection methods.

Example answer 2:
Assumes that an array of a sufficient size is declared (2D_ARRAY[][]) and PASSENGERS contain valid data for all 7 days in each of 30 weeks.

PASSENGERS.resetNext()
loop for WEEK from 0 to 29
   loop for DAY from 0 to 6
2D_ARRAY[WEEK][DAY] = PASSENGERS.getNext()//PASSENGERS.getData()
end loop
end loop

Award [1] for nested loops.
Award [1] for loops that generate the right output (correctly read PASSENGERS into 2D_ARRAY).
Award [1] for assignment into correct array location.
Award [1] for correct use of collection methods.

a.
total (N)
// if N (column number) is not passed as an input parameter then
// assignment must appear in pseudocode, for example, N = input()
SUM = 0
loop for WEEK from 0 to 29
SUM = SUM + 2D_ARRAY[WEEK][N]
end loop
return SUM
end total

Award [1] for assigning the input to a variable / passing the value of N.
Award [1] for initializing and returning/outputting SUM.
Award [1] for correct loop.
Award [1] for correct addition of each term to SUM. (Note: The array position must be completely correct with the input column and the varied row.)

b.
MAXAV = 0
MAXDAY = ""
loop for DAY from 0 to 6
if total(DAY)/30 > MAXAV
MAXAV = total(DAY)/30
MAXDAY = convert(DAY)
end if
end loop
output MAXAV,MAXDAY

Award [1] for correct loop.
Award [1] for use of method total() when calculating the average number of passengers.
Award [1] for initializing, updating and outputting/returning MAXAV and MAXDAY.

c.
salesCalculate(2D_ARRAY, A, B, X, Y)
// A,B are row & column of first day,
// X,Y are row & column of last day.

TOTAL = 0

loop for COL= B to 6
if COL < 5 then
TOTAL = TOTAL + 2D_ARRAY[A][COL] * FEES[0]
else
TOTAL = TOTAL + 2D_ARRAY[A][COL] * FEES[1]
end if
end loop
//calculates total for week A,
//days are in the range from B to 6
//weekdays are days 0-4, and weekend 5,6

loop for ROW = A + 1 to X - 1
loop for COL= 0 to 6
if COL < 5 then
TOTAL = TOTAL + 2D_ARRAY[ROW][COL]*FEES[0]
else
TOTAL = TOTAL + 2D_ARRAY[ROW][COL]*FEES[1]
end if
end loop
end loop
//calculates total for all weeks from A+1 to X-1,
//days are in the range from 0 to 6

loop for COL= 0 to Y
if COL < 5 then
TOTAL = TOTAL + 2D_ARRAY[X][COL]*FEES[0]
else
TOTAL = TOTAL + 2D_ARRAY[X][COL]*FEES[1]
end if
end loop
//calculates total for week X,
//days are in the range from 0 to Y

output TOTAL
end salesCalculate

Award [7 max].
Award [1] for initializing, updating and outputting TOTAL.
Award [1] for nested loops.
Award [1] for correct calculation of TOTAL in row/week A (column subscripts/days/ in 2D_ARRAY must be in range B to 6).
Award [1] for correct calculation of TOTAL in row/week X (column subscripts/days/ in 2D_ARRAY must be in range 0 to Y).
Award [1] for correct calculation of TOTAL in rows/weeks from A + 1 to X – 1 (column subscripts/days/ in 2D_ARRAY must be in range 0 to 6).
Award [1] if evident that the number of days to be included in calculating total amount is different for weeks A + 1 to X – 1, week A and X (three different cases).
Award [2], [1] for checking for weekdays / weekend and [1] for using correct subscript in FEE (0 for weekdays, 1 for weekend).

d.

Examiners report

[N/A]
a.
[N/A]
b.
[N/A]
c.
[N/A]
d.

Syllabus sections

Topic 5: Abstract data structures » 5.1 Abstract data structures
Show 80 related questions
Topic 5: Abstract data structures

View options