Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth...

29
Chapter 2: Beginning the Problem- Solving Process Introduction to Programming with C++ Fourth Edition

Transcript of Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth...

Page 1: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Chapter 2:Beginning the Problem-Solving

Process

Introduction to Programming with C++

Fourth Edition

Page 2: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 2

Objectives

• Explain the problem-solving process used to create a computer program

• Analyze a problem• Complete an IPO chart• Plan an algorithm using pseudocode and

flowcharts• Desk-check an algorithm

Page 3: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 3

Problem Solving/Solving Everyday Problems

• Steps include:– Analysis

– Planning

– Review

– Implementation

– Evaluation

– Modification

Page 4: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 4

Analysis and Planning

Page 5: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 5

Modified Algorithm

Page 6: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 6

Creating Computer Solutions to Problems

Page 7: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 7

Analyzing the Problem

• Purpose of analyzing the problem:– to determine the goal

– to determine the items needed to achieve the goal

Page 8: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 8

Analyzing the Problem (continued)

Page 9: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 9

IPO (Input, Processing, Output) Charts

• Used by programmers to organize and summarize the results of a problem analysis

• To determine input:– Search the problem specification for an answer to

the following question: What information will the computer need to know to print, display, or store the output items?

Page 10: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 10

IPO Chart with Input and Output

Page 11: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 11

Determining Important Information

• If you are not sure if a piece of information is important, ask yourself this question: If I didn’t know this information, could I still solve the problem?

• When reading a problem specification, it helps to use a pencil to lightly cross out unnecessary information

Page 12: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 12

Problem Specification

Page 13: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 13

Problem Specification Lacking Information

Page 14: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 14

Problem Specification with Input not Stated

Page 15: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 15

Planning the Algorithm

• Processing item - an intermediate value that the algorithm uses when processing the input into the output

• Pseudocode - a tool programmers use to help them plan an algorithm

• Flowchart - uses standardized symbols to show the steps the computer needs to take to accomplish the program’s goal

Page 16: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 16

Completed IPO Chart

Page 17: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 17

IPO Chart with Flow Chart

Page 18: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 18

Flowchart Symbols

• Flowlines - used to connect symbols

• Start/stop symbol (oval) – indicates beginning of flowchart

• Process symbols (rectangles) – used to represent tasks such as calculations

• Input/output symbol (parallelogram) - used to represent input tasks

Page 19: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 19

Solving Sarah’s Problem

Page 20: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 20

IPO Chart for Problem Specification

Page 21: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 21

Hints for Planning Algorithms

Page 22: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 22

Desk-Checking the Algorithm

• Reasons for desk-checking:– To verify that the program is not missing any

steps

– To verify that the existing steps are correct and in the proper order

Page 23: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 23

Desk-Check Table with New Weekly Pay

Page 24: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 24

Results of Second Desk-Check

Page 25: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 25

The Gas Mileage Problem

Page 26: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 26

The Gas Mileage Problem (continued)

• Analyze the problem looking for nouns and adjectives that represent both input and output

• Output should answer the following question: What does the user want to see printed on paper, displayed on the screen, or stored in a file?

• Input should answer the following question: What information will the computer need to know to print, display, or store the output items?

Page 27: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 27

IPO Chart

Page 28: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 28

Completed Desk-Check Table

Page 29: Chapter 2: Beginning the Problem-Solving Process Introduction to Programming with C++ Fourth Edition.

Introduction to Programming with C++, Fourth Edition 29

Summary

• Explain the problem-solving process used to create a computer program

• Complete an IPO chart• Use algorithms (pseudocode) and flowcharts• Use desk-checking techniques