You are on page 1of 26

CREATING COMPUTER

SOLUTIONS TO PROBLEMS
How To Create a Computer Solution to a
Problem
ANALYZE THE
PROBLEM
PLAN THE
ALGORITHM

DESK CHECK
STEP 1 – ANALYZE THE
PROBLEM
STEP 1 – ANALYZE THE
PROBLEM
You cannot solve a problem unless you understand it, and you
cannot understand a problem unless you analyze it—in other
words, unless you identify its important components. Th e two
most important components of any problem are the problem’s
output and its input. The output is the goal of solving the
problem, and the input is the item or items needed to achieve
the goal. When analyzing a problem, you always search first for
the output and then for the input.
EXAMPLE INPUT PROCESS OUTPUT

IPO CHART Num1 (variable) Addition Sum


ADDING Num2

TWO 1 Sum = 1 + 1 2
NUMBERS 1
INPUT PROCESS OUTPUT

Sale price Multiply the sale price COST


Sale tax rate by the state sales tax
IPO CHART rate

Cost = sale price +


sales tax

Addison O’Reilly wants a program


that calculates and displays the cost
of a 4K Ultra HD TV, which is finally
on sale at one of the stores in her area.
The program should calculate the cost
by multiplying the sale price by the
state sales tax rate and then adding
the result to the sale price.
INPUT PROCESS OUTPUT

n of students dividing the number of average number of


IPO CHART n of teachers students by the
number of teachers.
Students per teacher
(Average)

Average = S / T

The principal of a local school wants


a program that displays the average
number of Students per teacher at
the school. The principal will enter
the number of students enrolled and
the number of teachers employed. The
student-teacher ratio is obtained
by dividing the number of students by
the number of teachers.
STEP 2 —PLAN THE
ALGORITHM
STEP 2 —PLAN THE
ALGORITHM

The second step in the problem-solving process is to plan the


algorithm that will transform the problem’s input into its
output. You record the algorithm in the Processing column of
the IPO chart. Each instruction in the algorithm will describe an
action that the computer needs to take in order to derive the
output from the input. Therefore, each instruction should start
with a verb.
Step 1: Start
EXAMPLE
Step 2: Declare variables num1, num2
AGLORITHM and sum.
ADDING TWO Step 3: Read values for num1 and num2.
NUMBERS Step 4: Add num1 and num2 and assign
the result to variable sum.
sum=num1+num2
Step 5: Display sum
Step 6: Stop
Step 1: Start
ALGORITH Step 2: Declare variables average,
students and teachers
M Step 3: Read values for students and
teachers
Step 4: Calculate average number of
The principal of a local school wants students per teacher by dividing the
a program that displays the average
number of Students per teacher at the
number students by the number of
school. The principal will enter the teachers. (average = students /
number of students enrolled and the teachers)
number of teachers employed. The
student-teacher ratio is obtained
Step 5: Display average
by dividing the number students at by Step 6: Stop
the number of teachers.
FLOWCHART
START

Declare variables num1, num2


and sum.
ADDING TWO NUMBERS

Step 1: Start
Read/Enter num1
Step 2: Declare variables
and num2
num1, num2 and sum.
Step 3: Read values for num1
and num2.
Step 4: Add num1 and num2
Sum = num1 + num2
and assign the result to
variable sum.
sum=num1+num2
Step 5: Display sum
Step 6: Stop Display sum

END
START
A
Addison O’Reilly wants
a program that calculates Declare variables cost, sale
price, sales tax and sales rate.
and displays the cost… cost = sale price + sales
tax
Step 1: Start
Step 2: Declare variables Read/Enter sales
cost, sale price, sales tax tax rate, sales price
and sales rate. Display COST
Step 3: Calculate sales tax
by multiplying sale price by
sales tax rate.
(sales tax = sale price * sales sales tax = sale price *
tax) sales tax END
Step 4: Calculate cost by
adding sale price plus sales
tax rate. A
(cost = sale price + sales tax)
Step 5: Display Cost
Step 6: End
START
The principal of a local
school wants a program that
displays… Declare variables average,
students and teachers
Step 1: Start
Step 2: Declare variables
Enter/Read values
average, students and for students and
teachers teachers
Step 3: Read values for
students and teachers
Step 4: Calculate average = students
teachers)
average number of
students per teacher
by dividing the number
students by the number Display average
of teachers. (average =
students / teachers)
Step 5: Display average END
Step 6: Stop
Step 1: Start
AGLORITHM Step 2: Declare participants as int
Write an algorithm and draw a
Step 3: Read/Enter participants
flowchart for an alternative selection
structure that displays one of two
Step 4: If participants is equal or greater
different messages, depending on the
than 75 then display “Use Kanton room”
number of seminar participants stored
else if participants is less than 75 then
in an int variable named participants.
display “Use Harris room”
Display the message “Use the Kanton Step 5: Display Output
room” when the number of seminar
Step 6: End
participants is at equal or greater than
75. When less than 75, display the
message “Use the Harris room”.
START

Step 1: Start Declare participants as


Step 2: Declare int
participants as int
Step 3: Read/Enter
participants Enter/Read
Step 4: If participants is participants
equal or greater than 75
then display “Use
Kanton room” else if TRUE FALSE
participants is less than If participants >= 75
75 then display “Use
Harris room” “Use Kanton “Use Harris
Step 5: Display Output room” room”
Step 6: End

END
DESK CHECK
DESK CHECK First number
1
Second number
1
Sum
2
ADDING TWO NUMBERS
3 5 8
Step 1: Start 100 125 225
Step 2: Declare variables
num1, num2 and sum.
Step 3: Read values for num1
and num2.
Step 4: Add num1 and num2
and assign the result to
variable sum.
sum=num1+num2
Step 5: Display sum
Step 6: Stop
Addison O’Reilly wants
a program that
calculates and displays
Sale price Sales ax rate Sales tax cost
the cost 2300 .05 115 2415
Step 1: Start 1500 .05 75 1575
Step 2: Declare variables 3500 .10 350 3850
cost, sale price, sales tax and
sales rate.
Step 3: Calculate sales tax by
multiplying sale price by
sales tax rate.
(sales tax = sale price * sales
tax)
Step 4: Calculate cost by
adding sale price plus sales
tax rate.
(cost = sale price + sales tax)
Step 5: Display Cost
Step 6: End
The principal of a local
school wants a program
that displays… Students Teachers Average
1200 60 20
Step 1: Start 2500 100 25
Step 2: Declare variables
average, students and
teachers
Step 3: Read values for
students and teachers
Step 4: Calculate average
number of students per
teacher by dividing the
number students by the
number of teachers.
(average = students /
teachers)
Step 5: Display average
Step 6: Stop
Celsius Calculation Output/Fahrenheit

32 (37 / 5) x 9 + 32 89.6

(Divide by 5, then multiply by


9, then add 32)

100 (120 / 5) x 9 + 32 212

(Divide by 5, then multiply by


9, then add 32)
END OF LESSON
Key term
• Algorithm—the set of step-by-step instructions that accomplish a
task.
• Desk-checking—the process of manually walking through each of the
instructions in an algorithm; also called hand-tracing.
• Flowchart—a tool that programmers use to help them plan (or
depict) an algorithm; consists of standardized symbols connected by
flowlines
• Hand-tracing—another term for desk-checking
• Input—the items a program needs in order to achieve the output
key terms
• Invalid data—data that the algorithm is not expecting the user to
enter.
• IPO—an acronym for Input, Processing, and Output
• IPO chart—a chart that some programmers use to organize and
summarize the results of a problem analysis
• Output—the goal of solving a problem; the items the user wants to
display, print, or store.
• Pseudocode—a tool that programmers use to help them plan an
algorithm; consists of short English statements; means false code
key terms
• Start/stop symbol—the oval symbol in a fl owchart; used to mark the
beginning and end of the flowchart
• Valid data—data that the algorithm is expecting the user to enter
• Process symbol—the rectangle symbol in a fl owchart; used to
represent tasks such as calculations.
• Input/output symbol—the parallelogram in a flowchart; used to
represent input and output tasks.
• Flowlines—the lines that connect the symbols in a flowchart

You might also like