Using Decomposition & Abstraction (Edexcel GCSE Computer Science)
Revision Note
Written by: Robert Hampton
Reviewed by: James Woodhouse
Using Decomposition & Abstraction to Analyse,
Understand & Solve Problems
Examiner Tips and Tricks
Before attempting to use decomposition and abstraction it is important to understand the process by reading here
Task
Write a program that calculates the total cost of a pizza order. The program should include the following features:
Size: The user can choose from three sizes (small, medium, and large) with different base prices
Toppings: The user can choose any number of toppings from a list, with each topping having a set price
Discount: There is a 10% discount applied to orders over £20
Abstraction
Create a function that calculates and returns the base price of the pizza by taking the size as an input
Decomposition
Break down the task in to smaller, more manageable pieces
For example, using separate functions to:
Get the user input for pizza size and toppings
Calculate cost of toppings
Apply discount (if applicable)
Output final order total
Python code
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# ----------------------------------------------------------------------- # This function displays options and gets valid user input from the provided list # -----------------------------------------------------------------------
# ----------------------------------------------------------------------- # This function calculates the total cost of selected toppings # -----------------------------------------------------------------------
# ----------------------------------------------------------------------- # This function applies a 10% discount if the total cost exceeds £20 # -----------------------------------------------------------------------
# ----------------------------------------------------------------------- # This function coordinates the program flow and calls other functions # -----------------------------------------------------------------------
# ----------------------------------------------------------------------- # Main program starts here # -----------------------------------------------------------------------
|
Last updated:
You've read 0 of your 5 free revision notes this week
Sign up now. It’s free!
Did this page help you?