Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
105 views

Programming Handout - Problem Solving

The document discusses problem solving and programming. It begins by asking how you would respond to a problem, then notes that computers solve problems quickly and accurately by following the precise instructions in programs. The steps of problem solving are defined as: 1) define the problem, 2) analyze the problem, 3) find a solution, 4) evaluate solutions, 5) represent the best solution as an algorithm, 6) test the program, and 7) document the program. Key aspects of defining and analyzing a problem are determining the inputs, outputs, and processing needed. An IPO chart can be used to map these components. The document also discusses variables, operators, and provides examples of completing IPO charts for problems of calculating a total and

Uploaded by

Tahjay Kerr
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views

Programming Handout - Problem Solving

The document discusses problem solving and programming. It begins by asking how you would respond to a problem, then notes that computers solve problems quickly and accurately by following the precise instructions in programs. The steps of problem solving are defined as: 1) define the problem, 2) analyze the problem, 3) find a solution, 4) evaluate solutions, 5) represent the best solution as an algorithm, 6) test the program, and 7) document the program. Key aspects of defining and analyzing a problem are determining the inputs, outputs, and processing needed. An IPO chart can be used to map these components. The document also discusses variables, operators, and provides examples of completing IPO charts for problems of calculating a total and

Uploaded by

Tahjay Kerr
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Munro College

Information Technology
4th Form March 2021
Topic: Introduction to Problem Solving

When you are faced with a problem, which of the following would you do? 
1. Quit?
2. Yell for ‘Mummy’?
3. Migrate?
4. Pout?
5. Try to find a solution?

Computers are designed to solve problems speedily and accurately. Although computers are used
to solve problems, they do not have brains. They cannot think. A computer is a moron – it simply
does exactly what we tell it to do. This is why the role of the computer programmer is so
important. Instructions are given to the computer in the form of computer programs. A computer
program is a finite set of precise instructions, written in a programming language. Before we
write a computer program, we first have to find a way to solve the problem at hand.

STEPS TO PROBLEM SOLVING


 
1. Define the problem
2. Analyze the problem
3. Find a solution to the problem
4. Evaluate alternative solutions
5. Represent the most efficient solution as an algorithm (a series of steps to solve the
problem)
6. Test and debug the program
7. Document the program (A written explanation of how the program works and how to use
it.

DEFINING THE PROBLEM


 
One of the biggest challenges faced in problem-solving is to understand the problem to be solved.
Defining the program can be accomplished by breaking down the problem into three key
components:
1. What is given (input)
2. The tasks that must be performed (processing)
3. The expected results (output)

ANALYSING THE PROBLEM AND DEFINING DIAGRAM


 
When analyzing the problem an IPO Chart is used. This is a table with three columns used to
represents the three components: input, processing and output.

 Input Processing Output 


     

* Input refers to the source data provided to solve the give problem. - Easily identified by the
keywords – given, read or accept, input, prompt.

* Output refers to the end result required - keywords are print, display, produce, output,
list, show, suitable label, appropriately labelled, or “caption

*Processing is the actions must be performed to achieve the required output - it answers the
question: What must I do with the inputs in order to produce the desired result. Check for words
like “calculate” and “compute, add, sum, subtract, divide average”.

*Storage is a temporary location that stores data.

TO ANALYSE A PROBLEM DO THE FOLLOWING:

1. Determine the input that is needed.


2. Use variable names to store any input. E.g. number, date, last name
3. Determine the output that is required.
4. Use variable names to store any output.
5. Determine the processing that is required.

VARIABLES:  In the computer, values are stored in memory locations. In order to keep track of
where our values are stored, we need to place a label or identifier in a particular memory
location. The label or identifier is called a variable.
A variable is a symbolic name assigned to a memory location that stores a particular value.
E.g. name= Mary Jane.
It is good practice to choose variable names that reflect the kind of data that is being stored,
e.g. num1- it is going to store the first number entered by the user
age1- it is going the store the first age entered by the user.
Sum- it is going to store the total of a group of numbers.
Average- it is going to store the average of a group of numbers, grades or scores
A variable or constant can only store one piece of data.

INITALIZATION OF VARIABLES
  Variables that are used as counters or used to store totals should always be assigned an initial
value of zero (0) before they are used. This is called initialization, e.g.  Count = 0.
The initialization ensures that the variable is cleared of any values that may have been assigned in
a previous execution of the program
 For example 1st Execution: Count= 1, 2nd Execution: Count=0

OPERATORS
Operators can be either Mathematical (computes arithmetic expressions) or Logical (performs
decision making where the answer is either True or False).
 
The Mathematical operators are:

Symbol Description Example


+ Addition 2+1
- Subtraction 6 -2
/ Divide By 54/2
* Multiplication 4*9
^ Raised to the power to 4^2
DIV Integer Division 17 DIV 5 = 3
MOD Remainder 17 MOD 5 = 2
 
 
 
 
 
 
 
 
 
 
 
The Logical operators are:
 
Symbol Description Example
= Equal to x = 35
> Greater than 8>5
< Less than 3<9
>= Greater than or equal to x>=8
<= Less than or equal to x<=60
<> Not equal to 40 <>34
 
 
 
 

The logical operators compare Boolean expressions (an expression that results in a value of either


TRUE or FALSE) and returns a Boolean result (either TRUE or FALSE).
Additional Logical operators include:
1. AND – performs logical conjunction on two Boolean expressions. If both expressions are
True, then the ‘AND’ operator returns True. If either or both expressions are to False,
then And returns False value.
2. OR - The Or operator performs logical disjunction on two Boolean expressions. If either
expression are to True, OR returns True. If neither expression evaluates
to True, OR returns False.
3. NOT - yields the opposite of the expression it evaluates. If the expression evaluates
to True, Not yields False; if the expression evaluates to False, Not yields True
 
AND 
Expression A   Expression  B   Result  
False False False
False True False
True False False
True True True
 
OR
Expression A   Expression B   Result  
False False False
False True True
True False True
True True True
 

NOT
Expression  Result  
False True
True False

FOLLOW THESE 5 STEPS TO COMPLETE AN IPO CHART:

1. Write the input (what is needed from the person using the algorithm).
2. Write the output (the end result that is stated in the problem).
3. In the processing column write "get" and anything that is under the input column.
4. Ask yourself the following question. “What do I have to do with the inputs in order to
produce the desired output?” Then write down what should be done. 
5. Write "display" and anything under the Output column. 

PROBLEM 1:
Write a solution to read three numbers and calculate and print the total. 

Input Processing Output


3 numbers Get 3 numbers print Total

Add 3 numbers

INPUT PROCESSING OUTPUT

num1, num2, num3 Get num1,num2, num3 Total


Total = num1+num2+num3
user: 10 35
20
5 10+ 20+5= 35
 
 

PROBLEM 2:
Given three integers representing the age of three boys respectively, write a solution to find their
average age.
 

Input Processing Output


3 ages Get 3 ages print average

Add 3 ages

Divide total of ages by 3

INPUT PROCESSING OUTPUT

age1, age2, age3 Sum= age1+age2+age3 Average


Average= sum/3

 
 

You might also like