Using Decomposition & Abstraction (Edexcel GCSE Computer Science)
Revision Note
Using Decomposition & Abstraction to Analyse,
Understand & Solve Problems
Examiner Tip
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 10 free revision notes
Unlock more, it's free!
Did this page help you?