name of presentation - tun hussein onn university of...
TRANSCRIPT
Faculty of Computer Science and Information Technology
BIC 10204 Algorithm and Programming
1
CHAPTER 2
BIC 10204 Algorithm and Programming
Problem Solving and
Algorithm
Chap 2 Problem Solving and
Algorithm
2
what is problem problem identification techniques problem solving tools and techniques various forms of algorithm flow chart and pseudo-code convert problem to flow chart /pseudo-code convert pseudo-code to flowchart
After this lesson, you should be able to understand
or explain about:
Chap 2 Problem Solving and
Algorithm
3
Going to FSKTM from
your Hostel. Making a delicious
chocolate cake.
Installing a software
into a pc.
Log into a system.
Chap 2 Problem Solving and
Algorithm
4
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.
Bake for 45 minutes.
Wipe chocolate cream around the baked cake.
Chap 2 Problem Solving and
Algorithm
5
How to install a software into a PC?
Put the software CD in the CD driver.
Open the CD directory in PC
Click the installer file in the CD, install.exe.
Follow the setup instructions for installation
process.
Or use Control Panel > Add programs.
Chap 2 Problem Solving and
Algorithm
6
How to log into an online system?
If you are a registered user,
Enter your ID or username
Enter your password
Click on the submit button
If you are not registered, do the registration process
by filling in the registration form.
Chap 2 Problem Solving and
Algorithm
7
How to go to FSKTM from your hostel?
Chap 2 Problem Solving and
Algorithm
8
Withdraw money from ATM machine Register subjects through online system Buy cold drinks from vending machine 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
Chap 2 Problem Solving and
Algorithm
9
Chap 2 Problem Solving and
Algorithm
10
Writing computer program
Chap 2 Problem Solving and
Algorithm
11
Steps in computer
program
for computer to do its job
Famous Muslim scientist/
mathematician
Chap 2 Problem Solving and
Algorithm
12
Procedure or formula
for solving problem
Sequence set of
steps taken to
solve a problem
Instructions for actions to be executed by computer
(input/process/output)
Chap 2 Problem Solving and
Algorithm
13
1. Go to the taxi stand.
2. Get in a taxi.
3. Give the taxi driver the destination address.
4. Once arrived, pay the taxi fare.
5. Get out from the taxi.
Chap 2 Problem Solving and
Algorithm
14
1. Go to the ATM machine.
2. Insert ATM card.
3. Select language.
4. Enter pin number.
5. Select withdrawal option from menu.
6. Enter amount of money to withdraw.
7. Take the money.
8. Take the bank slip.
Example 2: Money withdrawal algorithm
Chap 2 Problem Solving and
Algorithm
15
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
Chap 2 Problem Solving and
Algorithm
16
Chap 2 Problem Solving and
Algorithm
17
A text-based design tool that helps programmmers to develop algorithm
Using natural language (communication language
e.g: Malay/English) wording phrase
Compact and informal high level
language description of a computer
programming algorithm
Simple codes which resembles
program code that will be written
during implementation phase
(program coding)
Chap 2 Problem Solving and
Algorithm
18
i. Consists of a statement of instructions in sequence.
ii. Every steps consists of keyword which explain the actions/
operation/process to be executed by computers
iii. Every steps should be written in different steps, if continued, the
next row must be indented.
iv. Can use if/else for conditional statement and while, do/while and
for repetition statement
v. Every steps should use clear statements and easy to understand.
vi. Use start to represent the beginning of the operation and end to
show the end of the operation.
Chap 2 Problem Solving and
Algorithm
19
if student's grade is greater than or equal to 60
print the statement "passed"
else
print the statement "failed"
Keyword
?
“print” means display on the
screen monitor
if credit card number is valid
execute transaction based on number and order
else
show a generic failure message
“show” also means
display on the screen monitor
Chap 2 Problem Solving and
Algorithm
20
Set total to zero
Set grade counter to one
While grade counter is less than or equal to ten
Input the next grade
Add the grade into the total
Set the class average to the total divided by ten
Print the class average.
Keyword
?
“set” means assign the value,e.g: total = 0
“while” is used whenever the
process is to be continued
Chap 2 Problem Solving and
Algorithm
21
Write the pseudo code based on the IPO (input/process/
output) which you have identified during the analyzing
phase
Identify the keyword(s) based on the IPO
Did you remember the steps we’ve done in Chap 1 & 2?
Chap 2 Problem Solving and
Algorithm
22
Input Value of x and a
Process Replace the value of x and a in the formula, y = 2x +a -6
Output The value of the equation, y
Identify the problem
Chap 2 Problem Solving and
Algorithm
23
Given the value of x is 10 and a is 12, find the result of the following equation:
y = 2x + a - 6
(Using example from chapter 1)
start read the value of x read the value of a compute the value of y as y = 2x + a -6 display/print the result (or the value of y) end
Write a
program!
Keyword Keyword Keyword
Chap 2 Problem Solving and
Algorithm
24
Uncle Degawan wants to buy 5 tins of paint from
Cinda’s shop. The price of each tin of the paint is
RM 15.60. Calculate the price which Uncle Degawan
have to pay for all the tin of paints he bought.
(Using example from chapter 1)
start read the amount of paint compute the total price as price per tin times by amount of paint display/print the result (or the total price) end
Write a
program!
Keyword?
Chap 2 Problem Solving and
Algorithm
25
Mrs Sue needs to determine her students grade for programming subject based on the mark scored during final examination. The ‘A’ grade will be given if the mark scored is between 85 to 100. If a student has scored 90 marks, what is the grade that Mrs Sue should give to the student?
(Using example from chapter 1)
Write a program!
Chap 2 Problem Solving and
Algorithm
26
start read the student mark if mark is greater than 85 and mark is less than 100, then set grade as A display/print the grade end
Keyword Keyword
Keyword
Chap 2 Problem Solving and
Algorithm
27
A box has height, width and length. Write the pseudo code to calculate the volume of a box.
Write the pseudo code to calculate salary of an employee for a month.
Test your
understanding!
Chap 2 Problem Solving and
Algorithm
28
Given the following formula, write the pseudo code to calculate the porosity of rock: porosity = (pure volume /total rock volume) x 100%
Chap 2 Problem Solving and
Algorithm
29
Chap 2 Problem Solving and
Algorithm
30
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
Chap 2 Problem Solving and
Algorithm
31
Start/Stop
The terminator symbol marks the starting or ending point of the system. It usually contains the word "Start" or "End."
Action or Process A box can represent a single step ("add two cups of flour"), or and entire sub-process ("make bread") within a larger process.
Chap 2 Problem Solving and
Algorithm
32
Decision A decision or branching point. Lines representing different decisions emerge from different points of the diamond.
Input/Output Represents material or information entering or leaving the system, such as customer order (input) or a product (output).
Chap 2 Problem Solving and
Algorithm
33
Flow Line Lines indicate the sequence of steps and the direction of flow.
Connector Indicates that the flow continues where a matching symbol (containing the same letter) has been placed.
Chap 2 Problem Solving and
Algorithm
34
Off Page Indicates that the process continues off page.
Database Indicates a list of information with a standard structure that allows for searching and sorting.
Chap 2 Problem Solving and
Algorithm
36
What software use to
draw flowchart?
You can use Ms Word >
AutoShapes> Flowchart or
other flowchart drawing tools
e.g: SmartDraw/Visio Drawing, etc.
Chap 2 Problem Solving and
Algorithm
37
(Based on the Example 1 (Slide number 23))
Start
End
Read x
Read a
y = 2x + a - 6
Print y
Chap 2 Problem Solving and
Algorithm
38
start read the amount of paint compute the total price as price per tin times by amount of paint display/print the result (or the total price) end
start read the student mark if mark is greater than 85 and mark is less than 100, then set grade as A display/print the grade end
Convert
to
flowchart
Convert
to
flowchart
Convert
to
flowchart
Convert
to
flowchart
Chap 2 Problem Solving and
Algorithm
39
A box has height, width and length. Write the pseudo code to calculate the volume of a box.
Write the pseudo code to calculate salary of an employee for a month.
Convert
to
flowchart
Convert
to
flowchart
Chap 2 Problem Solving and
Algorithm
40
Given the following formula, write the pseudo code to calculate the porosity of rock: porosity = (pure volume /total rock volume) x 100%
Convert to
flowchart
Chap 2 Problem Solving and
Algorithm
41
Chap 2 Problem Solving and
Algorithm
42
Algorithm development and program design using C (1997) Gary J. Bronson, Course Technology C How To Program (2007), 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