top-down design outline the project in the boldest steps possible, do not worry about how to achieve...

9

Upload: paulina-mathews

Post on 19-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Top-down design Outline the project in the boldest steps possible, do not worry about how to achieve each step uIt is to be expected that some steps are
Page 2: Top-down design Outline the project in the boldest steps possible, do not worry about how to achieve each step uIt is to be expected that some steps are

Top-down design

• Outline the project in the boldest steps possible, do not worry about how to achieve each step

It is to be expected that some steps are beyond your immediate understanding

• Consider each step, refine it as much as possible, go to another step if you run into trouble

• If you are dealing with a computer program, continue to refine until the steps are program language commands

Page 3: Top-down design Outline the project in the boldest steps possible, do not worry about how to achieve each step uIt is to be expected that some steps are

Example 1: opening a restaurant

• Choose a Theme• Pick a neighborhood• Find a Site• Compute the Costs• Acquire the Funds• Build it• Get the Staff• Prepare the Ads

Compute the Costs

- Hire an architect, get the building costs

- Determine costs of utilities, trash removal, etc.

- Evaluate Labor Costs

- Evaluate Publicity Costs

Page 4: Top-down design Outline the project in the boldest steps possible, do not worry about how to achieve each step uIt is to be expected that some steps are

Example 2: merging files

• Consider a large file of names and phone numbers– a telephone directory for a large city

• Consider a smaller file of new names and phone number which must be added to the original list– new phone numbers added today

• Design a procedure (a program?) that will merge these two files into a new phone directory

Page 5: Top-down design Outline the project in the boldest steps possible, do not worry about how to achieve each step uIt is to be expected that some steps are

Example 2: merging files

1.Alphabetize OLDLIST

2.Alphabetize ADDLIST

3.Create a blank file, call it NEWLIST

4.Merge OLDLIST and ADDLIST into NEWLIST

5.Delete OLDLIST

6.Delete ADDLIST

7.Rename NEWLIST, calling it OLDLIST

Page 6: Top-down design Outline the project in the boldest steps possible, do not worry about how to achieve each step uIt is to be expected that some steps are

Example 2: merging files

1.Alphabetize OLDLIST

(already done, it was yesterday’s output.)

2.Alphabetize ADDLIST

(learn how to sort stuff, too much trouble to describe here.)

3.Create a blank file NEWLIST

(easy to do…)

Page 7: Top-down design Outline the project in the boldest steps possible, do not worry about how to achieve each step uIt is to be expected that some steps are

Example 2: merging files

4.Merge OLDLIST and ADDLIST into NEWLIST

A. read the first item of OLDLIST, call it OLD, read the first item of ADDLIST, call it ADD

B. compare OLD with ADD, write the smaller of them to NEWLIST, read the next item to replace it.

C. if you have not run out of file OLDLIST or ADDLIST, return to B again, otherwise go to D.

D. If you have drained ADDLIST, read the rest of OLDLIST into NEWLIST, if you have drained OLDLIST, read the rest of ADDLIST into NEWLIST.

Page 8: Top-down design Outline the project in the boldest steps possible, do not worry about how to achieve each step uIt is to be expected that some steps are

Example 2: merging files

5.Delete OLDLIST

6.Delete ADDLIST

7.Rename NEWLIST, calling it OLDLIST

Page 9: Top-down design Outline the project in the boldest steps possible, do not worry about how to achieve each step uIt is to be expected that some steps are

int Cube ( int n ){ return n * n * n;

}

• The heading declares the function’s name, specifying its return type and the name and type of each of its parameters

• The body is a compound statement (block) which defines the behavior of the function

Two parts of a function definition

Heading

Body