Lesson video

In progress...

Loading...

Hello, I'm Dr.

Thas.

Welcome to Computing.

I'm so pleased that you have decided to join me for this lesson today.

In today's lesson, we will be covering a Programming Project: Subroutines Part I.

Welcome to today's lesson from the unit Programming Subroutines.

This lesson is called Programming Project: Subroutines Part I.

By the end of this lesson, you should be able to use a project brief to design a solution.

Some of the keywords that we will be using in today's lesson include structure chart.

Structure chart, a top-down diagram used to design the structure of the subroutines required for completing a programme.

Flow chart.

Flow chart, a visual representation of an algorithm or programme.

Today's lesson is divided into two sections.

The first section looks at investigating a project brief.

The second section looks at representing a system using a flow chart.

Let's start by looking at the first section where we will see how to investigate a project brief.

Copington Adventure Theme Park has just purchased an automated ticketing system and would like you to programme the interface for the customers to use.

The ticketing system should ask the customer various questions about their visit requirements before it provides a total charge, asks for payment, and issues a ticket.

The ticket prices for Copington Adventure Theme Park are detailed in the table below.

An adult ticket costs 20 pounds, a child's ticket costs 12 pounds, and a senior citizen's ticket costs 11 pounds.

Visitors also have the option to buy a wristband for 20 pounds, which will give them priority access to rides.

Parking is free, but a car pass must be displayed.

The project brief specifies the programme should do the following: provide a welcome message, display the entrance ticket prices, ask the user how many adult tickets are required, ask the user how many children tickets are required, ask the user how many senior citizen tickets are required, ask the user how many wristbands are required, ask for the lead booker's surname for the ticket, ask if they require a pass for the car park, display the total cost, ask for payment.

They should come up with the message that the machine only accepts 10 pound and 20 pound notes.

Each note entered will need to be counted.

Display change if any.

Print a ticket displaying the lead booker's surname, tickets purchased, wristbands purchased, and today's date.

Print a car parking pass if requested.

Use data validation techniques to avoid runtime errors through incorrect data entry, and finally, thank the user for their purchase.

An output from the programme may look similar to this image that's shown here, so the text output from the programme starts by welcoming the user to Copington Adventure Theme Park.

Then it displays the entrance prices.

The first question, the first input from the user is how many adult tickets they require.

Once the user enters that, then the programme asks how many children tickets are required.

After the users entered that information, the programme asks how many senior citizen tickets are required.

The user enters that information and then the programme asks how many wristbands are required.

Once the user enters that information, the programme asks for the lead booker's surname.

Once the the user enters that information, the programme finally asks whether the user requires a car parking pass.

The option in this case is given as yes or no, y or n.

Once the user enters their option, the the total cost of the tickets purchased is displayed.

Then it asks the user to enter the amount paid with the message displayed that the machine only accepts 10 pound and 20 pound notes.

Once the users entered how much money they have paid, the change due, if there is any change, is then displayed.

Finally, the ticket information with all the details that the user has entered: today's date, the lead booker's surname, number of adult tickets, number of children tickets, number of senior citizen tickets, wristbands is displayed, and then the car parking pass with the date and with the information that they should be displayed clearly in the vehicle is printed.

And then finally the programme thanks the user for their purchase.

Right, let's do a quick check.

Which of the following is not a requirement of the theme park booking system? You have been given three options.

Why don't you pause the video here and have a think? Did you say option C, calculate the discount for annual members? You were right.

Using a structured approach means breaking down a problem into smaller subroutines.

A structure chart is created to decide the hierarchy for the programme.

The programme has multiple requirements and will need to be broken down into smaller subroutines.

We call the main programme the ticket booking system and it will have these different offshoots, which are the different subroutines that you need to create.

One of the subroutines could be display ticket prices within the subroutine, the identifier, the subroutine's identifier could be display_prices.

It doesn't take any parameters.

It doesn't have any return values.

Right, let's do another quick check.

You've been doing so well.

If a subroutine needs to pass a value back to the main programme, what should you use? You have been given three options.

Why don't you pause the video here and have a quick think? Well done.

A is the right option.

What the subroutine will return is a return value.

Right, this brings us to the end of the first section.

Let's see if you have understood what we've covered in this section by doing a task.

Task A has two parts.

The first part asks you to plan out the remaining subroutines for the ticket booking system.

Remember, we looked at an example subroutine that display ticket prices in a previous slide.

Note, you may need to add more subroutines to your structure chart.

The second part asks you to add the details for the interface for each subroutine.

As we did as you saw in the slide, the display ticket prices subroutine, the identifier was display_prices.

It did not take any parameters, did not return any values.

Similarly, think about what the other subroutines could be and what their identifiers, the parameters they use, and the return values they return.

Could pause the video here, have a think.

I am sure you'll be able to come up with the solutions.

Let's look at what the possible solutions could be.

So for the first question where it asks you to plan out the remaining subroutines for the ticket booking system, what you could have is the calculate entrance price as a subroutine, car parking, collect payment, and issue ticket.

Remember, this is just a sample solution.

You may have divided the problem into different subroutines, and that is absolutely fine.

For the second part, if we carry on working with the subroutines from the sample solution, as we saw earlier, the display ticket prices subroutine will have the identifier display_prices.

No parameters are required for this subroutine and no return value given back to the main programme.

For the calculate entrance price subroutine, the identifier could be calculate_entrance.

Parameters could be the booking name, total number of adults, total number of children, total number of senior citizens, total number of wrist bands required.

The return value will be the total cost.

For the car parking subroutine, the identifier could be parking.

The parameters, well, this particular subroutine doesn't take any parameters.

The return value would be parking_required.

For the collect payment subroutine, the identifier could be collect_payment.

The parameters it will take is the total cost.

The return value, the subroutine does not return anything back to the main programme.

Finally, the issue ticket subroutine could have the identifier issue_ticket.

Parameters that it would take would be booking name, the total number of adults, the total number of children, the total number of senior citizens, the total number of wristbands, the total cost, and if the parking is required.

The return value would be nothing.

It will not return anything back to the main programme.

Well done on attempting this task, I'm sure you were able to work it out.

This brings us to the next section of the lesson where you will look at representing a system using a flow chart.

A flow chart is a diagram used to illustrate the steps of an algorithm.

Flow charts are made up of symbols, each containing a single step of the algorithm.

The shape of the symbol represents the type of process that the symbol contains.

Arrows are used to show the flow of execution.

When investigating the requirements of a system, it is useful to plan the programme flow using a flow chart.

The various flow chart symbols are shown here.

You start off with terminal, an almost oval block.

Then an arrow represents a flow line.

A rectangle represents a process, so, for example, if you were calculating something.

A rhombus is for a decision.

So if you were in your programme trying to decide what to do when a condition is true, for example.

A parallelogram would denote an input/output statement, so your print statements would go here.

Finally, a rectangle with partitions, unequal partitions on both sides will represent a subroutine.

Right, before we move on, a quick check.

Which flow chart symbol is used to represent decision? Why don't you pause the video here and have a quick think? Did you come up with option A? You were right.

Sam has created a flow chart for the first part of the theme park booking system.

What is display_prices in Sam's flow chart? Why don't you pause the video here and have a quick think? I'm sure you know the answer.

Well done, it is a subroutine.

The display_prices subroutine can be represented in its own flow chart, which might look something like the diagram shown here.

So within the display_prices subroutine, you will have a few messages.

So the first message would be entrance prices, then you print what the adult ticket cost is, which is 20 pounds.

Then you print child ticket cost, which is 12 pounds.

Then it's the senior citizen ticket cost, which is 11 pounds.

And you could carry on by printing the wristband ticket price, which is 20 pounds.

This brings us to the end of this section.

Let's just recap whatever you have learned in this section by attempting this task.

So Task B has one part, and it is asking you to create a flow chart to represent the whole theme park ticket booking system using the project brief to help you.

Remember, you split the project into subroutines in Task A, so you can create smaller flow charts to represent each subroutine.

Pause the video here, have a think and try and work this out.

I'm sure you'll be able to.

Well done on attempting this task.

Our adventure theme park ticket booking system could look something like this.

So you start the programme, then you print the message, "Welcome to Copington Adventure Theme Park." Then the display_prices subroutine is called, followed by the calculate_entrance subroutine, followed by the collect_payment subroutine, and finally, the issue_ticket subroutine.

The calculate_entrance subroutine would have further.

So if you create a flow chart for the calculate_entrance subroutine, it could look like you start by calculating the adult total where adult tickets multiplied by the cost per ticket, the child total, child tickets multiplied by the cost per child's ticket, senior total, senior tickets multiplied by the cost per senior ticket, and the wristband total, which is your number of wristbands multiplied by the cost per wristband.

Finally, the total cost, which is the sum of the adult cost, the child cost, the senior cost, and the wristband cost will be calculated.

Well done on attempting this task, I'm sure you were able to create flow charts for the other subroutines that you defined in your programme.

To summarise, a project brief specifies what the requirements of a programme are.

A structure chart is a diagram used to design the structure of the subroutines required for completing a programme.

A flow chart is a visual representation of the programme.