User interface language: English | Español

Date November 2021 Marks available 4 Reference code 21N.1.SL.TZ0.11
Level SL Paper 1 Time zone no time zone
Command term Construct Question number 11 Adapted from N/A

Question

A bus company provides services within a city. The basic fare depends on the travel distance between the departure station and the destination station.

The cost per kilometre is € 0.20.

Children under the age of 5 can travel for free.

Children between the ages of 5 and 15 inclusive can travel with a child age ticket, which gives a 50 % discount off the kilometre fare.

The senior discount (age 65+) offers 30 % off the kilometre fare.

The sub-program costperkm(AGE) accepts an integer AGE (the age of a passenger), then calculates and returns the cost per kilometre.

For example,

costperkm(10) returns 0.1,
costperkm(20) returns 0.2,
costperkm(80) returns 0.14

Passengers can find the distance between any two bus stations.

Figure 1 shows the one-dimensional array NAMES. It is used to store the names of all bus stations on the route from Oppox to Dovely.

Figure 2 shows the one-dimensional array DISTANCES. It is used to store the distances (in kilometres) on the route from Oppox to Dovely.

DISTANCES[K] holds the distance between the bus stations NAMES[K-1] and NAMES[K].

For example, the distance between Kronos (NAMES[7]) and Longlines (NAMES[8]) is 1.2 km and can be found in DISTANCES[8].

The sub-program calcdistance(P1,P2) accepts the indexes of the names of two bus stations in the array NAMES, where index P1 is always less than index P2, and returns the distance between them.

Construct an algorithm in pseudocode for the sub-program costperkm(AGE).

[4]
a.

State the distance between Kiko and Endsley.

[1]
b.

State the distance between Oppox and Brinkley.

[1]
c.

Describe how the distance between the two bus stations can be calculated in this sub‑program.

[3]
d.

An algorithm is needed that inputs the names of the two bus stations and the age of the passenger. It then calculates and outputs the price of a ticket.

If any of the inputted names are not found, the algorithm outputs an appropriate message. Figure 3 shows three examples of inputs and outputs.

Figure 3: Three examples of inputs and outputs from the algorithm

Construct an algorithm as described. You should call sub-programs costperkm() and calcdistance() in your algorithm.

[6]
e.

Markscheme

Award [4 max] 

Award [1] mark for correct condition (in if statement) and correct calculation of the cost per km for each type of tickets, x4.

Example 1:

costperkm(AGE)
if AGE<5
then COST=0.0
else
if AGE<=15
then COST=0.20*0.50 // COST=0.20*50/100
else
if AGE<65 //accept AGE<=65
then COST=0.20
else COST=0.20*0.70 // COST=0.20*70/100
endif
endif
endif
return COST
end costperkm

Example 2:

costperkm(AGE)
if AGE<5
then COST=0.0
endif
if AGE>=5 and AGE<=15
then COST=0.20*0.50 // COST=0.20*50/100
endif
if AGE>=15 and AGE<65
//accept AGE>=15 and AGE<=65
then COST=0.20
endif
if AGE>=65
//if condition in the previous if statement is
//AGE>=15 and AGE<=65, then this condition
//should be AGE>65
then COST=0.20*0.70 // COST=0.20*(100-30)/100
endif
return COST
end costperkm

Note: The method heading and the return statement may not appear in the candidates’ responses.

a.

Award [1 max] 
1.3;

b.

Award [1 max] 
1.2 + 1.0 or 2.2;

c.

Award [3] 
The sum of elements;
in the array DISTANCES from P1+1;
to P2;

d.

Award [6 max]
Award [1] for all variables correctly declared and initialized;
Award [1] for any correct loop through the array NAMES;
Award [1] for to determine positions of both names in the array;
Award [1] for outputting a message if one or other not present;
Award [1] for comparison of positions to find smallest/largest;
Award [1] for correct calculation and output of the price;
Award [1] for correct invocation of methods calcdistance() and costperkm()

Example 1:

NAME1=input()
NAME2=input()
AGE= input()
POS1=-1
POS2=-1
K=0
loop while K<=9 and (POS1==-1 or POS2==-1)
if NAMES[K].equals(NAME1) //accept '==' instead of equals()
then POS1=K
end if
if NAMES[K].equals(NAME2)
then POS2=K
end if
K=K+1
end loop
if POS1==-1 OR POS2==-1
then
output('stations are not found')
else
if POS1 > POS2
then
output( calcdistance(POS2,POS1)* costperkm(AGE))
else
output( calcdistance(POS1,POS2)* costperkm(AGE))
end if
end if

Example 2:

ST1=input()
ST2=input()
AGE= input()
PS1=-1
PS2=-1
loop K from 0 to 9
if NAMES[K].equals(ST1) //accept '==' instead of equals()
then PS1=K
end if
if NAMES [K].equals(ST2)
then PS2=K
end if
end loop


if PS1!=-1 AND PS2!=-1
then
if PS1 < PS2
then T=PS1
PS1=PS2
PS2=T
end if
PRICE= calcdistance(POS1,POS2)* costperkm(AGE)
output(PRICE)
else
output('stations not found')
end if

Example 3:

Note: Award marks for the algorithm written in Java/Python/Javascript/any other programming language. The following example is the solution written in Javascript.

function findStation(station)
{ var found = false;
var i = 0;
do
{ found = (ROUTE_X_NAMES[i] == station);
if (!found) i = i + 1;
} while (!found && i < 10);
if (found) return i;
else
{ output("No such bus station as "+station);
return -1;
}
}

var station1 = input();
var P1 = findStation(station1);
var station2 = input();
var P2 = findStation(station2);
var AGE = input();
if (P1 >= 0 && P2 >=0)
{ if (P1 < P2)
output("Cost = "+costperkm(AGE)*calcdist(P1, P2));
else
output("Cost = "+costperkm(AGE)*calcdist(P2, P1));
}
e.

Examiners report

Most candidates were able to work out the conditional statements required to construct the algorithm for the sub-program in the question. However, some marks were lost due to errors related to the operation of the sub-program, such as, answers that were simply output rather than in a return statement would not work, or calculations or values that were enclosed within quotation marks would simply be output as strings and would not work as required in the algorithm.

a.

The vast majority of candidates gave the correct answer to this question.

b.

The vast majority of candidates gave the correct answer to this question.

c.

The vast majority of candidates were able to achieve some marks by describing how the distance between two bus stations could be calculated within the given sub-program. Many candidates gave a fully correct explanation and achieved all three marks.

d.

Candidates were required to construct an algorithm that involved the other sub-programs used in earlier parts of this question. Some very good full mark answers were seen, with most candidates scoring some marks here.

e.

View options