Upload
garrett-clarke
View
19
Download
0
Tags:
Embed Size (px)
DESCRIPTION
What is a Problem?. A problem is a circumstance for which we need to develop a solution to get to some goal or provide the means to some end. Types of Problems. Informal Problems - PowerPoint PPT Presentation
Citation preview
8/26 & 8/28/2002 Pamela Brauda 1
What is a Problem?
A problem is a circumstance for which we need to develop a solution to get to some goal or provide the means to some end.
8/26 & 8/28/2002 Pamela Brauda 2
Types of Problems
Informal Problemswe do NOT necessarily find solutions by precisely specifying the initial conditions, the desired results, or the actions (process) by which we achieve the desired results
8/26 & 8/28/2002 Pamela Brauda 3
Types of Problems
Formal Problems – the kind that can be solved by writing a program for a computer
Problems of synthesis: have specific initial conditions and specific plans of actions (processes), but specify only the general form of the result {Trip: Jax, drive, West Coast}Problems of analysis: the initial conditions and results are known, but not a specific plan of action (process) {Trip: Jax, L.A.}
8/26 & 8/28/2002 Pamela Brauda 4
Types of Problems
***All problems solved with the aid of computers are problems of synthesis
***The programmer transforms the problem from one of analysis to one of synthesis
8/26 & 8/28/2002 Pamela Brauda 5
Solving a Problem
1. Understand the problem2. Devise a plan – major steps to accomplish our goal
Divide the problem into segmentsDesign a solutionConsider alternatives and refine solution
8/26 & 8/28/2002 Pamela Brauda 6
Solving a Problem
3. Carry out the plan (implement)4. Look back
Did you really solve the problem? If not, return to Step 1
8/26 & 8/28/2002 Pamela Brauda 7
7 Steps in Program Development
Define the problemUse a Defining Diagram
Inputs
Outputs
Processing steps to produce the required output
8/26 & 8/28/2002 Pamela Brauda 8
7 Steps in Program Development
Outline the solutionBreak the problem up into smaller steps
Major processing steps involved
Major subtasks
Major control structures (e.g. repetition loops)
Major variables and record structures
Mainline Logic
Use a hierarchy or structure chart
8/26 & 8/28/2002 Pamela Brauda 9
7 Steps in Program Development
Develop the outline into an algorithm
An algorithm is a set of precise steps that describe exactly the tasks to be performed and the order in which they are to be carried outThink ‘recipe for making French toast as given to a robot cook’Pseudocode is how we represent algorithms
8/26 & 8/28/2002 Pamela Brauda 10
7 Steps in Program Development
Test the algorithm for correctnessDesk checking to identify logic errors
Walk through each step of the algorithm
Keep track of all major variables
Use sample data that tests boundary conditions
8/26 & 8/28/2002 Pamela Brauda 11
7 Steps in Program Development
Code the algorithm into a specific programming language
NEVER approach the keyboard without a planCode-as-you-go results in wasted time and effort
8/26 & 8/28/2002 Pamela Brauda 12
7 Steps in Program Development
Run the program with test dataSyntax errors show up at compile time
Typos, punctuation, grammar
Logic errors appear at run time2 + 3 = 6???
Sometimes undetected if testing isn’t thorough
8/26 & 8/28/2002 Pamela Brauda 13
7 Steps in Program Development
Document and maintain the programExternal documentation
Hierarchy or structure charts, pseudocode, test data and sample results
Internal documentation‘Flower Boxes’ at the beginning of each module or functionInline comments describing the variables and what should be happeningSample program following COBOL Standards
8/26 & 8/28/2002 Pamela Brauda 14
Structured Programming
Top-down DevelopmentStart out with a general solutionBreak down the solution into more detailed steps (modules)Step-wise refinement – moving from general to specific
8/26 & 8/28/2002 Pamela Brauda 15
Structured Programming
Modular DesignGroup similar tasks together
Reading a file, checking for end of file, verifying the item read is valid
Printing page headings or totals
Enables several people to work as a team, with each person working on a separate function
Input/Output
Sorting, Updating
Calculating
8/26 & 8/28/2002 Pamela Brauda 16
Structured Programming
The Structure TheoremEliminated the GOTO statementAll programs can be written with 3 basic control structures
Sequence
Selection, or IF-THEN-ELSE
Repetition, or DO-WHILE
8/26 & 8/28/2002 Pamela Brauda 17
Algorithm to add two numbers
CalculatorTurn onPress 1st numberPress ‘+’Press 2nd numberPress ‘=‘
ComputerInput 1st numberInput 2nd numberAddPrint result (sum)
8/26 & 8/28/2002 Pamela Brauda 18
Pseudocode
Structured English used to express an algorithm
Use indentation for logical flowOne instruction per line
Six basic algorithm structures – roughly matching the six basic computer operations
8/26 & 8/28/2002 Pamela Brauda 19
Pseudocode
Getting data into the computerRead student name {from a file}Get system date {from the system}Read number_1, number_2 {file}Get tax_code {from the keyboard}
8/26 & 8/28/2002 Pamela Brauda 20
Pseudocode
Getting results from the computer
Print ‘Program Completed’ {printer}Write customer record to file {disk}Display ‘End of Data’ {screen}
8/26 & 8/28/2002 Pamela Brauda 21
Pseudocode
Doing the mathAdd number to totaltotal = total + numberCompute C = (F – 32) * 5/9Symbols okay to use: +, -, *, /, (, )
8/26 & 8/28/2002 Pamela Brauda 22
Pseudocode
Assigning a value to a variableSet Count to 0Initialize Totals to zeroTotal = cost + tax
8/26 & 8/28/2002 Pamela Brauda 23
Pseudocode
Comparing two variablesIf-Then-ElseIF Student is part-time THEN
Add 1 to part-time count
ELSEAdd 1 to full-time count
ENDIF
8/26 & 8/28/2002 Pamela Brauda 24
Pseudocode
Repeat a group of actions: DO-WHILE, FOR Loop, DO Loop
WHILE student_total < 50 DORead student recordPrint student name, address to reportAdd 1 to student_total
ENDWHILE