1. Trang chủ
  2. » Giáo Dục - Đào Tạo

Tài liệu Top-Down Design pptx

16 358 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Top-down design
Trường học University of Maryland
Chuyên ngành Computer Science
Thể loại Lecture slides
Năm xuất bản 2001
Định dạng
Số trang 16
Dung lượng 49,5 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Advantages of Top-Down Design• Breaking the problem into parts helps us to clarify what needs to be done.. • Breaking the problem into parts allows more than one person to work on the

Trang 1

Top-Down Design

Topics

Reading

Trang 2

Top-Down Design

impossible to solve because it is so complex

Examples:

top-down design, also known as stepwise

refinement, where

Trang 3

Advantages of Top-Down Design

• Breaking the problem into parts helps us to

clarify what needs to be done.

• At each step of refinement, the new parts

become less complicated and, therefore,

easier to figure out.

• Parts of the solution may turn out to be

reusable.

• Breaking the problem into parts allows more

than one person to work on the solution.

Trang 4

An Example of Top-Down Design

• Problem:

waterproofing

code 21222)

customers in that area

Trang 5

The Top Level

code 21222 from the sorted customer list

Main

Read

Trang 6

Another Level?

• Should any of these steps be broken down

further? Possibly.

• How do I know? Ask yourself whether or

not you could easily write the algorithm for

the step If not, break it down again.

• When you are comfortable with the

breakdown, write the pseudocode for each

of the steps (modules) in the hierarchy.

• Typically, each module will be coded as a

separate function.

Trang 7

Structured Programs

programming projects

using only the three kinds of control structures, sequential, selection and

repetition, are called structured programs.

modify, and are also easier for other programmers to understand

Trang 8

Another Example

• Problem: Write a program that draws this

picture of a house.

Trang 9

The Top Level

Main

Draw Chimney

Draw Door

Draw Windows Draw

Outline

Trang 10

Pseudocode for Main

Call Draw Outline

Call Draw Chimney

Call Draw Door

Call Draw Windows

Trang 11

• The door has both a frame and knob We

could break this into two steps.

Main

Draw Chimney

Draw Door

Draw Windows

Draw

Outline

Draw Door Frame KnobDraw

Trang 12

Pseudocode for Draw Door

Call Draw Door Frame

Call Draw Knob

Trang 13

Another Observation

• There are three windows to be drawn.

Main

Draw Windows

Draw

Draw Window 3

Draw Window 2 Draw

Window 1

Trang 14

One Last Observation

• But don’t the windows look the same?

They just have different locations.

• So, we can reuse the code that draws a

window.

place the window in the correct location, or

correct location each time (we will see how to

do this later)

This is an example of code reuse.

Trang 15

Reusing the Window Code

Main

Draw Windows

Draw

Draw a Window

Trang 16

Pseudocode for Draw Windows

Call Draw a Window, sending in Location 1

Call Draw a Window, sending in Location 2

Call Draw a Window, sending in Location 3

Ngày đăng: 13/12/2013, 22:15

TỪ KHÓA LIÊN QUAN

w