CMSC 104, Version 8/061L17Top-DownDesign.ppt Top-Down Design Topics Top-Down Design Top-Down Design Examples The Function Concept Reading Sections 3.1.

Slides:



Advertisements
Similar presentations
Modular Design Using Subroutines (functions later)
Advertisements

CMSC 104, Version 9/011 Top-Down Design Topics Top-Down Design Top-Down Design Examples The Function Concept Reading Sections 3.9, 3.10.
A complete citation, notecard, and outlining tool
Chapter 2: Modularization
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
Basics of Computer Programming Web Design Section 8-1.
Computer Science: A Structured Programming Approach Using C Converting File Type A rather common but somewhat trivial problem is to convert a text.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Recursion.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
CS 201 Functions Debzani Deb.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
CS 201 Functions Debzani Deb.
Copyright © 2003 Pearson Education, Inc. Slide 1.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Chapter 1 Program Design
Algorithms IV: Top-Down Design
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
Simple Program Design Third Edition A Step-by-Step Approach
Top-Down Design and Modular Development
Program Design CMSC 201. Motivation We’ve talked a lot about certain ‘good habits’ we’d like you guys to get in while writing code. There are two main.
Modular Programming. Modular Programming (1/6) Modular programming  Goes hand-in-hand with stepwise refinement and incremental development  Makes the.
First Steps in Modularization Simple Program Design Third Edition A Step-by-Step Approach 8.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
Computer Science: A Structured Programming Approach Using C1 4-6 Scope Scope determines the region of the program in which a defined object is visible.
Top-Down Design and Modular Development. The process of developing methods for objects is mostly a process of developing algorithms; each method is an.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
General Algorithms for Common Business Problems Simple Program Design Third Edition A Step-by-Step Approach 10.
CS221 Algorithm Basics. What is an algorithm? An algorithm is a list of instructions that transform input information into a desired output. Each instruction.
1 CS161 Introduction to Computer Science Topic #9.
1 5.4 Modular Design Top-Down Design Structured Programming Advantages of Structured Programming.
Data Structure and Algorithms. Algorithms: efficiency and complexity Recursion Reading Algorithms.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
L061 Algorithms, Part 3 of 3 Topics Top down-design Structure charts Reading Sections , 3.3.
Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School Unit 2 Software Development Process Topic.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Recursion.
Introduction to OOP CPS235: Introduction.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
1 UMBC CMSC 104, Section Fall 2002 Functions, Part 1 of 3 Topics Top-down Design The Function Concept Using Predefined Functions Programmer-Defined.
CMSC 2021 Software Development. CMSC 2022 Software Development Life Cycle Five phases: –Analysis –Design –Implementation –Testing –Maintenance.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Algorithms and Flowcharts
CMSC 104, Version 8/061L24Searching&Sorting.ppt Searching and Sorting Topics Sequential Search on an Unordered File Sequential Search on an Ordered File.
Algorithms and Problem Solving
Visit for more Learning Resources
Algorithms IV Top-Down Design.
Algorithm development
2011/11/20: Lecture 15 CMSC 104, Section 4 Richard Chang
2008/11/05: Lecture 15 CMSC 104, Section 0101 John Y. Park
2008/11/12: Lab 5/Lecture 17 CMSC 104, Section 0101 John Y. Park
Searching and Sorting Topics Sequential Search on an Unordered File
Chapter 4 Functions Objectives
Chapter 6 : Algorithm Development
Topics discussed in this section:
Problem Solving: Structure Charts
UMBC CMSC 104 – Section 01, Fall 2016
Algorithms IV Top-Down Design.
Algorithms and Problem Solving
Functions, Part 4 of 4 Topics: Coding Practice Reading: None
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
1-6 Midterm Review.
Algorithms, Part 3 of 3 Topics Top down-design Structure charts
Top-Down Design & JSP Skill Area Part D
Module 6 Working with Functions
Functions, Part 3 of 3 Topics: Coding Practice Reading: None
2008/11/05: Lecture 15 CMSC 104, Section 0101 John Y. Park
Algorithms, Part 3 of 3 Topics Top down-design Reading
Presentation transcript:

CMSC 104, Version 8/061L17Top-DownDesign.ppt Top-Down Design Topics Top-Down Design Top-Down Design Examples The Function Concept Reading Sections

CMSC 104, Version 8/062L17Top-DownDesign.ppt Top-Down Design If we look at a problem as a whole, it may seem impossible to solve because it is so complex. Examples: o writing a tax computation program o writing a word processor Complex problems can be solved using top- down design, also known as stepwise refinement, where o We break the problem into parts o Then break the parts into parts o Soon, each of the parts will be easy to do

CMSC 104, Version 8/063L17Top-DownDesign.ppt 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.

CMSC 104, Version 8/064L17Top-DownDesign.ppt An Example of Top-Down Design Problem: o We own a home improvement company. o We do painting, roofing, and basement waterproofing. o A section of town has recently flooded (zip code 21222). o We want to send out pamphlets to our customers in that area.

CMSC 104, Version 8/065L17Top-DownDesign.ppt The Top Level Get the customer list from a file. Sort the list according to zip code. Make a new file of only the customers with the zip code from the sorted customer list. Print an envelope for each of these customers. Main SortSelectPrintRead

CMSC 104, Version 8/066L17Top-DownDesign.ppt 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.

CMSC 104, Version 8/067L17Top-DownDesign.ppt Code Reuse A primary goal of software engineering is to write error-free code. Code reuse, reusing program fragments that have already been written and tested whenever possible, is one way to accomplish this goal. Those fragments are written as functions and can be used and reused just like the printf( ) function that you have already been using.

CMSC 104, Version 8/068L17Top-DownDesign.ppt Structured Programs We will use top-down design for all remaining programming projects. This is the standard way of writing programs. Programs produced using this method and using only the three kinds of control structures, sequential, selection and repetition, are called structured programs. Structured programs are easier to test, modify, and are also easier for other programmers to understand.

CMSC 104, Version 8/069L17Top-DownDesign.ppt Another Example Problem: Write a program that draws this picture of a house.

CMSC 104, Version 8/0610L17Top-DownDesign.ppt The Top Level Draw the outline of the house Draw the chimney Draw the door Draw the windows Main Draw Chimney Draw Door Draw Windows Draw Outline

CMSC 104, Version 8/0611L17Top-DownDesign.ppt Pseudocode for Main Call Draw Outline Call Draw Chimney Call Draw Door Call Draw Windows

CMSC 104, Version 8/0612L17Top-DownDesign.ppt Observation 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 Draw Knob

CMSC 104, Version 8/0613L17Top-DownDesign.ppt Pseudocode for Draw Door Call Draw Door Frame Call Draw Knob

CMSC 104, Version 8/0614L17Top-DownDesign.ppt Another Observation There are three windows to be drawn. Main Draw Windows Draw Outline... Draw Window 3 Draw Window 2 Draw Window 1

CMSC 104, Version 8/0615L17Top-DownDesign.ppt 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. o Simply copy the code three times and edit it to place the window in the correct location, or o Use the code three times, “sending it” the correct location each time (we will see how to do this later). This is an example of code reuse.

CMSC 104, Version 8/0616L17Top-DownDesign.ppt Reusing the Window Code Main Draw Windows Draw Outline... Draw a Window

CMSC 104, Version 8/0617L17Top-DownDesign.ppt 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

CMSC 104, Version 8/0618L17Top-DownDesign.ppt Pseudocode for Draw Windows (cont’d) In the case of the Draw Windows function, we have to supplement (or augment) the information with the specific location each time we use that function. This is a very common thing to do. On our structure, we can add the information about the argument(s) to help document the design. We can also add the return information, if any.

CMSC 104, Version 8/0619L17Top-DownDesign.ppt Reusing the Window Code - 2 Main Draw Windows Draw Outline... Draw a Window location void

CMSC 104, Version 8/0620L17Top-DownDesign.ppt Writing The Code Now we can write the shell of the program: #include int main( void ) { return 0; }

CMSC 104, Version 8/0621L17Top-DownDesign.ppt Writing The Code (cont’d) Looking at the structure chart, we can now design the prototypes: void drawAWindow( int xCoord, int yCoord); Now we can add it to the shell of our program.

CMSC 104, Version 8/0622L17Top-DownDesign.ppt Writing The Code (cont’d) Now we can write the shell of the program: #include void drawAWindow( int xCoord, int yCoord); int main( void ) { return 0; }

CMSC 104, Version 8/0623L17Top-DownDesign.ppt Writing The Code (cont’d) Using the prototype, we can add the shell of the function to the program. We would do the same thing for each function in our structure chart. Structure of the program is: o #include o #define o Prototypes o Functions (It does not matter which function comes first, but normally, people put main( ) first.

CMSC 104, Version 8/0624L17Top-DownDesign.ppt Writing The Code (cont’d) #include void drawAWindow( int xCoord, int yCoord); int main( void ) { return 0; } void drawAWindow( int xCoord, int yCoord) { }

CMSC 104, Version 8/0625L17Top-DownDesign.ppt Writing The Code (cont’d) Now we can see that the program would really be more useful and give a better solution, if all of our functions were given the the location for each thing that is to be drawn. Remember the general solution is the best solution

CMSC 104, Version 8/0626L17Top-DownDesign.ppt Good Programming Practices Review Use top-down design. Use Incremental programming. Reuse code. Use stepwise refinement. Use structured programming: o Sequential o Selection o Repetition