DoAssignment study guide
C1.3 · Decompose a task into subprograms
Learn to decompose a task into subprograms through clear examples and targeted practice.
Ontario Grade 12 Computer Science
Designing Modular Programs
ICS4U study topic C1.3: Divide a programming task into clear, connected parts
What you will learn
- Explain how decomposition divides a programming task into subprograms.
- Choose useful subprograms with clear responsibilities.
- Identify what information each subprogram needs and what result it provides.
- Trace how a main part coordinates subprograms to complete a task.
1. Start with the whole task
- State the complete task's input and expected outcome first.
- Group related actions into meaningful jobs.
- Use a level of detail that clarifies the task rather than fragmenting it.
2. Give each part a responsibility and a hand-off
- Give each subprogram a clear responsibility.
- Identify the information supplied to it and the result it provides.
- Check that the main part connects the jobs and uses their results.
3. Represent, trace, and review a decomposition
- Trace calls and returned results in the order the main part uses them.
- Check the trace against the whole task's expected outcome.
- Revise unclear responsibilities or missing hand-offs.
Worked example
Plan a purchase-cost task
The main part coordinates two calculation subprograms and uses their returned results.
Python 3
def calculate_tax(price, rate):
return price * rate
def final_cost(price, tax_amount):
return price + tax_amount
price = 20.00
rate = 0.08
tax_amount = calculate_tax(price, rate)
total = final_cost(price, tax_amount)
print(total)- State the whole taskThe input is an item price and a tax rate. The expected outcome is the cost after tax has been added. The rate is assumed to be provided as a decimal, such as 0.08 for eight percent.
- Assign clear jobsThe main part receives the input and coordinates two subprograms. calculate_tax receives the price and rate and returns the tax amount. final_cost receives the price and tax amount and returns the total.
- Check the hand-offsThe main part supplies the returned tax amount to final_cost. Both calculation jobs contribute to the requested outcome, and each has a distinct responsibility.
Worked example
Trace the purchase-cost program
The main part passes the input to calculate_tax, then passes the returned tax amount to final_cost.
Python 3
def calculate_tax(price, rate):
return price * rate
def final_cost(price, tax_amount):
return price + tax_amount
price = 20.00
rate = 0.08
tax_amount = calculate_tax(price, rate)
total = final_cost(price, tax_amount)
print(total)- State assumptions and inputAssume the price is non-negative and the rate is given as a decimal. The supplied values are a price of 20.00 and a rate of 0.08.
- Follow the first hand-offThe main part calls calculate_tax with the price and rate. Multiplying 20.00 by 0.08 gives 1.60, which the function returns as the tax amount.
- Follow the next resultThe main part calls final_cost with 20.00 and 1.60. Adding them gives 21.60. The print instruction displays the numeric value 21.6; it does not require two decimal places.
Worked example
Decompose a quiz-average task
The main part supplies the scores and uses the average returned by the calculation subprogram.
Python 3
def calculate_average(score1, score2, score3):
total = score1 + score2 + score3
return total / 3
average = calculate_average(6, 8, 10)
print(average)- Choose responsibilitiesThe main part receives the three scores and coordinates the result. A calculate_average subprogram receives the scores, calculates their average, and returns it.
- Trace the supplied valuesThe subprogram adds 6, 8, and 10 to get 24. It divides this total by the three scores, returning 8.0.
- Connect to the outcomeThe main part uses the returned average for display. The expected numeric output is 8.0. Receiving and presenting are distinct from the calculation responsibility.
Common mistakes and how to avoid them
Lesson summary
- Decomposition divides an overall programming task into smaller subprograms that work together.
- Start with the whole task, then give useful parts clear responsibilities.
- Identify the information each subprogram needs and the result it provides.
- Trace the main part's hand-offs to check that the parts complete the intended task.
Check your understanding
Question 1
- Use a conversion subprogram that returns the converted value, and let the main part display it.
- Put every instruction in one sequence and name the sequence do_everything.
- Create a display subprogram that does not receive or use the converted value.
- correctIndex
Show answer and explanation
Question 2
- 1.60, the tax amount
- 20.08, the final cost
- 21.60, the tax amount
- correctIndex
Show answer and explanation
Question 3
- Each subprogram has a clear responsibility and the information it needs.
- Every subprogram has the same responsibility.
- The main part never uses results from subprograms.
- correctIndex
Show answer and explanation
Key terms
- Decomposition
- Dividing an overall task into smaller parts that work together to complete it.
- Subprogram
- A named part of a program responsible for a particular job.
- Input
- Information supplied to a program or subprogram so it can do its job.
- Result
- A value or outcome a subprogram provides for use by another part.
Continue through ICS4U
View the complete ICS4U Ontario Grade 12 Computer Science curriculum and lessons
Tutor support for C1.3 · Decompose a task into subprograms
Working on C1.3 · Decompose a task into subprograms in ICS4U? Bring the question and your own attempt. In a live session, you can trace a small input step by step, compare expected and actual output, and test an edge case. Ask about the first step that does not make sense, then try a similar question yourself.
Explore coding tutoring · Request an eligible free 30-minute introduction. Your request is matched by subject and language; a tutor must accept before a time is confirmed.
برای مبحث C1.3 · شکستن کار به زیربرنامهها در درس ICS4U، سؤال و تلاش خود را همراه بیاورید. در جلسه میتوانید یک ورودی کوچک را گامبهگام دنبال کنید، خروجی مورد انتظار و واقعی را مقایسه کنید و یک حالت مرزی را بیازمایید. راهنمای معلم برنامهنویسی را ببینید یا جلسهٔ معارفهٔ رایگان ۳۰ دقیقهای درخواست کنید. زمان جلسه پس از پذیرش معلم قطعی میشود.
About this lesson and its review
Published by DoAssignment. This reviewed lesson follows Ontario Grade 12 Computer Science (ICS4U), expectation C1.3. It is a study resource, not an official curriculum publication.
Before publication, content is checked for structure, mathematical or chemical notation, calculations, course boundaries, and readability. Errors can still occur, so corrections are welcomed.