Make your own free website on Tripod.com

Tutorial 2

Beginning the Problem-Solving Process

Overview

This tutorial stresses the importance of proper design in the programming process. It also shows where design fits in the overall process of problem-solving. Different methods of designing the solution to the problem are shown (flowcharts & pseudocode). The author does an excellent job with her examples of implementing the problem-solving process.

Objectives

After completing the tutorial, the student will be able to:

Lecture Notes

Review algorithm definition

Remember from Tutorial 1 that an algorithm is the step-by-step instructions that accomplish a task. Another definition of an algorithm could be a series of finite steps that solve a problem. Remember that an algorithm should not consist of an infinite number of steps.

IPO chart

Programmers use IPO (Input, Processing, Output) charts to organize and summarize the results of a problem analysis. After determining what output is expected from the problem solution, you can then ask what information will the computer need to know in order to either print, display, or store the output items, therefore determining the input needed. Once determining what input you have and what output you want, the processing portion of the chart can be determined. Intermediate processing items (other than input or output) would be determined along with the algorithm.

Problem-Solving Process

Following a proper problem-solving process is critical to successfully completing a task. The problem-solving process presented by the author is a six-step process. These six steps are as follows:

1. Analyze the problem
2. Plan the algorithm
3. Desk-check the algorithm
4. Code the algorithm into a program
5. Desk-check the program
6. Evaluate and modify (if necessary) the program

The first step in the problem-solving process is the most import, which is analyzing the problem. For if the problem is not analyzed and determined properly, you may be solving a different problem than you intended to do. In analyzing the problem the Input and Output section on the IPO chart can be used to determine what you have and what you want.

After properly analyzing the problem a good design solution is essential to the success of solving the task at hand. First the IPO chart can be further utilized by identifying processing items, which are intermediate values used to process the input and output. Once these processing items are determined an algorithm can be created using one of two basic methods: flowcharts and pseudocode. A flowchart uses symbols to direct flow and structures, while pseudocode is an English-like version of a flowchart (like a table of contents).

Once an algorithm has been established it should be desk-checked. In order to do this a set of sample data must be created. Then the sample data can be used to test the algorithm verifying order and accuracy of the steps.

After determining that the algorithm is a viable one, the algorithm must be converted into a computer program. Note that up until this point that we did not have to know which programming language was being used. Before converting the algorithm into an actual program, one must understand the syntax and control structures used in the language that has been selected.

Just like the algorithm was desk-checked, the first draft of the program should also be desk-checked. Once again a set of sample data must be created, and a walk through of the code be conducted to verify the order and accuracy of steps.

Once the desk-check of the program has been conducted one must evaluate and modify the program if necessary. Even though a great deal of time was put into the problem-solving process up to this point, some details could have still been overlooked. Therefore based upon the desk checking that was performed once the program was coded, you may need to make program code changes or changes to the original algorithm. This is why a great deal of time needs to be spent on the original algorithm.

Utilizing existing algorithms

Use any previous algorithms/programs to your advantage. If the current task is identical or similar in any way to any previous task, do not waste time reinventing the design/code when it already exists.

Additional Activities

Solutions to Questions   

1. b analyze the problem  11. d pseudocode

2. b output                                    

 12. a Flowcharts
3. a input    13 c process
4. b output   14. a input/output

5. b IPO charts                                 

15. d (rectangle)
6. a input         16. c (parallelogram)
7. b entering the input items into the computer  17. b (oval)
8. c Processing 18. c desk-check the algorithm
9. c both what is to be calculated and how to calculate it  19. d all of the above
10. c entering the input items, then processing the input items, and then displaying, printing, or storing the output items

       Solutions to Concept Lesson Exercises

Input

Processing

Output

original number

Processing items: none

Algorithm:

  1. enter original number
  2. calculate the squared value by multiplying the original number by itself
  3. display the squared value

squared value

original number

squared value

4

6

16

36

2.

Input

Processing

Output

state1 sales

state2 sales

commission rate

Processing items: none

Algorithm:

  1. enter state1 sales, state2 sales, and commission rate
  2. calculate the total commission by adding the state1 sales to the state2 sales, and then multiplying the result by the commission rate
  3. display the total commission

commission

state1 sales

state2 sales

commission rate

commission

1000

3000

2000

2500

.05

.06

150

330

3.

    Input

    Processing

    Output

    sales

    commission rate

    Processing items: none

    Algorithm:

    commission

    sales

    commission rate

    commission

    2000

    5000

    .1

    .06

    200

    300

Input

Processing

Output

region1 sales

region2 sales

region3 sales

region1 increase

region2 increase

region3 increase

Processing items: none

Algorithm:

  1. enter the region1 sales, region2 sales, region3 sales, region1 increase, region2 increase, and region3 increase
  2. calculate the region1 projected sales by multiplying the region1 sales by the region1 increase, and then add the result to the region1 sales
  3. calculate the region2 projected sales by multiplying the region2 sales by the region2 increase, and then add the result to the region2 sales
  4. calculate the region3 projected sales by multiplying the region3 sales by the region3 increase, and then add the result to the region3 sales
  5. display the region1 projected sales, region2 projected sales, and region3 projected sales

region1 projected sales

region2 projected sales

region3 projected sales

region1 sales

region2 sales

region3 sales

region1 increase

region2 increase

region3 increase

region1 projected saes

region2 projected sales

region3 projected sales

10000

5000

3000

2000

6000

1000

.1

.02

.09

.03

.1

.02

11000

5100

3270

2060

6600

1020

 

Input

Processing

Output

original number

Processing items: none

Algorithm:

  1. enter original number
  2. if the original number is less than or equal to zero

display an error message

otherwise

calculate the squared value by multiplying the original number by itself

display the squared value

squared value

original number

squared value

10

-3

100

 
  1. Results of desk-checking the incorrect algorithm.

beginning inventory

amount sold

amount returned

ending inventory

50

10

2

58

Changes made to the original algorithm are shaded in the IPO chart.

Input

Processing

Output

beginning inventory

amount sold

amount returned

Processing items: none

Algorithm:

  1. enter the beginning inventory, amount sold, and amount returned
  2. calculate the ending inventory by subtracting the amount sold from the beginning inventory, then adding the amount returned to the result
  3. display the ending inventory

ending inventory

Results of desk-checking the correct algorithm

beginning inventory

amount sold

amount returned

ending inventory

50

10

2

42

 

  1. Changes made to the original algorithm are shaded in the IPO chart.

Input

Processing

Output

hours worked

rate of pay

Processing items: none

Algorithm:

  1. enter the hours worked and rate of pay
  2. calculate the gross pay by multiplying the hours worked by the rate of pay
  3. display the gross pay

gross pay

Solutions to Application Lesson Exercises

  1. Input

    Processing

    Output

    room length

    room width

    ceiling height

    single roll coverage

    Processing items:

    room perimeter

    wall area

    Algorithm:

    number of single rolls

Input

Processing

Output

beginning balance

monthly deposits

monthly withdrawals

Processing items: none

Algorithm:

  1. enter the beginning balance, monthly deposits, and monthly withdrawals
  2. calculate the ending balance by adding the monthly deposits to the beginning balance, and then subtracting the monthly withdrawals from the result
  3. display the ending balance

ending balance

beginning balance

monthly deposits

monthly withdrawals

ending balance

2000

500

775

100

1200

610

1575

-10

 

Input

Processing

Output

first number

second number

third number

Processing items: none

Algorithm:

  1. enter the first number, second number, and third number
  2. calculate the average by adding together the first number, second number, and third number, and then dividing the sum by 3
  3. display the average

average

first number

second number

third number

average

25

10

76

15

33

20

44.6666

15

 

4.

Input

Processing

Output

original price

discount rate

Processing items: none

Algorithm:

  1. enter original price and discount rate
  2. calculate the sales discount by multiplying the original price by the discount rate
  3. calculate the new price by subtracting the sales discount from the original price
  4. display the sales discount and the new price

sales discount

new price

original price

discount rate

sales discount

new price

100

50

.25

.1

25

5

75

45

5.

Input

Processing

Output

number of envelopes

number of pages

charge per envelope

charge per page

Processing items:

total envelope charge

total page charge

 

Algorithm:

  1. enter the number of envelopes, number of pages, charge per envelope, and charge per page
  2. calculate the total envelope charge by multiplying the number of envelopes by the charge per envelope
  3. calculate the total page charge by multiplying the number of pages by the charge per page
  4. calculate the total due by adding the total envelope charge to the total page charge
  5. display the total due

total due

number of envelopes

number of pages

charge per envelope

charge per page

total envelope charge

total page charge

total due

100

10

100

15

.10

.20

.25

.30

10

2

25

4.50

35

6.50

 

6.

Input

Processing

Output

first seminar attendees

second seminar attendees

seminar price

Processing items: none

Algorithm:

  1. enter the first seminar attendees, second seminar attendees, and seminar price
  2. calculate the total attendees by adding together the first seminar attendees and the second seminar attendees
  3. calculate the cost by multiplying the total attendees by the seminar price
  4. display the total attendees and the cost

total attendees

cost

first seminar attendees

second seminar attendees

seminar price

total attendees

cost

10

30

10

10

200

100

20

40

4000

4000

7.

Input

Processing

Output

hours worked

hourly pay rate

FWT rate

FICA rate

state rate

Processing items: total taxes

Algorithm:

  1. enter the hours worked, hourly pay rate, FWT rate, FICA rate, and state rate
  2. calculate the gross pay by multiplying the hours worked by the hourly pay rate
  3. calculate the FWT by multiplying the gross pay by the FWT rate
  4. calculate the FICA by multiplying the gross pay by the FICA rate
  5. calculate the state tax by multiplying the gross pay by the state rate
  6. calculate the total taxes by adding together the FWT, FICA, and state tax
  7. calculate the net pay by subtracting the total taxes from the gross pay
  8. display the gross pay, FWT, FICA, state tax, and net pay

gross pay

FWT

FICA

state tax

net pay

 

hours worked

hourly pay rate

FWT rate

FICA rate

state rate

total taxes

gross pay

FWT

FICA

state tax

net pay

20

30

6

10

.2

.2

.08

.08

.02

.04

36

96

120

300

24

60

9.60

24

2.40

12

84

204

 

8.

Input

Processing

Output

side1

side2

side3

side4

Processing items: none

Algorithm:

  1. enter side1, side2, side3, and side4
  2. calculate the perimeter by adding together side1, side2, side3, and side4
  3. display the perimeter

perimeter

 

The desk-check data may vary.

side1

side2

side3

side4

perimeter

10

20

6

10

5

15

8

20

29

65

9.

Input

Processing

Output

diameter

price per foot

Processing items: none

Algorithm:

circumference

total price

The desk-check data may vary.

diameter

price per foot

circumference

total price

35

7

2

3

109.90

21.98

219.80

65.94

 

10.

Input

Processing

Output

length in feet

width in feet

price per square foot of tile

Processing items: none

Algorithm:

  1. enter the length in feet, width in feet, and price per square foot of tile
  2. calculate the area by multiplying the length in feet by the width in feet
  3. calculate the total price by multiplying the area by the price per square foot of tile
  4. display the area and total price

area

total price

 

The desk-check data may vary.

length in feet

width in feet

price per square foot of tile

area

total price

10

20

6

10

5

3

60

200

300

600

11.

Input

Processing

Output

length in feet

width in feet

height in feet

Processing items: none

Algorithm:

  1. enter the length in feet, width in feet, and height in feet
  2. calculate the volume by multiplying the length in feet by the width in feet, and then multiplying the result by the height in feet
  3. display the volume

volume

 

The desk-check data may vary.

length in feet

width in feet

height in feet

volume

100

2

30

3

3

4

9000

24

 

12.

Input

Processing

Output

old pay1

old pay2

old pay3

raise rate

Processing items: none

Algorithm:

  1. enter the old pay1, old pay2, old pay3, and raise rate
  2. calculate the new pay1 by multiplying the old pay1 by the raise rate, and then adding the result to the old pay1
  3. calculate the new pay2 by multiplying the old pay2 by the raise rate, and then adding the result to the old pay2
  4. calculate the new pay3 by multiplying the old pay3 by the raise rate, and then adding the result to the old pay3
  5. display the new pay1, new pay2, and new pay3

new pay1

new pay2

new pay3

 

old pay1

old pay2

old pay3

raise rate

new pay1

new pay2

new pay3

7.55

8.00

10.00

6.50

10.30

7.25

.02

.02

7.70

8.16

10.20

6.63

10.51

7.40

13.

Input

Processing

Output

semester hours

tuition per semester hour

room and board fee

Processing items: none

Algorithm:

total cost

semester hours

tuition per semester hour

room and board fee

total cost

20

14

100

100

3000

3000

5000

4400

 

14.

Input

Processing

Output

hours worked

hourly pay rate

Processing items: overtime pay

Algorithm:

  1. enter the hours worked and hourly pay rate
  2. if the hours worked is greater than 40
  3. calculate the overtime pay as follows: first subtract 40 from the hours worked, then multiply the result by the hourly pay rate divided by 2

    calculate the gross pay by multiplying the hours worked by the hourly pay rate, and then adding the overtime pay to the result

    otherwise

    calculate the gross pay by multiplying the hours

    worked by the hourly pay rate

  4. display the gross pay

gross pay

 

hours worked

hourly pay rate

overtime pay

gross pay

20

43

6

10

15

120

445

15. Changes to the original algorithm are shaded in the figure.

Input

Processing

Output

number

Processing items: none

Algorithm:

  1. enter the number
  2. calculate the cube of the number by multiplying the number by itself three times
  3. display the cube of the number

cube of the number

number

cube of the number

4

64

 

16. Changes to the original algorithm are shaded in the figure.

Input

Processing

Output

original price

discount rate

Processing items: none

Algorithm:

  1. enter the original price and the discount rate
  2. calculate the discount by multiplying the original price by the discount rate
  3. calculate the sale price by subtracting the discount from the original price
  4. display the discount and the sale price

discount

sale price

original price

discount rate

discount

sale price

100

.25

25

75