Algorithms IV Top-Down Design.

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.
A8 – Control Structures if, if-else, switch Control of flow in Java Any sort of complex program must have some ability to control flow.
8 Algorithms Foundations of Computer Science ã Cengage Learning.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
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.
CS 201 Functions Debzani Deb.
1 Chapter 8 Designing Small Programs. 2 A ‘Procedure’ v A set of instructions which describe the steps to be followed in order to carry out an activity.
Chapter 1 Program Design
Structured Program Development in C
Chapter 4 Sec. 4.1, 4.2, 4.4 Procedures (User-defined)
The Program Design Phases
BPC.1 Basic Programming Concepts
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering.
Algorithms IV: Top-Down Design
The University of Texas – Pan American
Structured Programming Defn: This is an approach to program development that produces programs of high quality that are easy to test, debug, modify and.
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.
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
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.
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.
CS221 Algorithm Basics. What is an algorithm? An algorithm is a list of instructions that transform input information into a desired output. Each instruction.
Data Structure and Algorithms. Algorithms: efficiency and complexity Recursion Reading Algorithms.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering Problem Solving and Logic.
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.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
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.
Problem Solving.  Similar to Solving Math Word Problem  Read the Problem  Decide how to go about Solving the Problem  Solve the Problem  Test the.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Software Design and Development Development Methodoligies Computing Science.
Introduction to Computing Science and Programming I
Algorithms and Problem Solving
Possible exam questions with Scenarios
FLOWCHARTS.
Introduction to Programming
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
Print slides for students reference
Designing and Debugging Batch and Interactive COBOL Programs
Problem Solving Techniques
Learning to Program in Python
Learning to Program in Python
Lesson Objectives Aims You should be able to:
Chapter 5: Algorithms Computer Science: An Overview Tenth Edition
Chapter 6 : Algorithm Development
Chapter 3 – Control Structures
Computer Science Testing.
UMBC CMSC 104 – Section 01, Fall 2016
Programming.
Algorithms IV Top-Down Design.
Algorithms and Problem Solving
Lecture 7 Algorithm Design & Implementation. All problems can be solved by employing any one of the following building blocks or their combinations 1.
Loops.
CS 144 Advanced C++ Programming January 31 Class Meeting
Algorithms, Part 3 of 3 Topics Top down-design Structure charts
Module 6 Working with Functions
Unit 6 - Subroutines.
Software Development Techniques
Algorithms, Part 3 of 3 Topics Top down-design Reading
CMSC201 Computer Science I for Majors Lecture 12 – Program Design
Computational Thinking (How to think like a computer scientist)
Structural Program Development: If, If-Else
Computer Science: An Overview Tenth Edition
Presentation transcript:

Algorithms IV Top-Down Design

Pseudocode and Then Some We can write an algorithm for finding the average of two integers: Get an integer, num1, from the user Get an integer, num2, from the user sum = num1 + num2 average = sum / 2 Print “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 Print “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.

More Problem Solving 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