Topdown design - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Topdown design

Description:

... of names and phone numbers. a telephone directory for a large city ... that will merge these two files into a new phone directory. Example 2: merging files ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 10
Provided by: jayso
Category:

less

Transcript and Presenter's Notes

Title: Topdown design


1
(No Transcript)
2
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

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 yesterdays 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
Two parts of a function definition
  • int Cube ( int n )
  • return n n n
  • The heading declares the functions 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

Heading
Body
Write a Comment
User Comments (0)
About PowerShow.com