((e) Write an algorithm to calculate the cost of the tickets that the train traveller
wants to buy.
Part of the algorithm is to conduct a search of an array of records containing the
single full fare and return full fare for each destination. The search needs to
extract fare information for the destination station selected by the train traveller.
The structure of the array of records is:
A portion of the array of records is shown below.
Use the variable names:
UserDest to stand for the destination station selected by the
train traveller;
NumSingle to stand for the number of one-way tickets the
traveller wishes to purchase;
NumReturn to stand for the number of return tickets the traveller
wishes to purchase; and
TotalFare to stand for the total cost of all tickets purchased.
For this algorithm you may assume that:
there are 100 records in the array of records;
no concession, child or student fares are available;
the variables NumSingle and NumReturn could be zero. (If both variables were
zero then TotalFare would be zero.)
Scone
Singleton
Springwood
$23.80
$15.40
$ 5.20
$42.50
$28.40
$ 9.60
destination (index).fullreturn destination (index).fullsingle destination (index).station
This is copied straight from the pdf file for the 2002 hsc for sdd.....
Would anyone be kind enough to answer this question and/or analyse my answer as to whether its worth 5 marks or not?
My Answer (This was a pretty quick job):
[Edited to allow for indentation etc. - Laz]
wants to buy.
Part of the algorithm is to conduct a search of an array of records containing the
single full fare and return full fare for each destination. The search needs to
extract fare information for the destination station selected by the train traveller.
The structure of the array of records is:
A portion of the array of records is shown below.
Use the variable names:
UserDest to stand for the destination station selected by the
train traveller;
NumSingle to stand for the number of one-way tickets the
traveller wishes to purchase;
NumReturn to stand for the number of return tickets the traveller
wishes to purchase; and
TotalFare to stand for the total cost of all tickets purchased.
For this algorithm you may assume that:
there are 100 records in the array of records;
no concession, child or student fares are available;
the variables NumSingle and NumReturn could be zero. (If both variables were
zero then TotalFare would be zero.)
Scone
Singleton
Springwood
$23.80
$15.40
$ 5.20
$42.50
$28.40
$ 9.60
destination (index).fullreturn destination (index).fullsingle destination (index).station
This is copied straight from the pdf file for the 2002 hsc for sdd.....
Would anyone be kind enough to answer this question and/or analyse my answer as to whether its worth 5 marks or not?
My Answer (This was a pretty quick job):
Code:
BEGIN CalcTickets
index=0
Itemfound = false
WHILE UserDest <> destionation(index).station
index = index +1
UNTIL UserDest = destination(index.station OR index = 100
IF UserDest = destionation(index).station THEN
[NumSingle*destionation(index).fullsingle]+[NumReturn*destination(index).fullreturn]=TotalFare
ENDIF
ENDWHILE
END CalcTickets
Last edited: