32
Universiti Tun Hussien Onn Malaysia Faculty of Mechanical and Manufacturing Engineering

Copy of dti2143/dam31303 chap 1 problem solving and program design

Embed Size (px)

DESCRIPTION

SLIDE CHAPTER 1

Citation preview

Page 1: Copy of dti2143/dam31303 chap 1 problem solving and program design

Universiti Tun Hussien Onn MalaysiaFaculty of Mechanical and Manufacturing Engineering

Page 2: Copy of dti2143/dam31303 chap 1 problem solving and program design

• 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

Page 3: Copy of dti2143/dam31303 chap 1 problem solving and program design

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

Page 4: Copy of dti2143/dam31303 chap 1 problem solving and program design
Page 5: Copy of dti2143/dam31303 chap 1 problem solving and program design

A text-based design tool that helps programmers 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)

Page 6: Copy of dti2143/dam31303 chap 1 problem solving and program design

1. Consist of a statement of instructions in sequence2. Every step consists of keyword3. Every step should be written in different step, if continued,

thru next row must be indented4. if/else for condition, while/do for repetition5. Every step must contain clear statement and easy to understand6. Use start for beginning of operation, and end/halt for finishing it.

Page 7: Copy of dti2143/dam31303 chap 1 problem solving and program design

Computing Sales Tax : Pseudo-code the task of computing the final price of an item after figuring in sales tax. Note the three types of instructions:

Input (get or read), process/calculate (=) and output (display)

1. Start2. get price of item3. get sales tax rate4. sales tax = price of item * sales tax rate5. Final price = price of item + sales tax6. display final price7. 7 halt/end

Page 8: Copy of dti2143/dam31303 chap 1 problem solving and program design

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

Page 9: Copy of dti2143/dam31303 chap 1 problem solving and program design

Set total to zero Set grade_counter to one While grade_counter is less than or equal to ten

Input the next gradeAdd the grade into the total

Set the class_average to the total divided by ten Print the class_average.

Keyword?

set meansassign

the value,e.g

:total = 0

while is used

whenever the

process is to be

continued

Page 10: Copy of dti2143/dam31303 chap 1 problem solving and program design

Write the pseudo code based on the IPO (input/process/

output) which you have identified during the analyzing phaseIdentify the keyword(s) based on the IPO

Page 11: Copy of dti2143/dam31303 chap 1 problem solving and program design

Input Value of x and a

Process Replace the value of x and a in theformula, y = 2x +a -6

Output The value of the equation, y

Identify the problem

Page 12: Copy of dti2143/dam31303 chap 1 problem solving and program design

Given the value of x is 10 and a is 12, find the result of the following equation:

y = 2x + a - 6

startread the value of xread the value of acompute the value of y as y = 2x + a -6display/print the result (or the value of y)end

Write a program!

Keyword

Page 13: Copy of dti2143/dam31303 chap 1 problem solving and program design

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 Degawanhave to pay for all the tin of paints he bought.

startread the amount_of_paintcompute the total_price as price_per_tin times by amount_of _paintdisplay/print the result (or the total_price)end

Write a program!

Keyword?

Page 14: Copy of dti2143/dam31303 chap 1 problem solving and program design

startread the student markif mark is greater than 85 and mark is less than 100, then set grade as Adisplay/print the gradeend

Keyword

Keyword

Keyword

Page 15: Copy of dti2143/dam31303 chap 1 problem solving and program design

startSet total to zeroSet grade counter to one

While grade counter is less than or equal to teninput the next gradeadd the grade into the totaladd one to the grade counter

Set the class average to the total divided by tenPrint the class averageend

Keyword

Keyword

Keyword

Page 16: Copy of dti2143/dam31303 chap 1 problem solving and program design
Page 17: Copy of dti2143/dam31303 chap 1 problem solving and program design

Schematic representation of an algorithm or process

Helps to visualize the content/steps better or to find flaws in processIllustrate the steps in the process

Use symbols to represent the

steps

Page 18: Copy of dti2143/dam31303 chap 1 problem solving and program design

Start/Stop (oval)The terminator symbol marks the starting or ending point of the system. It usually contains the word "Start" or "End."

Action or Process (rectangle)A box can represent a single step ("add two cups of flour"), or and entire sub-process ("make bread") within a larger process.

Page 19: Copy of dti2143/dam31303 chap 1 problem solving and program design

Decision (Diamond)A decision or branching point. Lines representing different decisions emerge from different points of the diamond.

Input/Output (Parallelogram)Represents material or information entering or leaving the system, such as customer order (input) or a product (output).

Page 20: Copy of dti2143/dam31303 chap 1 problem solving and program design

Flow LinesLines indicate the sequence of steps and the direction of flow.

On-Page ConnectorIndicates that the flow continues where a matching symbol (containing the same letter) has been placed in the same page.

Page 21: Copy of dti2143/dam31303 chap 1 problem solving and program design

Off-Page ConnectorIndicates that the process continues on another page.

Database / Disk Storage Input-Output SymbolIndicates input from or output to disk storage.

Page 22: Copy of dti2143/dam31303 chap 1 problem solving and program design
Page 23: Copy of dti2143/dam31303 chap 1 problem solving and program design

What software use to draw flowchart?

You can use Ms Word > AutoShapes> Flowchart or

other flowchart drawing tools e.g: SmartDraw/Visio Drawing,

Rational Rose,etc.

Page 24: Copy of dti2143/dam31303 chap 1 problem solving and program design

1. Sequence Structure a series of steps or statements that are executed in order.

begin

Statement_1

Statement_2

Statement_n

end

Statement 1

Statement 2

Statement..n

Page 25: Copy of dti2143/dam31303 chap 1 problem solving and program design

Read x

Read a

y = 2x + a - 6

Display y

Start

End

Page 26: Copy of dti2143/dam31303 chap 1 problem solving and program design

2. Selection Structure Define two courses of action depending on the outcome condition ( true or false)

Page 27: Copy of dti2143/dam31303 chap 1 problem solving and program design

How to go to BP Mall ?1. Begin2. Do you have a car ?3. If yes, drive your car towards BP Mall4. Or else go by bus5. Reach BP Mall 6. End

Page 28: Copy of dti2143/dam31303 chap 1 problem solving and program design

3. Repetition Control Structures Specifies a block of one or more statements that are repeatedly executed until a condition is satisfied.

while condition

loop-body

end_while

condition Loop_bodyYes

Page 29: Copy of dti2143/dam31303 chap 1 problem solving and program design

startSet total to zeroSet grade_counter to one

While grade_counter is less than or equal to teninput the next gradeadd the grade into the totaladd one to the grade_counter

Set the class average to the total divided by tenPrint the class averageend

Page 30: Copy of dti2143/dam31303 chap 1 problem solving and program design

startread the amount_of_paintcompute the total_price as price_per_tin times by amount_of paintdisplay/print the result (or the total price)end

startread the student markif mark is greater than 85 and mark is less than 100, then set grade as Adisplay/print the gradeend

Convert to

flowchar

Convert to

flowchart

Page 31: Copy of dti2143/dam31303 chap 1 problem solving and program design

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

Convert to

flowchart

Page 32: Copy of dti2143/dam31303 chap 1 problem solving and program design