Lesson 02: Problem Solving and
Programming
Problem Solving and Programming Concepts
Dr. solaf ali
University of Sulaimani
College of Science
Department of Computer
29 Nov. 2021
1
Objectives
• What is programs and programming?
• What is problem solving?
• What is algorithm?
• Characteristics of algorithm.
• How to write algorithm?
• What is flowchart?
2
Problems Solving (1)
• People make decisions every day to solve problems
that affect their lives.
• If a bad decision is made, time and resources are
wasted.
Avoid bad decision…
How?!
3
Problems Solving (2)
4
IDEA: Let’s go on a picnic…
PROBLEM: What to do?
Problems Solving (3)
5
Solving Problems & Programming
• To write a program for a computer, we must go
through a two-phase process:
• Problem solving: Designing a strategy for solving the problem (Design an
algorithm), then
• Implementation: Translating the algorithm into program.
Programming is a
problem-solving
procedure.
6
Programming Phases (1)
• Problem-Solving Phase
• Analysis and Specification: Understand (define) the
problem and what the solution must do.
• General Solution (Algorithm): Specify the required
data types and the logical sequences of steps that
solve the problem.
• Verify: Follow the steps exactly to see if the solution
really does solve the problem.
7
Programming Phases (2)
• Implementation Phase
• Concrete Solution (Program): Translate the algorithm into a
programming language.
• Test: Have the computer follow the instructions.
• Then manually check the results.
• If you find errors, analyze the program and the algorithm, then
make corrections accordingly.
• Once a program has been written, it enters the third phase:
Maintenance.
8
Problem Solving & Programming
9
Algorithm (1)
• Algorithm can help programmer to plan a program.
• Algorithms are precise step-by-step instructions on
how to accomplish a desired task.
• It can be described in natural language, pseudo code or
in flowchart.
• Pseudo code: is natural language mixed with some programming
code.
• Flowchart: is a diagram that shows the flow of a program.
10
Example: Real Life Example
11
Algorithm (2)
• Writing an algorithm is probably the hardest part of
problem-solving process.
• The instructions in an algorithm:
• Cannot assume anything.
• Cannot skip steps.
• Must be executable one step at a time, and
• Must be complete.
12
Example 1:
• Write a solution to change a Fahrenheit temperature to
Celsius.
C = 5 / 9 (F – 32)
• The Solution:
1. Input: Give temperature in Fahrenheit (F).
2. Write equation for converting the temperature form Fahrenheit to Celsius.
3. Put temperature in Fahrenheit (F) in the equation.
4. Calculate the equation.
5. Output: C is the temperature in Celsius.
6. End.
13
Exercise 1
1. Consider your class representative wants to copy “Programming”
materials for the students. The price of copying 1 page is 50 IQD. He
wants to know how much does it cost to copy the materials for the
students. Test your solution with the following data:
• The material is 5 pages for 85 students.
2. An employee’s job in a printing company is to order paper for reports in
board meetings. The paper comes in sets of 500 sheets. He always makes
five more copies than the number of people that will be in the meeting.
He wants to know how many sets of paper he needs for a meeting. (Hint:
He can order only whole not partial sets). Test your solution with the
following data:
• The report is 145 pages long and there will be 25 members at the meeting.
3. A teacher would like to know if his student passed the exam or not. She
wants to enter students score.
14
Algorithms, Pseudo-code & Flowcharts
• To develop an algorithm, we need to represent the instructions in
some way that the steps involved is understandable to others. Two
commonly used representations for an algorithm is by using:
• pseudo code
• flow charts.
Pseudocode will vary according to
whoever writes it.
That is, one person’s pseudocode is
often quite different from another
person.
15
Flowcharts (1)
• A flowchart is a graphical representation shows the
steps of the sequence of operations in or program.
• Different symbols (or boxes) are used to draw
flowcharts.
• Diamonds and other shapes, connected by arrows.
• Each shape represents a step in the process.
• The arrows show the order in which they occur.
16
Flowcharts (2)
• Basic operations in flowcharts
Sequence: Listing instructions step by step in order
Selection: Making a decision (also called branch or
decision
Repetition: Repeating something (also called loop or
iteration)
Jumping: Jumping to a specific step
Storage: Saving information for later use
17
Flowchart & Pseudo code
• Write a solution to change a Fahrenheit temperature to Celsius.
C = 5 / 9 ( F – 32)
Flowchart
Pseudo code: Start
1. Input: Give temperature in Fahrenheit
(F).
2. Write equation for converting the Get temperature F
temperature form Fahrenheit to Celsius.
3. Put temperature in Fahrenheit (F) in the
equation. Calculate
4. Calculate the equation. C = 5 / 9 ( F – 32)
5. Output: C is the temperature in Celsius.
6. End. Output temp (C)
Stop 18
Flowchart Symbols
Symbol Name Function
Terminal Indicates start / end of the program
Flow Lines (Arrows) Shows direction of flow
Process Any type of operations
Input / Output Used to obtain data or output result
Decision Used to ask a question that answered with (Yes / No)
Used to join different parts of the flowchart without
Connecter
intersecting lines
Predefined Process Used to invoke subroutine 19
General Rules for Flowchart Drawing
• Flowchart will flow from top to bottom.
• All boxes of the flowchart are connected with arrows not lines.
• Flowchart symbols have an entry point on the top and exit point
on the bottom.
• Connectors are used to connect breaks in the flowchart.
20
Pseudo code Vs. Flowchart
• Although flowcharts can be visually appealing, pseudocode
is often the preferred choice for algorithm development
because:
• It can be difficult to draw a flowchart neatly, especially when
mistakes are made.
• Pseudocode fits more easily on a page of paper.
• Pseudocode can be written in a way that is very close to real program
code, making it easier later to write the program
• Pseudocode takes less time to write than drawing a flowchart.
21
References
• Maureen Sprankle & Jim Hubbard, “Problem solving and
programming concepts”, 9th Ed, 2012.
• Henri E. Bal & Dick Grune, “Programming Language Essentials’, 1994.
• Timothy J. O’leary & Linda I. O’leary, “Computing Essentials”,
complete edition, 2007.
22