You are on page 1of 15

1|Page Pre-Release Material (May/Jun17)

Pre-Release Material Tasks

The organizer of a senior citizens club arranges outings for the members. For each of these outings a
coach is hired, meals at a restaurant are reserved and tickets for the theatre are booked. A program is
required to work out the costs and provide a printed list showing everyone on the outing.

Write and test a program for the club manager.


Your program must include appropriate prompts for the entry of data.
Error messages and other output need to be set out clearly.
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 Work out the total cost of the outing

The organizer finds out how many senior citizens would be interested in the outing. The program for
TASK 1 works out the cost from this information.

Number of people Hire of coach ($) Cost of a meal ($) Cost of a theatre ticket ($)

12-16 150 14.00 21.00

17-26 190 13.50 20.00

27-39 225 13.00 19.00

The minimum number of senior citizens needed for the outing to go ahead is 10; there cannot be more
than 36 senior citizens on the outing. A minimum of two carers must go on the outing, with an
additional carer needed if more than 24 senior citizens go on the outing. Carers do not have to pay
anything for the outing. Work out the total cost and the cost per person for the senior citizens.

TASK 2 Record who is going on the outing and how much has been paid.

Using your results from TASK 1, record the names of the people on the outing and the amount they have
paid; include the carers on the outing. If there are spare places on the coach, then extra people can be
added; they are charged the same price as the other senior citizens. Calculate the total amount of
money collected. Print out a list of the people on the outing.

TASK 3 Identify the break-even point or profit that will be made on the outing

Show whether the outing has made a profit or has broken even using the estimated cost from TASK 1
and the money collected from TASK 2.
2|Page Pre-Release Material (May/Jun17)

Concept and Understanding of Tasks


All 3 tasks are a part of one big problem i.e. calculating the total cost of the outing and whether it has
made profit or not. The tasks are built incrementally and each task uses the code/algorithm of the
previous task. Hence the general flow and explanation of each task is provided separately in the
following diagram.

Task 1

Variables and constants declaration

Input the number of senior citizens going


on the outing

Validating user input (number of senior


citizens)

Calculate and output the total cost (from


the given table) and per person cost

Task 2

* It is assumed that Task1 has been completed.

Variables and constants declaration

Calculation of extra people that can be


accomodated in coach

Storing the names of all people (including carers)


going on the outing

Recalculate the total cost and output the names


of all people (including carers) that are going on
outing
3|Page Pre-Release Material (May/Jun17)

Task 3

* It is assumed that Task2 has been completed.

Variables declaration

Calculation of the difference of cost


calculated in Task 1 and Task 2

Output the message indicating if the


outing has made profit or broken even

* Broken even means that there is no profit and no loss.


4|Page Pre-Release Material (May/Jun17)

Approach to Solution
Like every other algorithm, there can be many approaches to solve these tasks depending upon the
understanding of person. We are listing down the key points that reflect our understanding and well
solve these tasks according to following assumptions.

In Task1, the cost of meal and theatre ticket are considered per person while the cost of coach is
considered accumulated.
In Task1, the total cost will be calculated by taking both senior citizens and carers into
consideration while per person cost will be divided among senior citizens only as listed in the
question (i.e. carers do not have to pay anything)
In Task2, a single array will be used to store the names of all people going on outing (i.e. both
senior citizens and carers)
In Task2, input of amount will not be taken because it has already been calculated in Task1 and
the question clearly says to use it from Task1. So it will be redundant to take it as an input
despite knowing that the cost per person is the same as Task1.

Color Codes
The pseudocode uses different colors to represent keywords for easier understanding. These color
codes are listed below.

Begin / End BLACK

Variable declaration and datatypes LIGHT BLUE

Selection statements (IF and CASE) RED

Input and Output GREEN

Loop (REPEAT-UNTIL) PURPLE

Strings/Text messages and variables BLACK

Loop (FOR-NEXT) PINK


5|Page Pre-Release Material (May/Jun17)

Explanation of Algorithm of Tasks


The explanation of the algorithms used in each task is listed below.

Task 1
In this task we take input the total number of senior citizens going on the outing. Validation will be
performed using REPEAT-UNTIL to check that the input lies between 10 and 36.
IF statement will be used to calculate the carers needed to go along with the senior citizens which will
give us the total people that are going on the outing.

The total cost will be calculated according to the table given in question (see diagram below for
explanation)

Hire of coach depends upon Cost of meal and ticket are per person
the number of people. It will basis; meaning if 13 people are going
be included only once for all then cost of both meal and ticket will be
people that are going multiplied by 13

Cost per person will be calculated by dividing the total cost among senior citizens only (since carers do
not pay anything so their cost will be bear by senior citizens.)

For example:

If 12 senior citizens are going on the outing, then they will be accompanied by 2 carers. The total cost
will be calculated according to the 1st row/block of table.

Total cost = 150 + 14 x (14.00 + 21.00)


Total cost = $ 640

However the cost per person will be calculated from the number of senior citizens only because carers
are not paying anything. So,

Per person cost = Total cost / 12


Per person cost = $ 53.33
6|Page Pre-Release Material (May/Jun17)

Task 2
In this task, well first calculate remaining seats in coach. Since the coach capacity (remaining seats)
depends upon the people that are going, this can be easily calculated by subtracting total people (from
Task1) by the maximum people that can be accommodated in the coach (given in table). This will be
done using IF statements.

An easy way to understand this is to assume that each row of the table corresponds to a different coach.

Coach 1

Coach 2

Coach 3

Thus is, if total people in Task 1 are 19 (including carers) then the remaining seats should be
26 19 = 7; because we know that only Coach 2 can accommodate greater than 17 people and its
maximum capacity is 26.

Once we get the count of remaining seats in coach, we will then take input the number of extra people
that can be included in outing and validate it using REPEAT-UNTIL loop. (An important thing to
remember is that these extra people will always be the senior citizens and not the carers because we
already calculated the carers in Task 1 and they will not change even when we add extra senior citizens)

A recalculation of total people is also needed because extra people may be added from the above step.
At the end we will use a FOR loop to fill the array with the names of people going on the outing and
calculate the total cost by simply multiplying the newly calculated total people by per person cost (from
Task 1)

Task 3
In this task we will calculate the difference of cost from Task1 and Task 2. If the difference is greater
than 0 then a message of Profit (or any other appropriate message) should be printed otherwise
Broken even should be printed.
7|Page Pre-Release Material (May/Jun17)

Task 1 Solution (Pseudocode)


BEGIN
SET scitizen 0, allpeople 0 AS INETGER
SET totalcost 0.0, personcost 0.0 AS FLOAT
CONST mincitizen 10, maxcitizen 36, mincarer 2, maxcarer 3 AS INTEGER

REPEAT
PRINT Enter the senior citizens going on outing?
INPUT scitizen
IF scitizen < mincitizen THEN
PRINT At least 10 senior citizens should go on outing
ELSE IF scitizen > maxcitizen THEN
PRINT Maximum of 36 senior citizens can go on outing
END IF
UNTIL scitizen >= 10 AND scitizen <= 36 Efficiency of Algorithm

IF scitizen <= 24 THEN Use of CONSTANTS to hold fixed


allpeople scitizen + mincarer values.
ELSE Uses IF statement to print
allpeople scitizen + maxcarer appropriate error message when
END IF validation fails
Uses REPEAT statement to
IF allpeople >= 12 AND allpeople <= 16 THEN validate senior citizens
totalcost 150 + allpeople * (14.00 + 21.00) Uses IF statement to calculate
ELSE IF allpeople >= 17 AND allpeople <= 26 THEN total cost according to given table
totalcost 190 + allpeople * (13.50 + 20.00) in question.
ELSE IF allpeople >= 27 AND allpeople <= 39 THEN Output of total cost and per
totalcost 225 + allpeople * (13.00 + 19.00) person cost with suitable
END IF message.

personcost totalcost / scitizen


PRINT The total cost of outing is : , totalcost
PRINT Cost per person is : , personcost
END
8|Page Pre-Release Material (May/Jun17)

Pseudocode Explanation of Task 1

Variables and constants declaration.

Validation using REPEAT


loop. It will force user to
input senior citizens
between 10 and 26

IF statement to
print appropriate
error message

Calculation of the total


people going on outing by
adding carers

Calculation of total cost


by adding coach, meal
and ticket cost from the
table given in question.

Calculation of per person cost


9|Page Pre-Release Material (May/Jun17)

Task 2 Solution (Pseudocode)


* variables from Task 1 has been underlined for easier readability

BEGIN
SET peoplename[1:39] AS STRING
SET extracitizen 0, remseats 0, count 0 AS INTEGER Efficiency of Algorithm
SET finalcost 0.0 AS FLOAT
Use of Array to store people
IF allpeople >= 12 AND allpeople <= 16 THEN name.
remseats 16 allpeople Uses REPEAT loop to validate
ELSE IF allpeople >= 17 AND allpeople <= 26 THEN extra citizens
remseats 26 allpeople Use of FOR loop to input and
ELSE print people names in array.
remseats 39 allpeople Recalculation of total cost
END IF including extra people.

REPEAT
PRINT Number of remaining seats on coach are, remseats
PRINT Enter the number of additional senior citizens going
INPUT extracitizen
IF extracitizen > remseats THEN
PRINT Not enough space to accommodate this many people
END IF
UNTIL extracitizens >= 0 AND extacitizen <= remseats

allpeople allpeople + extracitizen

FOR count 1 TO allpeople


peoplename[count]
PRINT Enter the name of person on outing
INPUT peoplename[count]
NEXT count

FOR count 1 TO allpeople


PRINT Name of person , peoplename[count]
NEXT count

finalcost totalcost + ( extracitizen * personcost )


PRINT The total cost for outing is, finalcost
END
10 | P a g e Pre-Release Material (May/Jun17)

Pseudocode Explanation of Task 2

* variables from Task 1 has been underlined for easier readability

Variables and array


declaration. Few variables
from Task 1 will be reused.

Calculation of remaining seats in coach.


IF statement is used to check which
data from the table is to be applied for
the calculation of remaining seats.

Validation of extra
people. It should be
greater or equal to
0 and less than or
equal to remaining
seats

Reusing and updating allpeople


variable from Task 1. It will now contain
all people plus extra citizens

Initializing and storing people names in


array. FOR loop will run as many times as
there are people on outing. (calculated
above)

Separate FOR loop for printing people


names. This step is done separately
just because of clarification. It can be
combined with the above loop

Recalculation of total cost by adding


cost calculated in Task 1 with the cost
of extra citizens.
11 | P a g e Pre-Release Material (May/Jun17)

Task 3 Solution (Pseudocode)


* variables from Task 1 & 2 has been underlined for easier readability

BEGIN
SET difference 0.0 AS FLOAT
Efficiency of Algorithm
difference finalcost totalcost
IF difference > 0 THEN Use of variables from Task 1 &
PRINT The outing has made a profit
Task 2 for the calculation of
ELSE
difference.
PRINT The outing has broken even
Use of IF statement to identify
END IF
END the profit or broke even.
12 | P a g e Pre-Release Material (May/Jun17)

Pseudocode Explanation of Task 3

* variables from Task 1 & 2 has been underlined for easier readability

Variable for storing difference

IF statement to identify whether the


outing has made a profit or not.
13 | P a g e Pre-Release Material (May/Jun17)

Combined Pseudocode Solution of all Tasks


BEGIN
SET scitizen 0, allpeople 0, extracitizen 0, remseats 0, count 0 AS INETGER
SET totalcost 0.0, personcost 0.0, finalcost 0.0 AS FLOAT
CONST mincitizen 10, maxcitizen 36, mincarer 2, maxcarer 3 AS INTEGER
SET peoplename[1:39] AS STRING

REPEAT
PRINT Enter the senior citizens going on outing?
INPUT scitizen
IF scitizen < mincitizen THEN
PRINT At least 10 senior citizens should go on outing
ELSE IF scitizen > maxcitizen THEN
PRINT Maximum of 36 senior citizens can go on outing
END IF
UNTIL scitizen >= 10 AND scitizen <= 36

IF scitizen <= 24 THEN


allpeople scitizen + mincarer
ELSE
allpeople scitizen + maxcarer
END IF

IF allpeople >= 12 AND allpeople <= 16 THEN


totalcost 150 + allpeople * (14.00 + 21.00)
ELSE IF allpeople >= 17 AND allpeople <= 26 THEN
totalcost 190 + allpeople * (13.50 + 20.00)
ELSE IF allpeople >= 27 AND allpeople <= 39 THEN
totalcost 225 + allpeople * (13.00 + 19.00)
END IF

personcost totalcost / scitizen


PRINT The total cost of outing is : , totalcost
PRINT Cost per person is : , personcost

IF allpeople >= 12 AND allpeople <= 16 THEN


remseats 16 allpeople
ELSE IF allpeople >= 17 AND allpeople <= 26 THEN
remseats 26 allpeople
ELSE
remseats 39 allpeople
END IF
14 | P a g e Pre-Release Material (May/Jun17)

REPEAT
PRINT Number of remaining seats on coach are, remseats
PRINT Enter the number of additional senior citizens going
INPUT extracitizen
IF extracitizen > remseats THEN
PRINT Not enough space to accommodate this many people
END IF
UNTIL extracitizens >= 0 AND extacitizen <= remseats

allpeople allpeople + extracitizen

FOR count 1 TO allpeople


peoplename[count]
PRINT Enter the name of person on outing
INPUT peoplename[count]
NEXT count

FOR count 1 TO allpeople


PRINT Name of person , peoplename[count]
NEXT count

finalcost totalcost + ( extracitizen * personcost )


PRINT The total cost for outing is, finalcost

difference finalcost totalcost


IF difference > 0 THEN
PRINT The outing has made a profit
ELSE
PRINT The outing has broken even
END IF
END
15 | P a g e Pre-Release Material (May/Jun17)

Practice Questions
1. When you performed the tasks, you used variables. Write suitable declarations for two of these.
State what you used each one for.
2. When you performed the tasks, you may have used constants. Write suitable declarations for two of
these. State what you used each one for.
3. Write an algorithm to complete Task 1, using either pseudocode, programming statements or a
flowchart.
4. Write an algorithm to complete Task 2, using either pseudocode, programming statements or a
flowchart.
5. Write an algorithm to complete Task 3, using either pseudocode, programming statements or a
flowchart. You should assume that Task 1 & Task2 has been already completed.
6. Explain how you performed validation of senior citizens input in Task 1. You can include pseudocode
or programming statements as part of your explanation.
7. Explain how you calculated total cost of the outing in Task 1. You can include pseudocode or
programming statements as part of your explanation.
8. In Task 2, explain how you calculated the remaining seats in the coach. You can include pseudocode
or programming statements as part of your explanation.
9. Explain how you completed Task 3. You should assume that Task 2 has been completed. You can
include pseudocode or programming statements as part of your explanation.
10. Comment on the efficiency of your design for Task 1.
11. Comment on the efficiency of your design for Task 2.
12. Comment on the efficiency of your design for Task 3.
13. Give a set of extra citizen data that could be used to check your validation rules in Task 2. Explain
why you chose this data set.

You might also like