Download presentation
Presentation is loading. Please wait.
Published byRudolph McDaniel Modified over 9 years ago
2
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering Problem Solving and Logic Diagrams Lecture 3
3
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 2Winter Quarter TOOLS FOR PROGRAM DEVELOPMENT A variety of tools and techniques can be used in the process of program development Useful for organizing the tasks in problem solving Many of the tools are focused on the: –development or formulation of algorithms –representation of algorithms –refinement or structuring of algorithms
4
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 3Winter Quarter TOOLS FOR PROGRAM DEVELOPMENT Top-down design technique –Start with overall function and perform several step-wise refinements Pseudo code –Artificial and informal language that helps programmers develop algorithms Logic diagrams –Alternate representations of algorithms including graphic and state representations
5
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 4Winter Quarter TOP-DOWN STEPWISE REFINEMENT Begin with a single statement that conveys the overall function of the program. This is a complete (but simple) representation of the program. Divide this "top" statement into a series of smaller tasks and list them in the order in which they must be performed to produce a first refinement.
6
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 5Winter Quarter TOP-DOWN STEPWISE REFINEMENT Next, refine each of the smaller tasks into yet smaller steps, defining specific "variables" as may be needed in this second refinement. Continue refinement until algorithm is fully developed. When combined with pseudo code, writing the program is normally straightforward.
7
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 6Winter Quarter Top-Down Example The Problem: The students in a class have taken their first quiz. The grades (in the range of 0 to 100) are available. Determine the class average on the quiz. Givens: Grades, Possible range of legitimate grades.
8
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 7Winter Quarter Top-Down Example (continued) Unknowns: How many grades to be averaged? Assumptions: A "grade" not in the range of expected grades could be used to indicate the that all of the legitimate grades have been entered. (Called "sentinel" or "flag".)
9
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 8Winter Quarter Top-Down Example (continued) Using pseudo code, we begin by representing the top: –Determine the class average for the quiz
10
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 9Winter Quarter Top-Down Example (continued) Next, perform the first refinement: –Determine the class average for the quiz Initialize variables Input, sum, and count quiz grades Calculate and print the class average
11
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 10Winter Quarter Top-Down Example (continued) Next, refine each one of these smaller tasks: –Initialize variables Initialize a running total to zero Initialize a grade counter to zero
12
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 11Winter Quarter Top-Down Example (continued) Input, sum, and count quiz grades Input the first grade While the user has not entered the "flag" Add this grade into the running total Add one to the grade counter Input next grade (possibly the "flag")
13
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 12Winter Quarter Top-Down Example (continued) Calculate and print the class average If the grade counter is not zero Set the class average to the running total divided by the grade counter Print the average Else Print "No grades were entered"
14
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 13Winter Quarter Handling Special Cases Notice that the top-down refinement example included the handling of a "special case". Many of you are aware of the special treatment that Windows gives to the extreme "special cases" (sometimes called the BSOD or Blue Screen of Death…)
15
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 14Winter Quarter Handling Special Cases
16
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 15Winter Quarter Some Types of Logic Diagrams Flow Charts -- graphic representation of an algorithm –an aid to writing the program –no formal standards, but common guidelines Action Diagrams -- technique for diagramming of control structures of a program –an outline of the computer application –what things happen, when, where, how many times
17
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 16Winter Quarter Characteristics of Flow Charts Useful tool in program development Not a complete description of program Not only tool to use Made before writing the program Program might differ from flowchart Only executable statements are shown Specific equations and tests not included Every main and sub-program is charted
18
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 17Winter Quarter Flow Charting Symbols The commonly used flowcharting symbols follow Refer to Section 9 of the H192 "Class Notes" for a more complete description of the various flowcharting symbols normally used
19
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 18Winter Quarter Flow Charting Symbols Begin or End a Procedure: "Main Program" "Subprogram" Begin End
20
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 19Winter Quarter Flow Charting Symbols Write to Screen: Read from Keyboard:
21
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 20Winter Quarter Flow Charting Symbols Read from a File: Read from a File with a Check for End-of-File:
22
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 21Winter Quarter Flow Charting Symbols Decision or Selection Structure: General Processing:
23
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 22Winter Quarter Flow Charting Symbols Definite Loop: Indefinite Loop:
24
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 23Winter Quarter Flow Charting Symbols On-Page Connectors: Off-Page Connectors:
25
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 24Winter Quarter Flow Charting Symbols Call (or Invoke) a Subprogram:
26
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 25Winter Quarter Daily Assignment E2 Problem: There are a number of apples in a large box which must be sorted into baskets. An apple is either a "large red" one, a "small red" one, or a "green" one.
27
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 26Winter Quarter Daily Assignment E2 Assumptions: 1.There are 3 empty baskets present and they are labeled: #1 – large red, #2 – small red, #3 – green 2.There are counters of some sort present. 3.The person sorting is not color blind and can tell the difference between large and small apples. 4.Only these three kinds of apples are in the large box.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.