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

BIC 10204 Chapter 2 Problem Solving and Algorithm

This document discusses problem solving and algorithms in computer science. It explains that algorithms are a set of steps to solve a problem and are used by programmers to plan computer programs. The document provides examples of algorithms for making a chocolate cake, withdrawing money from an ATM, and going from a hostel to FSKTM. It also discusses problem identification techniques, problem solving tools, and converting problems into flow charts and pseudo-code.

Uploaded by

Rebekah Joy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views

BIC 10204 Chapter 2 Problem Solving and Algorithm

This document discusses problem solving and algorithms in computer science. It explains that algorithms are a set of steps to solve a problem and are used by programmers to plan computer programs. The document provides examples of algorithms for making a chocolate cake, withdrawing money from an ATM, and going from a hostel to FSKTM. It also discusses problem identification techniques, problem solving tools, and converting problems into flow charts and pseudo-code.

Uploaded by

Rebekah Joy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Faculty of Computer Science and Information Technology

Chap 2 Problem Solving & Algorithm

BIC 10204 Algorithm and Programming After this lesson, you should be able to understand
or explain about:
Chapter 2 ✓ what is problem
Problem Solving and ✓ problem identification techniques
✓ problem solving tools and techniques
Algorithm ✓ various forms of algorithm
✓ flow chart and pseudo-code
✓ convert problem to flow chart /pseudo-code
✓ convert pseudo-code to flowchart
2

Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

Making a delicious Going to FSKTM from


chocolate cake. your Hostel. How to make a delicious chocolate cake?

▪Prepare the ingredients.


▪Beat the butter and the eggs.
▪Mix with cake flour and sugar.
▪Add chocolate to the mixture.
▪Pour the mixture in the
▪Put the mixture in the oven.
Installing a software Log into a system. ▪Bake for 45 minutes.
into a pc. ▪Wipe chocolate cream around the baked cake.

3 4

Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

How to install a software into a PC? How to log into an online system?

If you are a registered user,


▪Put the software CD in the CD driver. ▪Enter your ID or username
▪Open the CD directory in PC ▪Enter your password
▪Click the installer file in the CD, install.exe. ▪Click on the submit button
▪Follow the setup instructions for installation
process. ▪If you are not registered, do the registration process
Or use Control Panel > Add programs. by filling in the registration form.

5 6

1
Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

 Withdraw money from ATM machine


How to go to FSKTM from  Register subjects through online system
 Buy cold drinks from vending machine
your hostel?  Calculate the monthly salary payment
 Calculate car loan interest
 Determine odd and even numbers
 Count the total visitor of a Web
 Determine air velocity in physic lab

7 8

Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

Writing computer program

9 10

Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

Steps in computer
Procedure or formula
program for solving problem
for computer to do its job
Sequence set of
steps taken to
solve a problem

Famous Muslim Instructions for actions to be executed by computer


scientist/
mathematician (input/process/output)
11 12

2
Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

Example 2: Money withdrawal algorithm


1. Go to the ATM machine.
1. Go to the taxi stand. 2. Insert ATM card.
2. Get in a taxi. 3. Select language.
3. Give the taxi driver the destination address. 4. Enter pin number.
4. Once arrived, pay the taxi fare. 5. Select withdrawal option from menu.
5. Get out from the taxi. 6. Enter amount of money to withdraw.
7. Take the money.
8. Take the bank slip.

13 14

Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

Do computer can really


understand algorithm?

Algorithm is used by programmer to plan


the instructions to be written in the
computer program and executed by
computer

15 16

Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

Simple codes which resembles


program code that will be written
during implementation phase
(program coding)
i. Consists of a statement of instructions in sequence.
ii. Every steps consists of keyword which explain the actions/
A text-based design tool that helps
operation/process to be executed by computers
programmmers to develop algorithm
iii. Every steps should be written in different steps, if continued, the
next row must be indented.
Using natural language iv. Can use if/else for conditional statement and while, do/while and
Compact and informal high level (communication language for repetition statement
language description of a computer e.g: Malay/English) wording v. Every steps should use clear statements and easy to understand.
programming algorithm
phrase vi. Use start to represent the beginning of the operation and end to
show the end of the operation.

17 18

3
Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

Keyword?
Keyword?

if student's grade is greater than or equal to 60 “set” means


print the statement "passed" “print” means Set total to zero assign the
else display on the
print the statement "failed"
Set grade counter to one value,e.g:
screen While grade counter is less than or equal to ten
monitor total = 0
Input the next grade
Add the grade into the total
Set the class average to the total divided by ten
if credit card number is valid “show” also Print the class average.
execute transaction based on number and order means
else display on the “while” is used
show a generic failure message screen monitor whenever the
process is to be
19 continued 20

Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

Identify the problem

Input Value of x and a


Write the pseudo code based on the IPO (input/process/
output) which you have identified during the analyzing Process Replace the value of x and a in the
phase
formula, y = 2x +a -6
Identify the keyword(s) based on the IPO
Output The value of the equation, y
Do you remember the steps we’ve done in Chap 1 & 2?

21 22

Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

(Using example from chapter 1) (Using example from chapter 1)


Write a
Uncle Degawan wants to buy 5 tins of paint from
Given the value of x is 10 and a is 12, program!
Cinda’s shop. The price of each tin of the paint is
find the result of the following equation:
RM 15.60. Calculate the price which Uncle Degawan
y = 2x + a - 6 Keyword have to pay for all the tin of paints he bought.
Write a
program!
start start
read the value of x read the amount of paint
read the value of a compute the total price as price per tin times by amount of
compute the value of y as y = 2x + a -6 paint
display/print the result (or the total price) Keyword?
display/print the result (or the value of y)
end 23 end 24

4
Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

(Using example from chapter 1) Keyword


Mrs Sue needs to determine her students grade for
programming subject based on the mark scored during start
final examination. The ‘A’ grade will be given if the mark read the student mark
scored is between 85 to 100. If a student has scored 90 if mark is greater than 85 and mark is less than 100, then
marks, what is the grade that Mrs Sue should give to the set grade as A
student? display/print the grade
end
Keyword
Write a program!

25 26

Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

Test your
understanding!

A box has height, width and length.


Write the pseudo code to calculate the volume Given the following formula, write the pseudo code
of a box. to calculate the porosity of rock:
porosity = (pure volume /total rock volume) x 100%

Write the pseudo code to calculate salary of


an employee for a month.

27 28

Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

Schematic representation of an
algorithm or process

▪Helps to visualize the


content/steps better or to find
flaws in process
▪Illustrate the steps in the
process

29 30

5
Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

Start/Stop Decision
The terminator symbol marks the A decision or branching point. Lines
starting or ending point of the representing different decisions
system. It usually contains the emerge from different points of the
word "Start" or "End." diamond.
Input/Output
Action or Process Represents material or information
A box can represent a single step entering or leaving the system,
("add two cups of flour"), or and such as customer order (input) or a
entire sub-process ("make product (output).
bread") within a larger process.
31 32

Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

Off Page
Flow Line Indicates that the process continues off
Lines indicate the sequence of page.
steps and the direction of flow.

Database
Connector Indicates a list of information with a
Indicates that the flow continues standard structure that allows for
where a matching symbol searching and sorting.
(containing the same letter) has
been placed.

33 34

Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

What software use to


draw flowchart?

You can use Ms Word >


AutoShapes> Flowchart or
other flowchart drawing tools
e.g: SmartDraw/Visio Drawing, etc.

35 36

6
Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

(Based on the Example 1 (Slide number 23)) start


Start
read the amount of paint
compute the total price as price per tin times by amount of
paint
Read x
display/print the result (or the total price)
end
Read a Convert
to
start
y = 2x + a - 6 read the student mark flowchart
if mark is greater than 85 and mark is less than 100, then
Print y set grade as A
display/print the grade
End 37 end 38

Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

Convert to
flowchart
A box has height, width and length.
Write the pseudo code to calculate the volume Given the following formula, write the pseudo code
of a box. to calculate the porosity of rock:
Convert
Convertto
to porosity = (pure volume /total rock volume) x 100%
flowchart
flowchart
Write the pseudo code to calculate salary of
an employee for a month.

39 40

Chap 2 Problem Solving & Algorithm Chap 2 Problem Solving & Algorithm

▪Algorithm development and program design using C (1997)


Gary J. Bronson, Course Technology
▪C How To Program (2016), P.J. Deitel and H.M. Deitel,
Pearson International Edition
▪Problem Solving and Program Design in C (2007),
J.R. Hanly and E.B. Koffman, Pearson International Edition.
▪Wikipedia- the free encyclopedia,
Available at : http://en.wikipedia.org/wiki
▪Learn how to draw flowcharting shapes, available at:
http://www.smartdraw.com/tutorials/flowcharts/tutorial_05.htm

41 42

You might also like