L061 Algorithms, Part 3 of 3 Topics Top down-design Structure charts Reading Sections 1.4 - 1.5, 3.3.

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.
1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
3.1.3 Program Flow control_1 Understand the need for structure Breaking things down.
Chapter 6 Problem Solving and Algorithm Design. 6-2 Chapter Goals Determine whether a problem is suitable for a computer solution Describe the computer.
Basics of Computer Programming Web Design Section 8-1.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
CS 201 Functions Debzani Deb.
Structured Programming structured programming: A technique for organizing and coding computer programs in which a hierarchy of modules is used, each having.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Chapter 2: Algorithm Discovery and Design
CS 201 Functions Debzani Deb.
Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved.
Programming Fundamentals (750113) Ch1. Problem Solving
Chapter 1 Program Design
Problem Solving Chapter 2. What is an algorithm? n A solution to a problem that is: –Precise –Effective –Terminating.
Chapter 4 Sec. 4.1, 4.2, 4.4 Procedures (User-defined)
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
1 Chapter 2 Problem Solving Techniques INTRODUCTION 2.2 PROBLEM SOLVING 2.3 USING COMPUTERS IN PROBLEM SOLVING : THE SOFTWARE DEVELOPMENT METHOD.
The Program Design Phases
Algorithms IV: Top-Down Design
The Art of Programming Top-Down Design. The Art of Problem Solving The art of problem solving is the transformation of an English description of a problem.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 02.
Chapter 2: Developing a Program Prelude to Programming Concepts and Design Copyright © 2001 Scott/Jones, Inc.. All rights reserved. 1 Chapter 2 Developing.
Structured Programming Defn: This is an approach to program development that produces programs of high quality that are easy to test, debug, modify and.
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.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition.
Invitation to Computer Science, Java Version, Second Edition.
First Steps in Modularization Simple Program Design Third Edition A Step-by-Step Approach 8.
Array Processing.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Practice and Evaluation. Practice Develop a java class called: SumCalculator.java which computes a sum of all integer from 1 to 100 and displays the result.
INTRODUCTION TO COMPUTING CHAPTER NO. 04. Programming Languages Program Algorithms and Pseudo Code Properties and Advantages of Algorithms Flowchart (Symbols.
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.
กระบวนการแก้ปัญหาด้วย คอมพิวเตอร์ 3 พฤษภาคม :00-17:00.
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.
Lecture 13: 10/10/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
CS221 Algorithm Basics. What is an algorithm? An algorithm is a list of instructions that transform input information into a desired output. Each instruction.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
1 CS161 Introduction to Computer Science Topic #9.
1 5.4 Modular Design Top-Down Design Structured Programming Advantages of Structured Programming.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
Top-down approach / Stepwise Refinement & Procedures & Functions.
Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School Unit 2 Software Development Process Topic.
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Recursion.
1 UMBC CMSC 104, Section Fall 2002 Functions, Part 1 of 3 Topics Top-down Design The Function Concept Using Predefined Functions Programmer-Defined.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
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
Algorithms and Problem Solving
Algorithms IV Top-Down Design.
Basics of Computer Programming
Algorithms IV Top-Down Design.
Algorithm development
Programming Problem steps must be able to be fully & unambiguously described Problem types; Can be clearly described Cannot be clearly described (e.g.
CMSC201 Computer Science I for Majors Lecture 11 – Program Design
Basics of Computer Programming
Basics of Computer Programming
Chapter 6 : Algorithm Development
UMBC CMSC 104 – Section 01, Fall 2016
Algorithms IV Top-Down Design.
Algorithms and Problem Solving
Algorithms, Part 3 of 3 Topics Top down-design Structure charts
Top-Down Design & JSP Skill Area Part D
Algorithms, Part 3 of 3 Topics Top down-design Reading
Presentation transcript:

L061 Algorithms, Part 3 of 3 Topics Top down-design Structure charts Reading Sections , 3.3

L062 Pseudocode and Then Some We can write an algorithm for finding the average of two integers: Read integer, from the user Read integer from the user = + = / 2 Display “The average of “and” “is”. Steps 1, 2 & 5 will make use of code found in the run-time library

L063 Investigating Steps 1 & 5 Read integer, from the user Display “The average =”. Are these really single steps? Each of them is really a sequence of steps, a subprogram. Two kinds of subprograms: o Functions - an answer is returned to the main program. o Procedures - no answer returned to the main program

L064 Functions and Procedures In our example, the function that gets a value from the user and the procedure that prints out the answer were already written. Many times it is necessary for us to write our own procedures or functions.

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

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

L067 An Example of Top-Down Design Scenario: 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.

L068 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

L069 Pseudocode for our Main Program Start Call Read Customer List Call Sort on customer list by zipcode Call Select Target List from Customer List using only zipcode Call Print Envelopes using target list Stop

L0610 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 pseudocode for each of the steps (modules) in the hierarchy.

L0611 Structured Programs We will use top-down design for all of our 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.

L0612 Another Example Problem: Write a program that draws this picture of a house.

L0613 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

L0614 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

L0615 Another Observation There are three windows to be drawn. Main Draw Windows Draw Outline... Draw Window 3 Draw Window 2 Draw Window 1 (x 1,y 1 )(x 2,y 2 )(x 3,y 3 )

L0616 Code Reuse 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.

L0617 The Pseudocode Start Call DrawHouseOutline giving a position Call DrawChimney giving position Call DrawDoor giving position Call DrawWindow giving (x,y) position #1 Call DrawWindow giving (x,y) position #2 Call DrawWindow giving (x,y) position #3 Stop

L0618 Summary Use the divide-and conquer strategy to split the original problem into a series of sub-problems. Consider each sub-problem separately and split them further into smaller sub-problems, progressively refining the previous versions in a top-to-bottom manner, until no further refinement is possible. Stop the process when you have the pseudocode that can be directly translated in a C program.

L0619 Exam 1 All material before this page is “fair game” for the midterm. Exam 1 will be given Tuesday October 11th If you know that you can not make the exam, tell me today after class, so that we can schedule a possible makeup. Only very SERIOUS conflicts will be honored.