Title: Lecture 2 Problem Solving
1Lecture 2Problem Solving
- ENGR17 Engineering Programming
- Section 1
- Fall 2001
9/11/01
2Outline
- Six problem-solving steps used to create a
computer program - Complete an IPO chart
- Plan an algorithm using pseudocode and flowcharts
- Desk-check an algorithm
- Code and execute the algorithm
3Creating Computer Solutions
4Analyzing the Problem
- Determine the output(goal or purpose of solving
the problem) - Determine the input(information needed to reach
the goal) - Use an IPO (Input, Processing, Output) chart to
organize and summarize the results of problem
analysis
5Analyzing the Problem
6Analyzing the Problem
- Most difficult problem-solving step
- Problem specification can contain too much or too
little information - Distinguish between information that is missing
in the problem specification, and information
that is not explicitly stated
7Analyzing the Problem
8IPO Chart
9Analyzing the Problem
10Planning the Algorithm
- Algorithm the steps that will transform the
input into the output - Enter input items
- Process the data (usually by doing some
calculations) - Print or display the output items
- Tools
- IPO chart
- Pseudocode
- Flowcharts
11Planning the Algorithm
12Pseudocode Flowcharts
- Use standardized symbols, connected with
flowlines, to show the steps the computer needs
to take to accomplish the programs goal
Start/Stop
Process
Input/Output
13(No Transcript)
14Hints for Writing Algorithms
15Hints for Writing Algorithms
16Hints for Writing Algorithms
17Hints for Writing Algorithms
18Hints for Writing Algorithms
19Desk-checking the Algorithm
- Refers to completing each step in the algorithm
manually, using a set of sample data for input
values - Verifies that the algorithm is not missing steps
- Verifies that the existing steps are correct and
in the proper order - Also called hand-tracing
- Can use a desk-check table
20Desk-checking the Algorithm
21Desk-checking the Algorithm
22Desk-checking the Algorithm
23Problem Solving Summary
- Problem-solving steps used to create a computer
program - Analyze the problem
- Plan the algorithm
- Desk-check the algorithm
- Code the algorithm into a program
- Desk-check the program
- Evaluate and modify the program
- IPO charts
- Planning an algorithm using pseudocode and
flowcharts - Desk-checking an algorithm
continued
24Completing the Problem-Solving Process
25The C Programming Language
- Object-oriented successor to the
procedure-oriented C language - C language
- 1972, Dennis Ritchie, Bell Laboratories
- C
- 1985, Bjarne Stroustrup, Bell Laboratories
- Can be used as a procedural as well as an
object-oriented language
26Requirements for Creating C Program
- Text editor
- Used to enter the C instructions (source code)
- C compiler
- Converts source code into machine code (object
code) - Case sensitive
27Different C Systems
- Integrated Development Environment (IDE)
- Contain editor and compiler in one integrated
environment - Examples Microsoft Visual C, Borland C
Builder - Command-line compilers
- Contain only the compiler
- Require use of general purpose editor (NotePad,
WordPad) to enter program instructions
28Coding the Algorithm
- Coded algorithm a program
- Starting Microsoft Visual C 5.0
29Program Instructions
30C Programs
- Use a precise syntax
- Can include comments (//)
- Contain at least one directive
- Must contain a function named main
31Other Coding Terminology
- Header files (.h)
- Keywords
- Functions and void functions ( and )
- Variables
- Statements ()
- Streams (cout and cin)
- Insertion operators (()
- Stream manipulators
32Evaluating and Modifying the Program
- Testing
- Execute the program and enter sample data
- Valid data
- Invalid data
- Debugging
- Locate and remove errors in a program
- Syntax error
- Logic error
33Executing a C Program
- Before it can be executed, a C program must be
compiled (source code translated into object code)
34After Completing Program
- Assemble external documentation and keep in a
safe place - IPO chart
- Flowchart of pseudocode
- Printout of the program
35Programming Summary
- Origins of the C programming language
- Source code and object code
- Opening a C source file
- Coding an algorithm
- Compiling, building, and executing a C program
- Evaluating and modifying a program