Why decomposition helps: team work and reuse

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Why decomposition helps: team work and reuse

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A school app is split into sub-problems. Which statement about team work is correct?
A Only one programmer can work on the program at a time
B Different programmers can write different parts at the same time
2. Which is a benefit of decomposition for a team?
A A specialist can work on the part they know best
B Every programmer must write every part of the program
3. A team needs a screen layout and a database search. Which is the best way to share the work?
A Give both parts to the same person and have everyone else wait
B Give each part to the programmer skilled in that area
4. A validation subroutine has been written and tested for a school login program. What can the team do with it?
A Reuse it in other programs that need the same check
B Delete it, because it can only work in the first program
5. Which statement about reusing a subroutine is correct?
A Reusing a tested subroutine saves development time
B Every program needs its own newly written copy of the same check

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1CALL ValidateAge() AThis does not share the work. Sub-problems should be split between team members so they are written at the same time.
2Programmer A: PROCEDURE Login() Programmer B: PROCEDURE Report() BCopying the same code again and again wastes time and risks errors. The check should be one subroutine that is reused.
3A validation subroutine written once can be reused in many programs CFUNCTION ValidateInput(Value : INTEGER) RETURNS BOOLEAN
4A specialist works on the sub-problem that matches their skills DRuns a finished validation subroutine that was already written, so it can be reused in a program without rewriting it
5Copy and paste the age check code into every new program EDatabase expert writes PROCEDURE SaveRecords()
6One programmer writes all of the sub-problems one after another FDifferent team members write different sub-problems at the same time

Definitions

team work and reuse

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
____ ValidateAge()
2.
FUNCTION Check(N : INTEGER) RETURNS _______
3.
PROCEDURE ShowMenu() OUTPUT "1. Play 2. Quit" ____________
4.
PROCEDURE CheckAge() ENDPROCEDURE CALL ________()
5.
IF Age >= 0 ___ Age <= 120 THEN

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A PROC CheckAge(Age)
B IF Age < 0 OR Age > 99 THEN
C OUTPUT "Invalid age"
D ENDIF
E ENDPROCEDURE
Question 2
A // Ana wrote GetMarks
B // Raj wrote ShowReport
C GetMarks()
D CALL ShowReport()
Question 3
A // Program 1: sign-up
B INPUT Age
C CALL CheckAge[Age]
D OUTPUT "Welcome"
Question 4
A FUNCTION Ok(N) RETURNS BOOLEAN
B IF N >= 1 AND N <= 10 THEN
C RETURN TRUE
D ENDWHILE
E RETURN FALSE
F ENDFUNCTION
Question 5
A FOR Count ← 1 UNTIL 3
B INPUT Age
C CALL CheckAge(Age)
D NEXT Count

Answer Key

Why decomposition helps: team work and reuse
Section A: Quick Questions
Q1
B — Different programmers can write different parts at the same time
Q2
A — A specialist can work on the part they know best
Q3
B — Give each part to the programmer skilled in that area
Q4
A — Reuse it in other programs that need the same check
Q5
A — Reusing a tested subroutine saves development time
Section B: Match the Pairs
Q1
CALL ValidateAge() → Runs a finished validation subroutine that was already written, so it can be reused in a program without rewriting it
Q2
Programmer A: PROCEDURE Login() Programmer B: PROCEDURE Report() → Different team members write different sub-problems at the same time
Q3
A validation subroutine written once can be reused in many programs → FUNCTION ValidateInput(Value : INTEGER) RETURNS BOOLEAN
Q4
A specialist works on the sub-problem that matches their skills → Database expert writes PROCEDURE SaveRecords()
Q5
Copy and paste the age check code into every new program → Copying the same code again and again wastes time and risks errors. The check should be one subroutine that is reused.
Q6
One programmer writes all of the sub-problems one after another → This does not share the work. Sub-problems should be split between team members so they are written at the same time.
Section C: Definitions
Q1
team work and reuse — Different programmers write separate sub-problems at the same time, using their own skills, and finished parts such as a validation subroutine can be reused in other programs.
Section D: Fill in the Blanks
Q1
CALL ValidateAge()
Q2
FUNCTION Check(N : INTEGER) RETURNS BOOLEAN
Q3
PROCEDURE ShowMenu() OUTPUT "1. Play 2. Quit" ENDPROCEDURE
Q4
PROCEDURE CheckAge() ENDPROCEDURE CALL CheckAge()
Q5
IF Age >= 0 AND Age <= 120 THEN
Section E: Spot the Error
Q1
A — Cambridge pseudocode starts a procedure with the keyword PROCEDURE, not PROC. This validation part is written once as a subroutine so it can be reused in many programs.
Q2
C — A procedure written by a team member is run with the CALL keyword. It should be CALL GetMarks().
Q3
C — Arguments are passed inside round brackets, not square brackets. It should be CALL CheckAge(Age), so the same validation procedure can be reused.
Q4
D — An IF statement must be closed with ENDIF, not ENDWHILE. The line should be ENDIF so this reusable validation function is complete.
Q5
A — A FOR loop uses TO to give the end value, not UNTIL. It should be FOR Count ← 1 TO 3. The reused CheckAge procedure is then called each time round the loop.