ICS3U Computer Science • Ontario Grade 11

Corrected exercises: software development life cycle and program design (ICS3U)

Exercises: software development life cycle and program design (ICS3U)

Name: Class: Date:

Solutions

Suggested time: 2 h 30 · No calculator · 10 exercises
https://www.letuteurscientifique.ca/en/exercices/ics3u-software-development-life-cycle

These ten corrected exercises cover the tenth chapter of ICS3U, Introduction to Computer Science, Grade 11, University Preparation, in Ontario: the software development life cycle and program design.

What the set covers, the traps it targets

You place work in the seven phases of the cycle (problem definition, analysis, design, writing code, testing, implementation, maintenance) and tell a phase from a milestone and a product, write a specification in the input-process-output model, clarify an ambiguous specification by the right question, read and correct a flow chart, translate pseudocode into Python, read the structure chart of a top-down design, choose prompts and messages that meet a specification, and plan a project led by the teacher with a task table, its critical path and slack, a Gantt chart and a PERT estimate.

The code is in Python 3; phases, charts and schedules are the same in any language, and a line of the solutions says where Java behaves differently.

By the end, you can put the seven moments of a room-booking project in order (exercise 1), turn the request of a karaoke bar into inputs, process and outputs (exercise 2), translate and trace the pseudocode of a pyramid of cups (exercise 3), find and repair the faulty decision in the flow chart of a robot vacuum (exercise 4), and read the structure chart of a ferry ticket kiosk (exercise 5). Part B lists the questions to ask a science museum about its prices (exercise 6), finds the critical path of a class project (exercise 7), corrects five statements (exercise 8), fills the prompts and messages of a parcel locker (exercise 9), and corrects the Gantt chart of a laptop sign-out app (exercise 10).

The thread of the set: each phase hands a product to the next one, and a project lasts as long as its longest chain of dependent tasks; what the analysis leaves open, a boundary or an input, and what lies on the critical path, a task with no slack, is what makes a program wrong or a project late. Five traps are named in the solutions: (1) taking testing for the last phase, when implementation and maintenance follow, exercises 1 and 8; (2) taking the shortest path for the critical path, which is the longest, exercises 7, 8 and 10; (3) believing a critical task can slip without moving the end, when it has no slack, exercises 7, 8 and 10; (4) a decision diamond without its two labelled exits, exercises 4 and 8; (5) settling an ambiguous boundary alone instead of asking the client before writing the code, exercises 6 and 8, with the boundaries of exercises 2 and 4. Also treated: a constant that is not an input and an input missing from a request (2), int(input()) and a comparison changed while translating (3), FOR ... TO n translated as range(1, n + 1) (3), shortening a critical task that gains less than expected (7), an entry that must not use a try (9), and a bar drawn before the task it waits for ends (10).

No calculator is needed: every value is a sum, a trace or a comparison worked out by hand, as on a unit test.

  • 10 corrected exercises • 100 points • 150 minutes
  • Self-checking, 105 answers
  • No calculator
Start exercise 1 The chapter sheet
Print

Print the homework or the solutions

The homework without solutions, one exercise per page, and the solutions on their own: it comes with your free space. An email is enough, no password, and you come back here.

Create my free space

Already have one? Sign in

Course recap

  • • The seven phases, in order: problem definition, analysis, design, writing code, testing, implementation, maintenance.
  • • A milestone is a date with no duration; a product is a document or a program that a phase hands on.
  • • A specification lists the inputs, the process (rules and constants) and the outputs, with every boundary settled.
  • • Flow chart: rounded box for start and end, parallelogram for input or output, rectangle for a process, diamond for a decision with two labelled exits.
  • • Pseudocode FOR i FROM 1 TO n includes n: in Python, range(1, n + 1).
  • • A structure chart shows which module calls which, from the whole task at the top down to small modules.
  • • The critical path is the longest path of dependent tasks; its length is the minimum duration of the project.
  • • Slack of a task: length of the critical path minus the longest path through the task; a critical task has none.

Part A: the basics (/50)

Exercise 1: The seven phases in order: booking the practice rooms of a music department

14 answers to check

The music department of a school wants its students to book its four practice rooms online, in slots of 30 minutes. The table lists seven moments of the project, out of order.

MomentWhat happens
1Students report that a booking of the last slot of the day, at 21:30, disappears. A programmer corrects the program, and version 1.1 is installed.
2The program is installed on the department's server, and the music teacher is shown how to cancel a booking.
3The music teacher explains the problem: two bands often arrive at the same room at the same time.
4The inputs (student number, room, day, slot), the outputs (a confirmation, or the reason for a refusal) and the rules (at most 2 slots per student per day) are written in a specification, which the teacher signs on October 3.
5A flow chart of the booking check and a structure chart of the modules are drawn.
6The modules are written in Python, each with a comment under its header.
7Each row of a test plan is run: input data, expected outcome, actual outcome, pass or fail.
  • a) The cycle has seven phases, listed here in alphabetical order: analysis, design, implementation, maintenance, problem definition, testing, writing code. Give the rank, from 1 to 7, of the phase of moments 3, 4 and 5 in the cycle.
  • b) Give the rank of the phase of moments 6, 7, 2 and 1.
  • c) A student writes in the project log: « Moment 7 is done and every test passes, so the project is finished. » How many phases of the cycle come after testing? Which of them lasts as long as students use the program?
  • d) Which row of the test plan would have revealed the bug of moment 1 before installation? In which phase is the bug corrected, now that the program is in use?
  • e) Say whether each item is a phase, a milestone or a product of the cycle: the signature of the specification on October 3; the flow chart of moment 5; the bug report sent by the students in moment 1.

Type your answers, the page tells you right or wrong 0/14

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) moment 3: rank 1, problem definition; moment 4: rank 2, analysis; moment 5: rank 3, design
  • b) moment 6: rank 4, writing code; moment 7: rank 5, testing; moment 2: rank 6, implementation; moment 1: rank 7, maintenance
  • c) 2 phases; maintenance
  • d) a booking of the last slot, 21:30; maintenance
  • e) a milestone; a product; a product

The life cycle orders the work on a program. Each phase answers one question and hands a product to the next: problem definition says what is wrong, analysis states what the program takes in, does and gives out, design says how, on paper, writing code turns the design into a program, testing compares the program with the specification, implementation puts it in the hands of its users, and maintenance corrects and changes it while it is used.

a)

Moment 3 states the problem in the words of the user: problem definition, rank 1.

Moment 4 writes inputs, outputs and rules in a specification: analysis, rank 2.

Moment 5 draws how the program will work, before any code: design, rank 3.

b)

Moment 6 is writing code, rank 4, and moment 7 runs the test plan, testing, rank 5.

Moment 2 puts the program on the server and shows its user how to work it: implementation, rank 6.

Moment 1 corrects a program already in use and installs a new version: maintenance, rank 7. The figure puts the seven moments back in order.

c)

Two phases come after testing: implementation, then maintenance.

Maintenance lasts as long as the program is used: every correction and every change asked by its users belongs to it.

Pitfall: ending the cycle at testing. A program that passes its tests still has to be installed, and its users will try cases that the test plan did not.

d)

The bug touches the last slot of the day, a boundary of the slots. A row with a booking at 21:30 would have shown it during testing; a booking at 16:00 tries an ordinary slot, which works.

The program is now in use, so the correction belongs to maintenance. The row at 21:30 joins the test plan, so that version 1.1 and the versions after it are tried on it.

e)

A phase is a period of work, a milestone is a date that marks the end of a step, a product is a document or a program that a phase hands on.

The signature on October 3 is a milestone: it closes the analysis. The flow chart is a product of the design. The bug report is a product too, the one that starts the work of maintenance.

1. Problem definitionmoment 3: the problem, in the teacher's words2. Analysismoment 4: the specification, signed October 33. Designmoment 5: flow chart and structure chart4. Writing codemoment 6: the modules in Python5. Testingmoment 7: the test plan, run row by row6. Implementationmoment 2: installed on the server7. Maintenancemoment 1: version 1.1dashed: a change asked in maintenance starts the cycle againThe seven moments put back in the order of the cycle

Tick the exercises you have done or want to review: a free account, no password, keeps your ticks and your right answers from one visit to the next, tells you which chapter to tackle next and lets you ask for the exercise you are missing. Create your space, an email is enough.

Exercise 2: Input, process, output: the specification of a karaoke room rental

12 answers to check

A karaoke bar rents its rooms by the hour. The owner's request: « The first hour costs 18 dollars, and each hour started after it costs 9 dollars. No room costs more than 60 dollars for the evening. The clerk types how long the room was used, in minutes, and the program displays the amount to charge. »

In the input-process-output model, a specification lists what the program receives, what it computes, and what it gives out.

  • a) Place each item in the model: the time the room was used, in minutes; the amount to charge; rounding a started hour up to a full hour; applying the cap of 60 dollars.
  • b) A room is used for 135 minutes. How many hours are charged? What amount?
  • c) What amount is charged for 60 minutes? For 61 minutes?
  • d) From how many charged hours does the cap of 60 dollars change the amount? What is charged for 400 minutes?
  • e) The owner adds: « A group can rent several rooms for the same time. » Which input is now missing from the specification? What does a group pay for 3 rooms used 135 minutes each?

Type your answers, the page tells you right or wrong 0/12

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) input; output; process; process
  • b) 3 hours; 36 dollars
  • c) 18 dollars; 27 dollars
  • d) 6 hours; 60 dollars
  • e) the number of rooms; 108 dollars

The input-process-output model reads a request in three columns: what the user types, what the program computes from it, and what it displays. A value that is the same for every rental, such as 18 dollars, is not an input: it is a constant of the process.

a)

The time in minutes is typed by the clerk: input.

The amount is displayed: output.

Rounding a started hour and applying the cap are computations on the input: process.

b)

135 minutes is 2 hours and 15 minutes: the third hour is started, so 3 hours are charged.

18 + 9 × 2 = 36 dollars.

In Python, (minutes + 59) // 60 gives the number of hours started, for a positive number of minutes: (135 + 59) // 60 = 194 // 60 = 3. The program of this specification is given below.

c)

60 minutes is one full hour, and no hour is started after it: 18 dollars.

61 minutes starts a second hour: 18 + 9 = 27 dollars.

Pitfall: the boundary of the request. « Each hour started » decides that 61 minutes costs 9 dollars more than 60; a request that only said « per hour » would leave 61 minutes open, and the question would go back to the owner before any code is written.

d)

With h hours charged, the amount before the cap is 18 + 9(h − 1): 5 hours give 54 dollars, 6 hours give 63, more than 60. The cap changes the amount from 6 hours.

400 minutes is 6 hours and 40 minutes: 7 hours are started, 18 + 9 × 6 = 72 dollars before the cap, so 60 dollars are charged.

e)

The number of rooms is a new input: nothing in the old specification gives it.

« No room costs more than 60 dollars » caps each room, not the group. Each room costs 36 dollars: 3 × 36 = 108 dollars.

Python
minutes = int(input('Minutes used: '))
hours = (minutes + 59) // 60
amount = 18 + 9 * (hours - 1)
if amount > 60:
    amount = 60
print('Amount to charge:', amount, 'dollars')

Exercise 3: From pseudocode to Python: a pyramid of cups

12 answers to check

For a fundraiser display, students stack plastic cups in rows: the top row has 1 cup, the next one 2 cups, then 3, and so on. The pseudocode below gives the number of complete rows that a number of cups can build, and the cups left over.

Pseudocode
INPUT cups                      # line 1
SET rows TO 0                   # line 2
SET used TO 0                   # line 3
WHILE used + rows + 1 <= cups   # line 4
    SET rows TO rows + 1        # line 5
    SET used TO used + rows     # line 6
END WHILE                       # line 7
OUTPUT rows, cups - used        # line 8
  • a) Trace the pseudocode for cups = 12. How many complete rows, and how many cups left over?
  • b) Same question for cups = 50.
  • c) Which Python line translates line 1? Which one translates line 4?
  • d) A student translates line 4 as while used + rows + 1 < cups: and keeps everything else. What does his program output for cups = 55? What should it output?
  • e) The display team wants the row numbers listed after the result, with FOR r FROM 1 TO rows, then OUTPUT r. Which range translates this FOR? For cups = 12, how many lines does this loop output?

Type your answers, the page tells you right or wrong 0/12

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) 4 rows; 2 cups left over
  • b) 9 rows; 5 cups left over
  • c) cups = int(input('Number of cups: ')); while used + rows + 1 <= cups:
  • d) 9 rows and 10 left over; 10 rows and 0 left over
  • e) range(1, rows + 1); 4 lines

Pseudocode states an algorithm in plain words, without the punctuation of a language. Translating it into Python means choosing, word for word, the Python form with the same meaning, comparisons and loop bounds included. A trace follows the variables after each pass of the loop.

a)

Start: rows = 0, used = 0. The test of line 4 asks whether the next row, of rows + 1 cups, still fits.

0 + 0 + 1 = 1 ≤ 12: rows = 1, used = 1. Then 1 + 1 + 1 = 3 ≤ 12: rows = 2, used = 3.

3 + 2 + 1 = 6 ≤ 12: rows = 3, used = 6. Then 6 + 3 + 1 = 10 ≤ 12: rows = 4, used = 10.

10 + 4 + 1 = 15 > 12: the loop ends. Output: 4 rows and 12 − 10 = 2 cups left over.

b)

The rows use 1 + 2 + ... + n cups. After 9 rows, used = 45; the tenth row needs 10 more cups, and 45 + 10 = 55 > 50: the loop ends.

Output: 9 rows and 50 − 45 = 5 cups left over.

c)

INPUT cups reads a number. In Python, input() gives back a string, which int() turns into a whole number: cups = int(input('Number of cups: ')).

Without int(), cups is a string, and line 4 stops the program with a TypeError, since <= cannot compare a number with a string.

Line 4 keeps its comparison and ends with a colon: while used + rows + 1 <= cups:. END WHILE has no Python line: the indentation closes the loop.

d)

With <, the loop stops as soon as the next row would use the last cup. For 55, after 9 rows used = 45, and 45 + 9 + 1 = 55 < 55 is False: the program outputs 9 rows and 10 left over, although the tenth row needs 10 cups, the 10 left.

The pseudocode, with <=, builds the tenth row: 10 rows and 0 left over.

Pitfall: changing a comparison while translating. The two versions differ only when the cups fill their last row with none left over, the case to try first.

e)

FOR r FROM 1 TO rows includes rows. range stops before its second bound: range(1, rows + 1). range(1, rows) would forget the last row.

For 12 cups, rows = 4: the loop outputs 4 lines, Row 1 to Row 4. The full translation is given below.

Python
cups = int(input('Number of cups: '))
rows = 0
used = 0
while used + rows + 1 <= cups:
    rows = rows + 1
    used = used + rows
print(rows, cups - used)
for r in range(1, rows + 1):
    print('Row', r)

Exercise 4: Reading and correcting a flow chart: a robot vacuum

12 answers to check

A robot vacuum cleans a floor one square metre at a time. Each square metre uses 3 % of its battery, and its dust bin is full after 20 square metres. The flow chart below, drawn by a student, describes its program; battery holds a whole percentage.

StartRead batterysquares = 0battery > 15 ?battery = battery - 3squares = squares + 1squares == 20 ?Display Empty my binEndDisplay squaresGo back to the dockEndYesNoYes
  • a) Which shape holds Read battery? Which one holds battery = battery - 3? Which one holds the test squares == 20 ?
  • b) The test squares == 20 ? is drawn with a single exit, Yes. What is wrong with it? Where must the missing exit lead?
  • c) With the chart corrected, the battery starts at 60. How many square metres does the robot clean? What is the battery level when it heads back to the dock?
  • d) The battery starts at 100. How many square metres does the robot clean, and what is its battery level when it stops? Which message does it display?
  • e) An engineer changes the first test to battery >= 15. With a start at 60, how many square metres does the robot clean now, and with what battery level does it head back to the dock?

Type your answers, the page tells you right or wrong 0/12

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) parallelogram; rectangle; diamond
  • b) the No exit is missing; back to the test battery > 15 ?
  • c) 15 square metres; 15 %
  • d) 20 square metres; 40 %; Empty my bin
  • e) 16 square metres; 12 %

A flow chart draws an algorithm with four shapes: a rounded box for the start and the end, a parallelogram for an input or an output, a rectangle for a process, a diamond for a decision. The arrows give the order, and the two exits of a diamond carry the two answers to its question.

a)

Read battery receives a value from outside: a parallelogram, input or output.

battery = battery - 3 changes a variable: a rectangle, process.

squares == 20 ? asks a question with two answers: a diamond, decision.

b)

A decision has two answers, so its diamond has two exits, each labelled with its answer. Here only Yes is drawn: when squares is not 20, the chart says nothing, and a program written from it has no next step.

The No exit must lead back to the test battery > 15 ?, so that the robot cleans the next square metre if its battery allows it. Leading it to Read battery would run squares = 0 again and lose the count.

Pitfall: a diamond with one exit, or with two exits and no labels. The solution figure shows the corrected chart, and the Python program below follows it.

c)

After k square metres, the battery holds 60 − 3k, and the test battery > 15 lets one more square metre start while 60 − 3k > 15, that is while k < 15.

The robot cleans square metres number 1 to 15. Then battery = 60 − 45 = 15, and 15 > 15 is False: it displays 15 and heads back to the dock with 15 %.

The bin test answers No at each pass, since squares stays below 20.

d)

From 100, the battery alone would allow 29 square metres, since 100 − 3 × 28 = 16 > 15. The bin test stops the robot first: after the 20th square metre, squares == 20 is True.

battery = 100 − 3 × 20 = 40: the robot displays Empty my bin and stops with 40 %.

e)

With >= 15, a square metre also starts when the battery holds 15: the robot cleans a 16th square metre and heads back with 15 − 3 = 12 %.

The two tests differ only at the boundary value 15. Whether 15 % is enough to clean one more square metre and still reach the dock is a question for the specification of the robot, settled before the test is written.

Python
battery = int(input('Battery level: '))
squares = 0
full = False
while battery > 15 and not full:
    battery = battery - 3
    squares = squares + 1
    if squares == 20:
        full = True
if full:
    print('Empty my bin')
else:
    print(squares)
    print('Going back to the dock')
StartRead batterysquares = 0battery > 15 ?battery = battery - 3squares = squares + 1squares == 20 ?Display Empty my binEndDisplay squaresGo back to the dockEndYesNoYesNoadded: the No exit of the bin testgoes back to the battery test

Exercise 5: Top-down design: the structure chart of a ferry ticket kiosk

7 answers to check

A ferry company wants a ticket kiosk. Its designer starts from one task, sell a ticket, and refines it step by step: get the order, compute the total, print the ticket. Each step is refined again until every module is small enough to be written on its own. The structure chart below is the result.

get_order asks for the number of adults, of children and of vehicles with read_count, and whether the trip is a return trip with read_yes_no; print_ticket asks with read_yes_no whether the client wants a receipt. Fares: 12 dollars per adult, 6 dollars per child, 25 dollars per vehicle; a return trip doubles the total.

main programget_ordercompute_totalprint_ticketread_countread_yes_noStructure chart: each line goes from a module down to a module it calls
  • a) How many modules does the main program call directly? Which module calls read_count?
  • b) Two lines reach read_yes_no. What does that mean? How many functions are written for this program, not counting the main program?
  • c) How many modules call no other module?
  • d) Which values must get_order send back to the main program so that compute_total can do its work?
  • e) A family orders 2 adults, 1 child and 1 vehicle, with a return trip. What total does compute_total give back?

Type your answers, the page tells you right or wrong 0/7

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) 3 modules; get_order
  • b) get_order and print_ticket both call it, and its code is written once; 5 functions
  • c) 3 modules
  • d) the numbers of adults, children and vehicles, and the answer about the return trip
  • e) 110 dollars

A structure chart is the picture of a top-down design: the whole task at the top, the modules that carry it out under it, each one refined into smaller modules until each can be written alone. It shows which module calls which; the order in which the lines run is the job of the flow chart or of the pseudocode.

a)

Three lines leave the main program, to get_order, compute_total and print_ticket.

read_count hangs under get_order: get_order calls it, once for each count it needs.

b)

Two lines reach read_yes_no, one from get_order (return trip?) and one from print_ticket (receipt?): two modules call it, and its code is written once. A question asked in two places becomes one function.

The functions to write are get_order, compute_total, print_ticket, read_count and read_yes_no: 5.

c)

read_count, read_yes_no and compute_total have no line under them: 3 modules call no other module.

compute_total computes the total from the values it receives, without asking anything.

d)

compute_total needs the three counts and the answer about the return trip. They are read inside get_order, whose local names disappear when it ends: get_order must send them back, and the main program passes them to compute_total.

A structure chart can show these exchanges as small arrows beside the lines, called data couples.

e)

One way: 2 × 12 + 1 × 6 + 1 × 25 = 24 + 6 + 25 = 55 dollars.

The return trip doubles it: 2 × 55 = 110 dollars.

Part B: problems and reasoning (/50)

Exercise 6: An ambiguous specification: the questions to ask before coding

8 answers to check

A science museum asks for a program that gives the admission price from the age of a visitor. Its first message: « Children under 5 get in free. Children between 5 and 12 pay 8 dollars. Teens pay 11 dollars. Adults over 18 pay 16 dollars. Seniors pay 11 dollars. »

  • a) A visitor is 12. Which prices does this message allow?
  • b) A visitor is 18. Which question should the programmer ask the museum? For a visitor of 70, what is missing from the message?
  • c) For the ages 3, 8, 12, 15, 18, 19, 40 and 70, how many need an answer from the museum before the program can give one price?
  • d) The museum answers: children from 5 to 12 included, teens from 13 to 17, adults from 18 to 64, seniors from 65. What does a family with members aged 4, 12, 17, 18 and 66 pay? What does a visitor of 19 pay?
  • e) Before asking, the programmer had guessed children 5 to 11, teens 12 to 18, adults 19 to 59, seniors from 60, and written a test plan with rows for the ages 4, 11, 12, 18, 19, 59, 60 and 65. How many of these rows have a different expected price after the museum's answer? In which phase should the questions have been asked?

Type your answers, the page tells you right or wrong 0/8

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) 8 dollars if « between » includes 12; otherwise no price at all
  • b) « Does an 18-year-old pay the teen price, 11 dollars, or the adult price, 16 dollars? »; the age at which a visitor becomes a senior
  • c) 4 ages: 12, 18, 19 and 70
  • d) 46 dollars; 16 dollars
  • e) 3 rows (ages 12, 18 and 60); the analysis

A request is written in the words of the client, and words leave boundaries open: « between », « over », « teens », « seniors ». Each open boundary is an age where two reasonable programs give different prices. The programmer finds them during the analysis and asks the client, in a dialogue; a guess leaves the question open until testing, or until a visitor is charged the wrong price.

a)

If « between 5 and 12 » includes 12, the price is 8 dollars. If it does not, 12 falls in no category, since teens start at thirteen.

The message allows 8 dollars or no price at all, and only the museum can say which.

b)

18 has two readings: a teen (eighteen ends in « teen »), 11 dollars, or an adult, if « over 18 » was meant as « 18 and over », 16 dollars. The useful question names both readings and their prices, so that the answer settles the code: « Does an 18-year-old pay the teen price, 11 dollars, or the adult price, 16 dollars? »

For 70, the price of seniors is given, but not the age at which a visitor becomes one.

Asking which language to use, or how many visitors come, settles no price: these questions do not touch the specification.

c)

3, 8 and 15 fall in one category under any reading. 40 is an adult over 18, and the senior ages in common use, from 55 to 65, are all above 40.

12 (included or not), 18 (teen or adult), 19 (a teen by the word, and over 18: two prices) and 70 (adult, or senior from an age not given) need an answer: 4 ages.

Pitfall: settling these boundaries alone, in the code. Each guess is a price the museum did not choose.

d)

With the answer, each age has one price: 4 gives 0, 12 gives 8, 17 gives 11, 18 gives 16 and 66 gives 11 dollars.

0 + 8 + 11 + 16 + 11 = 46 dollars. A visitor of 19 is an adult: 16 dollars. The function below follows the answer.

e)

Expected prices under the guess, then under the answer: 4: 0 and 0; 11: 8 and 8; 12: 11 and 8; 18: 11 and 16; 19: 16 and 16; 59: 16 and 16; 60: 11 and 16; 65: 11 and 11.

3 rows change, for the ages 12, 18 and 60: the guess placed three of the four boundaries differently from the museum.

The questions belonged to the analysis, before the design. Asked then, they cost one message to the museum; found after testing, they cost three rows of the test plan and the lines of code behind them.

Python
def price(age):
    # admission price in dollars, from the museum's answer
    if age < 5:
        return 0
    elif age <= 12:
        return 8
    elif age <= 17:
        return 11
    elif age <= 64:
        return 16
    else:
        return 11
print(price(4) + price(12) + price(17) + price(18) + price(66), price(19))

Exercise 7: Critical path: the schedule of a class project

11 answers to check

A Grade 11 class builds a lost-and-found web app for the school, in a project led by the teacher. Each task is given to one student, so tasks run at the same time whenever they can, and a task starts as soon as every task it must follow is finished. Durations are in school days.

TaskWorkDaysMust follow
ADefine the problem, write the specification3none
BDesign the screens4A
CDesign the search algorithm2A
DCode the screens5B
ECode the search module6C
FWrite the test plan2A
GTest the whole program3D, E, F
HInstall the app on the school website1G
  • a) Three paths lead from A to H. Give the length in days of the path through B and D, of the path through C and E, and of the path through F.
  • b) What is the minimum duration of the project? Which path is the critical path?
  • c) What is the slack of task E? Of task F?
  • d) Task D takes 2 days more than planned. What is the new minimum duration? If task F had taken 2 days more instead, what would it be?
  • e) With the durations of the table, a second student joins task D, which drops from 5 days to 2. What is the new minimum duration? Which path is critical now?

Type your answers, the page tells you right or wrong 0/11

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) 16 days; 15 days; 9 days
  • b) 16 days; A, B, D, G, H
  • c) 1 day; 7 days
  • d) 18 days; 16 days
  • e) 15 days; A, C, E, G, H

Tasks that must follow one another form a path, and a path lasts the sum of its durations. The project ends when its longest path ends: that path is the critical path, and its length is the minimum duration of the project. A task off the critical path has slack, time it can lose without moving the end.

a)

A, B, D, G, H: 3 + 4 + 5 + 3 + 1 = 16 days.

A, C, E, G, H: 3 + 2 + 6 + 3 + 1 = 15 days.

A, F, G, H: 3 + 2 + 3 + 1 = 9 days.

b)

G waits for D, E and F, and starts when the last of them ends. D ends on day 3 + 4 + 5 = 12, E on day 3 + 2 + 6 = 11, F on day 3 + 2 = 5: G runs from day 12 to day 15, and H from day 15 to day 16.

Minimum duration: 16 days, the length of the longest path. The critical path is A, B, D, G, H, in red on the figure.

Pitfall: choosing the shortest path, A, F, G, H. Nine days is the time of one chain of tasks; the project needs every chain finished.

c)

E ends on day 11 and G cannot start before day 12: E has 1 day of slack, 16 − 15. C, on the same path, has the same 1 day.

F ends on day 5: 7 days of slack, 16 − 9.

Here the slack of a task is the length of the critical path minus the length of the longest path through the task.

d)

D is on the critical path, with no slack: 2 days more on D give 2 days more on the project, 3 + 4 + 7 + 3 + 1 = 18 days.

F has 7 days of slack: 2 days more make its path 11 days, still shorter than 16. The project stays at 16 days.

Pitfall: a task on the critical path has no slack, so every day it loses is a day the project loses.

e)

The path through B and D drops to 3 + 4 + 2 + 3 + 1 = 13 days. The path through C and E, 15 days, becomes the longest: the minimum duration is 15 days, and A, C, E, G, H is critical now.

The project gains 1 day, not 3: shortening a critical task helps only until another path becomes the longest.

A, 3 dB, 4 dC, 2 dF, 2 dD, 5 dE, 6 dG, 3 dH, 1 dTask network: red, the critical path A, B, D, G, H (16 days)through C and E: 15 days, slack 1 day; through F: 9 days, slack 7 days

Exercise 8: Five statements to correct

10 answers to check

Each statement below was written by a student revising this chapter. Say whether it is true or false, then answer the question that follows it. Each false statement is corrected in the solution.

  • a) « Testing is the last phase of the software development life cycle. » A program released in September is used for three school years, and its users ask for two corrections each year. In which phase are these six corrections made?
  • b) « The critical path is the shortest path through the network of tasks. » In a project, A (2 days) comes first, then B (5 days) and C (3 days) run at the same time, and D (1 day) starts when B and C are both finished. What is the minimum duration of the project?
  • c) « A task on the critical path can lose one day without moving the end of the project. » In the project of question b, B takes 6 days instead of 5. What is the new minimum duration?
  • d) « A Yes-or-No diamond of a flow chart has two exits, each labelled with its answer. » A flow chart sets count to 0, then tests count < 4; its Yes exit leads to Display count, then to count = count + 1, then back to the test. How many times is the Yes exit taken?
  • e) « A client's rule of free shipping over 75 dollars can be coded with > 75 or with >= 75, as the programmer prefers: both programs are correct. » For the orders of 74.99, 75.00 and 75.01 dollars, how many get a different answer from the two programs?

Type your answers, the page tells you right or wrong 0/10

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) False; maintenance
  • b) False; 8 days
  • c) False; 9 days
  • d) True; 4 times
  • e) False; 1 order

Each statement is settled by one case worked out to the end: a phase placed in the cycle, a path added up, a loop counted, a boundary tried.

a)

False. After testing come implementation, then maintenance. The six corrections are made while the program is in use: maintenance.

Correct statement: « Testing is followed by implementation, then by maintenance, which lasts as long as the program is used. »

b)

False. The paths are A, B, D: 2 + 5 + 1 = 8 days, and A, C, D: 2 + 3 + 1 = 6 days. D waits for B: the project lasts 8 days, the length of the longest path.

Correct statement: « The critical path is the longest path; its length is the minimum duration of the project. »

c)

False. B is on the critical path and has no slack: A, B, D becomes 2 + 6 + 1 = 9 days, and the project lasts 9 days. C, with 8 − 6 = 2 days of slack, could lose up to 2 days without moving the end.

Correct statement: « A task on the critical path has no slack: each day it loses moves the end of the project by one day. »

d)

True. count holds 0, 1, 2 and 3 when the Yes exit is taken, and the test fails at 4: the Yes exit is taken 4 times, the No exit once.

A diamond with one exit, or with two exits and no labels, leaves the reader unable to tell where each answer goes.

e)

False. The two programs differ only at 75.00: free with >= 75, not free with > 75. 74.99 and 75.01 get the same answer from both: 1 order out of 3.

Correct statement: « Whether an order of exactly 75 dollars ships free is the client's decision: the programmer asks it during the analysis. »

Exercise 9: Problem: prompts and messages that meet a specification, on a parcel locker

10 answers to check

A parcel locker follows this specification: « The locker asks for the 6-digit pickup code printed on the delivery notice. An entry that does not have 6 characters is refused with a message that says how many characters were typed, and it does not use a try. A wrong code uses one of the 3 tries, and the screen says how many are left. The right code opens door 14. After 3 wrong codes, the locker locks for 10 minutes and says so. »

A teacher gives the skeleton below, with two blanks to fill, at lines 5 and 7.

Python
CODE = '482913'                                        # line 1
tries_left = 3                                         # line 2
opened = False                                         # line 3
while tries_left > 0 and not opened:                   # line 4
    entry = input(________)                            # line 5
    if len(entry) != 6:                                # line 6
        ________                                       # line 7
    elif entry == CODE:                                # line 8
        print('Door 14 is open.')                      # line 9
        opened = True                                  # line 10
    else:                                              # line 11
        tries_left = tries_left - 1                    # line 12
        print('Wrong code. Tries left:', tries_left)   # line 13
if not opened:                                         # line 14
    print('Locked for 10 minutes.')                    # line 15
  • a) Which prompt fills the blank of line 5, according to the specification?
  • b) Which line fills the blank of line 7? After an entry of 5 characters, how many tries are left?
  • c) With the blanks filled, a user types 482931, then 48291, then 482193, then 482913. How many messages does the locker display, prompts not counted? How many tries are left at the end? Does door 14 open?
  • d) Another user types 111111, 222222, 12, then 333333. How many messages does the locker display, prompts not counted? Which one is the last?
  • e) A student moves line 12 to the top of the loop body, just before line 5, so that every entry uses a try. For the entries 4829, 48291, 4829130, then 482913, does door 14 open? Which sentence of the specification does his version break?

Type your answers, the page tells you right or wrong 0/10

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) 'Enter the 6-digit pickup code from your notice: '
  • b) print('A pickup code has 6 characters. You typed', len(entry)); 3 tries
  • c) 4 messages; 1 try left; yes
  • d) 5 messages; Locked for 10 minutes.
  • e) no; an entry that does not have 6 characters does not use a try

An interface meets its specification when each prompt says what to type and each message says what happened, in the words of the user. In this skeleton the logic is given; the two blanks are the parts the user reads.

a)

The specification asks for the 6-digit pickup code printed on the notice: the prompt names the format, 6 digits, and where to find the code.

'Code? ' and 'Input: ' leave the user to guess what to type.

b)

The message must say how many characters were typed: print('A pickup code has 6 characters. You typed', len(entry)) does, and it also says what was expected. 'Error' says nothing of the kind, and the message of line 13 would announce a lost try where none is lost.

Line 12 is not reached for a wrong length: 3 tries are still left.

c)

482931 has 6 characters and is not the code: tries_left = 2, and the locker displays Wrong code. Tries left: 2.

48291 has 5 characters: the length message, no try used. 482193 is wrong: tries_left = 1.

482913 is the code: Door 14 is open., opened = True, and the loop ends. Line 15 is skipped, since opened is True.

4 messages, 1 try left, and door 14 opens.

In Java, two strings are compared with equals(), not ==: entry.equals(CODE).

d)

111111 and 222222: two wrong codes, 2 then 1 try left. 12: the length message, no try used. 333333: wrong, 0 tries left.

The loop ends, since tries_left > 0 is False, and opened is False: the locker displays Locked for 10 minutes.

5 messages, the last one Locked for 10 minutes.

e)

With tries_left = tries_left - 1 at the top of the loop, each entry uses a try before its length is checked: 4829, 48291 and 4829130 use the three tries, and the loop ends before the right code can be typed. Door 14 does not open, and the user reads Locked for 10 minutes.

The version breaks the sentence « an entry that does not have 6 characters does not use a try ». Moving one line changed what the user lives through; each sentence of a specification needs its own case before the program is accepted.

Python
CODE = '482913'
tries_left = 3
opened = False
while tries_left > 0 and not opened:
    entry = input('Enter the 6-digit pickup code from your notice: ')
    if len(entry) != 6:
        print('A pickup code has 6 characters. You typed', len(entry))
    elif entry == CODE:
        print('Door 14 is open.')
        opened = True
    else:
        tries_left = tries_left - 1
        print('Wrong code. Tries left:', tries_left)
if not opened:
    print('Locked for 10 minutes.')

Exercise 10: Problem: a Gantt chart, two milestones and a PERT estimate

9 answers to check

A Grade 11 class writes an app to sign laptops out of the classroom cart and back in, in a project led by the teacher. The table gives the tasks, in days. The Gantt chart below is the schedule a student drew from it: one bar per task, days counted from the start of the project, and two milestones marked with a diamond, the specification signed and the release of the app.

TaskWorkDaysMust follow
T1Specification3none
T2Design: flow charts and structure chart3T1
T3Code the sign-out module5T2
T4Code the return module4T2
T5Write the test plan2T1
T6Testing3T3, T4, T5
T7Release: install the app on the classroom tablet1T6
0246810121416days from the start of the projectT1 SpecificationT2 DesignT3 Sign-out moduleT4 Return moduleT5 Test planT6 TestingT7 Releasespecification signedreleaseMilestonesThe schedule drawn by a student
  • a) According to the chart as drawn, on which day does the coding of the sign-out module end? On which day is the release?
  • b) Which bar breaks a rule of the table?
  • c) In the corrected schedule, on which day is the release? Which tasks form the critical path?
  • d) In the corrected schedule, what is the slack of T4? Of T5?
  • e) The team is unsure about T3 and gives three estimates: 3 days at best, 5 days most likely, 13 days at worst. The PERT method takes the expected duration (o + 4m + p) / 6, where o, m and p are the best, most likely and worst estimates. What expected duration does it give for T3? With that duration, on which day is the release?

Type your answers, the page tells you right or wrong 0/9

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) day 11; day 14
  • b) T6, Testing: it starts on day 10, before T3 ends on day 11
  • c) day 15; T1, T2, T3, T6, T7
  • d) 1 day; 6 days
  • e) 6 days; day 16

A Gantt chart puts each task on a line of days: a bar starts when the task can start and lasts its duration, so the chart shows at a glance what runs at the same time. The dependencies, though, are in the table, and a bar drawn too early is a schedule the team cannot follow. A milestone has no duration: it is a date, drawn as a diamond.

a)

The bar of T3 runs from day 6 to day 11.

The release diamond sits at the end of T7, on day 14.

b)

T6 must follow T3, T4 and T5. T3 ends on day 11, so testing cannot start on day 10: the bar of T6 starts one day too early.

T4 ending before T3 breaks nothing, since both follow T2 only and run at the same time. T5 starts on day 3, when T1 ends, as the table allows.

c)

Corrected, T6 runs from day 11 to day 14 and T7 from day 14 to day 15: the release is on day 15 (solution figure).

The longest chain is T1, T2, T3, T6, T7: 3 + 3 + 5 + 3 + 1 = 15 days, the critical path. The chain through T4 lasts 14 days, the chain through T5 lasts 3 + 2 + 3 + 1 = 9 days.

Pitfall: reading the end of the project off a bar drawn too early. The chart said day 14; the dependencies say day 15.

d)

T4 ends on day 10 and T6 starts on day 11: 1 day of slack, 15 − 14.

T5 ends on day 5: 6 days of slack, 15 − 9.

e)

(3 + 4 × 5 + 13) / 6 = (3 + 20 + 13) / 6 = 36 / 6 = 6 days.

T3 is on the critical path, with no slack: one day more on T3 moves the release from day 15 to day 16.

The worst case, 13 days, pulls the estimate above the most likely duration, 5 days: the PERT estimate leaves room for what can go wrong.

0246810121416days from the start of the projectT1 SpecificationT2 DesignT3 Sign-out moduleT4 Return moduleT5 Test planT6 TestingT7 Releasespecification signedreleaseMilestonesCorrected schedule: red, the critical path, 15 daysT6 moved to days 11 to 14, after T3; T7 and the release move one day later
Something missing from this set? A type of exercise your teacher gives, a problem you are stuck on, a mistake you spotted: tell me, I read every request.

Sending goes through your free space: that is how I can answer you and tell you when the exercise is added. An email is enough, no password. Create your space. Rather not create an account? Write to me directly.

What is it about?
I read every request myself, nobody else sees it. No need to write your name or your school.
When your request is dealt with, you hear about it by email and in your space.

By sending, you agree that I read your request to answer it. It is kept with your account, erased with it, and never published: privacy policy.

© Ahmed Squalli Houssaini. Exercise set published at www.letuteurscientifique.ca/en/exercices/ics3u-software-development-life-cycle. Free for personal and classroom use; republishing it elsewhere requires written permission (legal notice).

Preparing for an ICS3U unit test?

I tutor Grade 11 computer science in English or in French, online. Get in touch for a first session: specifications, flow charts and schedules come back in every project of the course.

Site by Studio Squalli