Algorithms IV: Top-Down Design

Slides:



Advertisements
Similar presentations
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.
Advertisements

CMSC 104, Version 9/011 The while Looping Structure Topics The while Loop Program Versatility o Sentinel Values and Priming Reads Checking User Input Using.
CMSC 104, Version 9/011 Arithmetic Operators Topics Arithmetic Operators Operator Precedence Evaluating Arithmetic Expressions In-class Project Incremental.
Coding. Steps to Success 1.Create a PLAN including a detailed statement of requirements (SORs) 2.Write algorithms based on the SORs 3.Write pseudocode.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
0 Advanced Selection CE : Introduction to Software Development Week 3 Lecture 2.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Programming Fundamentals (750113) Ch1. Problem Solving
Chapter 1 Program Design
The Program Design Phases
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering.
CMSC 104, Version 9/01 1 The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 02.
The University of Texas – Pan American
General Programming Introduction to Computing Science and Programming I.
Making a great Project 2 OCR 1994/2360. Analysis This is the key to getting it right. Too many candidates skip through this section. It’s worth 20% of.
System Development Life Cycle. The Cycle When creating software, hardware, or any kind of product you will go through several stages, we define these.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
CMSC 104, Section 301, Fall Lecture 06, 9/18/02 Algorithms, Part 3 of 3 Topics Disk Quota Exceeded. Using Pine. More Algorithms Reading Read.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
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.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
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.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering Problem Solving and Logic.
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.
CMSC 104, Version 9/01 1 Functions, Part 3 of 3 Topics: Coding Practice o In-Class Project: The Box o In-Class Project: Drawing a Rectangle Reading: None.
1 Algorithms Practice Topics In-Class Project: Tip Calculator In-Class Project: Drawing a Rectangle.
CMSC 104, Version 8/061L10ArithmeticOps.ppt Arithmetic Operators Topics Arithmetic Operators Operator Precedence Evaluating Arithmetic Expressions In-class.
Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School Unit 2 Software Development Process Topic.
The Hashemite University Computer Engineering Department
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
Algorithms, Part 3 of 3 Topics In-Class Project: The Box
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
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.
Chapter 1 The Phases of Software Development. Software Development Phases ● Specification of the task ● Design of a solution ● Implementation of solution.
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.
How Computers Solve Problems Computers also use Algorithms to solve problems, and change data into information Computers can only perform one simple step.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Introduction to Computing Science and Programming I
Algorithms and Problem Solving
Algorithms IV Top-Down Design.
2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park
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
2008/09/24: Lecture 6b CMSC 104, Section 0101 John Y. Park
The while Looping Structure
2008/11/12: Lab 5/Lecture 17 CMSC 104, Section 0101 John Y. Park
Chapter 6 : Algorithm Development
Programming Fundamentals (750113) Ch1. Problem Solving
UMBC CMSC 104 – Section 01, Fall 2016
Algorithms IV Top-Down Design.
Algorithms, Part 3 of 3 Topics In-Class Project: The Box
Solutions to In-Class Problems
Algorithms Practice Topics In-Class Project: Tip Calculator
Algorithms and Problem Solving
Functions, Part 4 of 4 Topics: Coding Practice Reading: None
Algorithms, Part 3 of 3 Topics Top down-design Structure charts
Functions, Part 3 of 3 Topics: Coding Practice Reading: None
UMBC CMSC 104 – Section 01, Fall 2016
Software Development Techniques
Algorithms, Part 3 of 3 Topics Top down-design Reading
CMSC201 Computer Science I for Majors Lecture 12 – Program Design
Algorithms, Part 3 of 3 Topics In-Class Project: Tip Calculator
Functions, Part 3 of 4 Topics: Coding Practice Reading: None
Presentation transcript:

Algorithms IV: Top-Down Design Topics more pseudocode problem solving strategies Home-Exercise: The Box Home-Exercise: Drawing a Rectangle Reading None

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

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

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.

Problem Solving Strategies If we look at the problem as a whole; it may seem impossible, because it is so complex. Complex problems can be solved using a Top-Down approach aka Stepwise refinement Break the problem into parts Then break the parts into parts Soon each of the parts will be easy to do

Advantages of Top-down Design Breaking the problem down 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. What if you’ve broken a problem down as much as you can and you still don’t know? Missing information More detail is needed

A Practical Example Scenario: We own a home improvement company We do painting, roofing and basement waterproofing A section of town has recently had flooding We want to send out waterproofing pamphlets to our customers in that area

Our Algorithm Get the customer list from a file Sort the list according to zipcode Make a new file of only the customers with the zipcode 21222 from the sorted customer list Print an envelope for each customer in the new file

Single steps ? None of our steps are single steps Employ Top-Down Design Start with the large idea and break into large parts Each part will end up being a function or a procedure

Pseudocode for our Main Program Call <Get Customer List> Call <Sort on customer list> by zipcode Call <Make Target List> from customer list using only zipcode 21222 Call <Print Envelopes> using target list

The Next Step Write algorithms for each of the functions or procedures. These may include steps that are really several steps, too. Give names to these new functions and procedures. Write algorithms for them. Continue this process until done.

Structured Programs Top-down design will be used for all of our programming projects This is the standard way of writing programs. Programs produced using this method and using only the 3 kinds of structures, sequential, selection and repetition are called structured programs. Structured programs are easier to modify later and also easier for other programmers to understand.

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

The Algorithm Draw the outline of the house Draw the chimney Draw the door and doorknob Draw the windows

Similarities All three windows are identical. They are simply in different positions. We can write a function called <DrawWindow> that will draw one window at a position we specify and call it 3 times with the three different positions. Another benefit of Top-down design is reuseability. We are reusing the code for <DrawWindow>.

The Pseudocode Call <DrawHouseOutline> giving a position Call <DrawChimney> giving position Call <DrawDoor> giving position Call <DrawWindow> giving position #1 Call <DrawWindow> giving position #2 Call <DrawWindow> giving position #3

Problem Solving Techniques We have investigated three problem solving techniques: Multiple attacks Working backwards Top-down design

Writing Algorithms from Scratch Do the following 2 projects as exercises at home: Given a problem statement, write the corresponding generic algorithm for the solution. Use the following procedure: Determine the algorithm inputs and outputs Pseudocode a rough algorithm Complete the pseuodocode

The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also display the box dimensions. Error checking should be done to be sure that all box dimensions are greater than zero.

Drawing a Rectangle Problem: Write an interactive program that will draw a solid rectangle of asterisks (*). The program must also display the dimensions of the rectangle. Error checking must be done to be sure that the dimensions are greater than zero.