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

Chapter 1

The document discusses problem solving through a sequence of steps and activities. It provides examples of problems like making a cup of tea or building a structure. It then outlines the typical steps in problem solving as: 1) defining the problem, 2) creating step-by-step instructions through an algorithm or flowchart, 3) designing a program, 4) testing the program, and 5) documenting the program. Finally, it discusses flowcharts and common symbols used to illustrate the sequence of steps to solve a problem.

Uploaded by

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

Chapter 1

The document discusses problem solving through a sequence of steps and activities. It provides examples of problems like making a cup of tea or building a structure. It then outlines the typical steps in problem solving as: 1) defining the problem, 2) creating step-by-step instructions through an algorithm or flowchart, 3) designing a program, 4) testing the program, and 5) documenting the program. Finally, it discusses flowcharts and common symbols used to illustrate the sequence of steps to solve a problem.

Uploaded by

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

Problem

It is an objective or an output that we have to achieve


through a sequence of steps and activities and specific
input.
Ex:-
Cup of tea = Tea + Water + Sugar + glass+…
Ex:-
Going to school = transport + money + …. .
Ex:-
Building = Sand + cement + iron +……. .
Problem Solving :-
It is the sequence of steps, activities and operations that we
have to perform to attain an objective or an output..

Ex:-
(Tea + Water )  Boiling +sugar = Cup of tea
Ex:-
Take a bus pay money  Bus running = Arrive school.
Ex:-
Digging (cement + sand ) + iron  Workers = Building
oblem solving steps :-
1. Problem definition . Output 7
‫تحديد المشكلة‬ Input 3,4
Solution 7 = 4+3
2. Step-by-step instructions . Algorithm
Flowchart
3. Program design .
4. Program Testing .
5. Program Documentation .
First: Problem Definition:

Problem definition implies the identification of required


outputs, available inputs and, arithmetic and logical
operations to be executed.
Ex:-

8 4,2 8=4*2
Second: Performing step-by-step instructi ons
(Algorithm) to solve a Problem

Algorithm :- a group of logically arranged procedures to be


executed to attain a goal or precise output, out of specific inputs.

Draw

Flow chart
Third: Program design
We have to translate this flowchart into one of the
programming languages to create a program.

programming
Fourth: Program Testing
During writing a program we make some mistakes
Ex:-
Area of circle = 3.14 + R^2
We can’t detect errors unless we begin entering data to the program with previously
known results; to compare the results of the current program to those of the well-
known results.
Ex:-
Predefined result  3.14*5^2 = 78.5

If (R=5 cm)

Program result  3.14 + 5 ^2= 28.14


X
Fifth: Program Documentation
All steps taken for solving the problem that include:
1.Given Input, output, plan for solving the problem.

The documentation is beneficial when more than one


person participate in writing or modifying the program.
It is a diagram that uses standard graphical symbols , to illustrate
the sequence of steps required for solving a problem or specific
question .
The most commonly used symbols are as follows:

Significance Symbol
Terminal ( Start , End )

Input (Read , Input , Enter)


Output (Print , Output )

) = ( Process
Calculate , Compute

) ? ( Question – Comparison - Decision

Flow lines
- Simple
Types of flowchart - Branching
- Looping

1- Simple flow chart:-


Ex 1:-
Draw a flowchart for a program that calculates the sum of
two numbers entered by the user and display the result .
First: Define the problem
Output: The sum of two numbers
Input: The first number is “A “and the second number is “B”
Solution: Sum=A+B
Third :- Flowchart Second :- Algorithm

1- Start Start

2 -Enter number A , number B Enter A ,B

3 – Sum = A + B Sum= A+ B

4– Print Sum Print Sum


5 - End
End
Ex 2:-
Draw a flowchart for a program that calculates the average and product of
three numbers
First: - Define the problem:-
.Output: - The average, product of three numbers
Input:-The numbers are X , Y , Z.
Solution: - Average = (X + Y + Z) / 3 , Product = X * Y* Z
Third :- Flowchart Second :- Algorithm
Start
1- Start

2 -EnterEnter
x,y,z x,y,z

3- avg=(x+y+z)/3
Avg=(x+y+z)/3
pro=x *y*z
Pro=x*y*z
4- Print avg , pro
Print avg,pro
5-End
End
Exercise 1:-
Calculate the area of circle Area = 3.14 * R ^2
First: - Define the problem:-
Output: - Area of circle input
output
Input:- Radius (R)
Solution: - Area = 3.14 * R ^2
Third :- Flowchart Second :- Algorithm

Start
1- Start
Enter R
2 -Enter R

3- Area = 3.14 * R^2 Area = 3.14 * R^2

4- Print Area
Print Area
5-End
End
Exercise 2:-
Calculate the number of years using a known number of months
First: - Define the problem:-
Output: - Years (y) Y = m / 12
Input:- Months (m) input
Solution: - Y = m / 12 output

Third :- Flowchart Second :- Algorithm

Start
1- Start
Enter m
2 -Enter m

3- y = m / 12 Y = m / 12

4- Print y
Print y
5-End
End
2- Branching flow chart:- ?
Ex 1:-
Draw a flowchart for a program that obtains exam scores from the user
and determines whether the score is greater than or equal 50 and
display the message "Successful".

First: - Define the problem:-


Output: - Message “Successful”

Input:- Student degree (d)

Solution: - If d> = 50 , then print “Successful”


Else  end the program
Third :- Flowchart Second :- Algorithm

Start
1- Start
Enter d
2- Enter ( d )
Yes Print
3- If d>=50 , then If d>=50
“Successful“
3.1- Print “Successful”
No
4- End
End
Ex 2:-
Draw a flowchart for a program that compares between two number
and to know which of them is greater than the other showing a
message “The largest number is…..”.

First: - Define the problem:-


Output: - Message “the largest number is ……….”

Input:- Two numbers ( x , y )

Solution: - If x>y , then print “the largest number is x”


Else  print “the largest number is y”,
Third :- Flowchart Second :- Algorithm

Start
1- Start
Enter x , y
2- Enter x , y
Print “the
Yes largest
3- If x>y , then If x > y
number is x
3.1- Print “the largest number is “
x” No

4- Else Print “the


4.1- Print “the largest number is largest
y” number is y

5-End
End
Example 3:-

Draw a flow chart for a program that calculates the division of two
numbers .Determine whether the divisor equal “ Zero“ and display the
message “ Unknown “.

First: Define the problem


Output : Division of two numbers “div” or print the word ” unknown”

Input: The dividend is “x”, and the divisor is “y”.

Solution: If y=0 then print “unknown”


elsediv=x/y ,then print div.
Third :- Flowchart Second :- Algorithm

1- Start
Start
2- Enter x , y
3- If y =0 then, Enter x , y

3.1- Print ”unknown” Print


Yes
3.2 -Go to step 5 y=0 “unknown

4-Else No
div= x/y
4.1- div=x/y
4.2- Print div
Print div
5- End
End
3- Looping flow chart:-
Ex 1:-
Print out the integer numbers from 1 to 3 1 2 3
1 2 3 Start
N N N
N=1

1- 1 ‫ا لبداية ؟‬ No Yes
N <=3
2- 3 ‫ا لنهاية ؟‬
3-1 ‫مع دلا لزيادة ؟‬ Print N

N= N +1
End
Flowchart Algorithm

1- Start
2- N=1
3- If N<=3 then,
3.1- Print N
3.2 – N= N + 1

3.3 – Go to step 3
4-End

How many times was the content of the loop executed? 3 times
What will be the value of M at the end of the loop? 4
Ex 2:-
Draw a flow chart to print the multiplication table of number 3 .

N N*3

1* 3 = 3
2* 3 = 6
3* 3 = 9
4* 3 = 12
.
.
.
12* 3 = 36
Flowchart Algorithm

1- Start Start
2- N=1
N= 1
3- If N<=12 then,

3.1- Print N * 3 No
N <=12 N= N +1
3.2 – N= N + 1

3.3 – Go to step 3 Yes


Print N *3
4-End

End
Questions

You might also like