Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1

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 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

3 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

4 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

5 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

6 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…)

7 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.

8 Example 2: merging files 5.Delete OLDLIST 6.Delete ADDLIST 7.Rename NEWLIST, calling it OLDLIST

9 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


Download ppt "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."

Similar presentations


Ads by Google