0% found this document useful (0 votes)
39 views

Problem Solving

Uploaded by

yousseifindx5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Problem Solving

Uploaded by

yousseifindx5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Problem Solving [

By the end of this chapter, student will be able to:

Define the problem.


Identify the problem solving stages.
Write steps to solve the problem “Algorithm”.
Draw flowcharts that reflect the steps of the solution.

(5)
In your daily life, you may face a lot of problems through various activities that contain many
problems.

Problem is a situation that requires a solution or an objective you want to achieve through
following consecutive steps sequentially.

Problem Solving is the steps, activities, and processes to be done to reach an output or
objective.

Consider the following problem:


The problem is: Baking a cake according to certain specifications, input available are the
ingredients (such as eggs, flour, milk …etc.), then followed by activities or procedures that
should be done sequentially to get the cake in suitable shape.

Dear student
In this book, we focus on Problem Solving techniques
using the computer.

First: Problem Definition:


Problem definition implies the identification of required outputs, available inputs and,
arithmetic and logical operations to be executed.

Second: Algorithm Preparation:


Algorithm is one of the methods used to solve a problem through logically arranged
procedures.
After identifying and analyzing the problem, outputs and inputs; a plan in the form of a
series of successive steps is made which is called an (Algorithm), devised by the
Mathematician and the founder of Algebra “Muḥammed Ibn Mūsā al-Jwārizmī”.

One of the methods to represent algorithm is flowchart.

(6)
Flowchart:
It is a diagram that uses standard graphical symbols to illustrate the sequence of steps
required for solving a problem or specific question.
Some advantages of flowcharts:
 Facilitating the reading and understanding of the problem and illustrating to the
programmer what must be done.
 Useful to explain the program to others
 helping in documenting the program in better manner, especially if the program is
complicated

Third: Program design


Having drawn a “Flowchart” to solve the problem, using a computer; we have to
translate this flowchart into one of the programming languages.

Fourth: Program Testing


During writing a program we unintentionally make some mistakes e.g. writing a minus
sign (-) instead of (+). We cannot detect errors unless we begin entering data to the program
with previously known results; and compare the results of the current program to those of the
well-known results and so you can discover the errors and correct them.

Fifth: Program Documentation


This step includes writing all steps taken for solving the problem that include: given
Input, output, plan for solving the problem, drawn flowchart, programming language used
for coding , instructions, date of last modification of the program and, people who contribute
to the program development process . This is done to have the program documented to go
back for feedback and correction. This documentation is beneficial when more than one
person participate in writing or modifying the program.

Dear Student
After we have learnt about the problem-solving
stages and flowcharts, we will learn about some standard
(agreed on symbols), Special symbols can also be used for
exceptional cases.

Here are some of the most commonly used symbols as shown in table (1-1)

(7)
Significance symbol

)Terminal(

) Input/Output (

)Process(

)Decision(

)Flow Lines(

Table (1-1) Common symbols for Flowcharts

First: Define the problem

Output: The sum of two numbers


Input: The first number is “A “and the second number is “B”
Processing (Solution): C =A+B where the result is C

(8)
Second :Algorithm Third :Flowchart
1 Start
Start
2 Enter the number A and the
number B Enter A and B

3 Performing the sum of the two


numbers using this equation C=A+b
C=A+B, the output is C

4 Print the output C


Output C
5 End

End

Table (1-2) Algorithm and Flowchart for summation of tow numbers

1- The flowchart should start with the Start symbol and end with the End
symbol.
2- A,B,C are variable names .The variable refers to a memory storage that holds a
value.
3-The equation: C =A+B, indicates the sum of the value of A, to the value of B, and
stores the result in C.
4-Entering values in A and B is done by using the term “Enter”, inside a
parallelogram, you can also use another term to get the same meaning
like “Read” or “Input”.

5-The sum equation is written inside the rectangle, as it represents an


arithmetic operation.

6-The output is expressed with a parallelogram using the term “Output”,


we can also use another term like “Print” or "output".

7-Note that flow line shows the order of an Algorithm.

(9)
First: Define the problem
Output: The value of “Y”.
Input: X.
Processing (Solution): Compute the value of “Y” from the equation Y=3x+2.

Dear Student / remember:


1. The left hand side (LHS) of any equation should contain
only one variable; the value of this variable will be the
(output) or the solution of the equation.
2. The right hand side (RHS) of the equation may contain
abstracted values or arithmetic expressions that have one
or more variables (inputs).

Second :Algorithm Third :Flowchart


1 Start
Start

2 Enter value of X Input X

3 Calculate Y =3*X+2
Y=3*X+2

4 print value of Y
Print Y

5 End
End

Table (1-3) Algorithm and Flowchart to solve a first degree equation

(10)
Dear Student/ Notice
The word “Area” refers to a Variable name, whose value is
the calculated area of the rectangle; also “Perimeter” is a variable
name whose value is the calculated perimeter of the rectangle.

Variable names are chosen to WELL indicate the content of the


variables.

First: Define the problem

Output:

Input:

Solution :

Second :Algorithm Third :Flowchart

(11)
There are many problems that contain a question requires a Yes or No, or requires
branching to other processes determined by flowchart.

First: Define the problem


Output: print the word “ “.
Input: the score X.
Solution: If the value of X is greater than or equal 50; the word “ ” will
be printed.

Second :Algorithm Third :Flowchart


1 Start
Start
2 Enter the values of X

3 If X> =50 then Enter X

3-1 Print “ successful ”

4 End X>=50 Print


successful

End

Table (1-4) Algorithm and Flowchart to print the message “‫”ناجح‬

Dear Student / Notice


The execution of step (3-1) will be done only when the
value of x is greater than or equal to 50 (the result of the
condition is True), then it moves to step (4); otherwise when the
value of x is less than 50 (the result of the condition is False),
the execution is transferred to step 4 directly.

(12)
First: Define the problem
Output: print the result of dividing two numbers “R” or print the word
“undefined"
Input: Numerator is “num1”, denominator is “num2”.
Solution: if num2=0 then print “undefined”, otherwise print the result of the
division “R”.

Second :Algorithm Third :Flowchart

1 Start Start

2 Enter the Numerator num1


Enter num1
3 Enter the denominator num2

4 If num2 =0 then Enter num2

4-1 Print “undefined” print


Num2=0
4-2 Go to step 7 “undefined”

5 R=num1/num2 R=num1/num2

6 Print R
Print R
7 End

End

Table (1-5) Algorithm and Flowchart to print the division of two numbers
Dear Student / Notice
1. Step (4) is a decision (represented by the rhombus shape)
It is a comparison that evaluates this question (is
num2=0?) If the result is Yes then the word “undefined"
will be printed according to mathematical rules; then the
execution will be transferred to step (7) to end the
program and prevent the execution of the division.
2. If the result of the condition in (step 4) is false, the
execution will be transferred to step (5) directly because
step (4-1) and (4-2) won’t be executed.

(13)
First: Define the problem
Output: print the number type (even or odd).
Input: the number “N”.
Solution: the even number is determined if the entered number is divisible by 2
without remainder, otherwise it will be odd.
Second :Algorithm Third :Flowchart
1 Start
Start
2 Enter N

3 If N is divisible by 2 without Get N


remainder then

3-1 Print “even number”


N
4 Else divisible
by 2
4-1 Print “odd number”

5 End EVEN ODD

End

Table (1-6) Algorithm and Flowchart to enter a number and print its type (odd or even)

First: Define the problem


Output: print out “greater than zero” – “less than zero “or “equal zero”.
Input: temperature degree Celsius “D”.
Solution: the temperature degree entered will be compared to zero.

(14)
Second :Algorithm Third :Flowchart
1 Start
Start
2 Enter D (temperature
degree)
Get D
3 If D=o then

3-1 Print “Equal zero” Print


D =0
Equal 0
4 Else
Print
4-1 if D<0 then Below 0 D<0

4-1-1 Print “Below zero”


Print
4-2 Else Above 0

4-2-1 Print “Above zero”

5 End End

Table (1-7) Algorithm and Flowchart to get the temperature

First: Define the problem


Output: print out “the largest number is ...? “– “the smaller number is .…? “
Input: X, Y so x not equal y
Solution: ………………

Second :Algorithm Third :Flowchart

(15)
Flowchart Modified Flowchart
Start

Input R

A= 3.14 * R * R

Print A

End

Table (1-8) Flowchart to calculate the area of a circle

First: Define the problem


Output: print numbers from 1 to 3
Input: number M
Solution: print number M and increment it by 1 then continue printing
until the value of M become greater than 3

(16)
Second :Algorithm Third :Flowchart
1 Start
Start
2 M=1
M=1
3 If M<=3 then

3-1 Print M
M<=3
3-2 M=M+1

3-3 Go To step(3) Print M

4 End M=M+1

End

Table (1-9) Algorithm and Flowchart to print the numbers from 1 to 3

Dear Student / Notice


As long as the value of M does not exceed 3, the program prints value
of M. When M becomes 4 ;( M=4) the program goes to step (4).

Start

The opposite figure is the same flowchart M=1


drawn above but in a different way, this
means that what really matters is the M<=3
sequence of solution steps not the flowchart M=M+1
figure. Print M

End

You can track the progress of the solution steps and follow each step of the code as shown
in table (1-10).

(17)
Step value of M Result
1-Start There is No variable
2-M=1 1
3-If M<=3 (True) 1
1 3-1 Print M
3-2 M=M+1
1
2
1

3-3 Go to step (3) 2


3-If M<=3 (True) 2
2 3-1 Print M
3-2 M=M+1
2 2
3
3-3 Go to step (3) 3
3-If M<=3 (True) 3
3 3-1 Print M
3-2 M=M+1
3
4
3

3-3 Go to step (3) 4


3-If M<=3 (False) 4
4-End 4

Table (1-10) Tracking the variables and the corresponding result of exercise (1-7)

How many times was the content of the loop executed? ……………………
What will be the value of M after the end of the loop? ……………………………

Dear Student / Notice

1-When the value of M equals 4, the condition becomes (False).


2-We conclude that the number of repetition in the loop is pre
known in this exercise.
3- The variable M is called a counter; as it causes the steps (3-1)
and (3-2) and (3-3) to be repeated for a definite number of times (3 times).

(18)
Algorithm Flowchart
1 Start
Start
2 J=1
J=1
3 If J <=12 then

3-1 Print J*3 J <=12


J=J+1
3-2 J=J+1
Print J*3
3-3 Go To step(3)

4 End End

Table (1-11) Algorithm and Flowchart to print the multiplication table of No 3.

Compare this flowchart to the one in the previous exercise (what are the differences?).

(19)
Make the necessary modifications to the Flowchart of the previous exercise, so that
you can enter the required multiplication table constantly instead of printing the
multiplication table of “3”.

Algorithm Flowchart
1 Start
2 Enter N
3 J=1
4 If J<=12 then
4-1 Print J*N
4-2 J=J+1
4-3 Go To step(4)
5 End

Table (1-12) Algorithm to print the multiplication table of an entered number

:Algorithm Flowchart

(20)
Algorithm Flowchart
1 Start
Start
2 N=1
N=1
3 Sum=0
Sum=0
4 Sum =Sum + N
Sum=Sum+N
5 N=N+1
N=N+1
6 If N>3 Then

6-1 Print Sum N>3

7 Else
Print Sum

7-1 Go to step (4)

8 End End

Table (1-13) Algorithm and flowchart to print the sum of integer numbers from 1 to 3
You can track the values of variables as shown in table (1-14)
Step Value of N Value of Sum Result
1-Start No variable No variable
2-N=1 1 No variable
3-Sum=0 1 0
4-Sum=Sum+N 1 1
5-N=N+1 2 1
6-if N>3 (False) 2 1
7-1 Go To step (4) 2 1
4-Sum=Sum+N 2 3
5-N=N+1 3 3
6-if N>3 (False) 3 3
7-1 Go To step (4) 3 3
4-Sum=Sum+N 3 6
5-N=N+1 4 6
6-if N>3 (True) 4 6
6-1 Print Sum 4 6 6
Table (1-14) tracking the values of variables and corresponding results of exercise (1-9)

(21)
Dear Student / Notice
Variable N is considered a Counter, while variable Sum is used for
accumulation process.

(22)
First: Put () in front of the correct sentence and (X) in front of the wrong one:
(1) Flowcharts use standard symbols and lines to represent a problem algorithm. ) )
You can use any Geometric shape to represent Algorithm when drawing
(2) ) )
flowcharts.
(3) The symbol is used to represent start and end of flowchart. ) )
(4) The rectangle symbol is used to represent the data input operation. ) )
(5) The symbol is used to represent a decision process in flowcharts. ) )
(6) The problem means that an objective or output is required to reach. ) )
(7) Preparing a cup of tea is an example of a problem. ) )
Problem solving is the steps, activities, and processes to be done to reach an
(8) ) )
output or objective.
The program documentation is a set of procedures arranged logically for solving a
(9) ) )
specific problem.
(10) The program testing is writing down all the steps taken to solve a problem. ) )
(11) Documenting the program means making sure that the program is free of errors. ) )
(12) Algorithm is a set of procedures arranged logically for solving a specific problem. ) )
The program documentation is writing down all the steps taken to solve a
(13) ) )
problem.
(14) Testing the program means making sure that the program is free of errors. ) )
Flowcharts are diagram representations which depend on drawing some standard
(15) ) )
symbols to clarify the order of procedures to solve a problem.
Flowcharts help to facilitate understanding of the problem, analyse and convert it
(16) ) )
to a program.

Second: Choose the appropriate answer to complete each phrase of the following:
1- Steps, activities and procedures to be done to reach an objective or an output - can be
called:
a. problem definition b. problem c. problem solving

2- On drawing flowcharts we use:


a. standard symbols and lines b. all geometric figures c. one geometric figure

3- A set of procedures arranged logically for solving a specific problem – can be called:
a. problem b. algorithm c. program testing

4- Making sure that the program is free of errors – can be called:


a. program testing b. program documentation c. algorithm

5- Writing down all the steps taken to solve a problem errors – can be called:
a. program documentation b. program testing c. flowcharts

(23)
6- Problem-solving includes many terminologies, the terminology that expresses the
preparation of a cup juice is:
a. Flowchart b. algorithm c. problem

7- Problem-solving approach includes many of the terminologies, the terminology that


expresses the mathematical problem is:
a. Algorithm b. problem c. program design

8- A diagramatic representation that depends on drawing some standard symbols to


clarify the order of procedures to solve a problem can be called:
a. Problem b. algorithm c. flowchart

9- In the following flowchart:

Start

M=1

FALSE
M<=3
M=M+1
TRUE
Print M

End

The number of iterations (print the value of M) is:


a- 2 b- 3 c- 4

10- In Flowchart of the previous question, the value of M after the end of the iterative
loop equals:
a. 2 b- 3 c- 4

(24)

You might also like