Like this presentation? Why not share!

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

## by Alish Al-shahab, Instructor at Uthm on Jun 28, 2011

• 3,654 views

SLIDE CHAPTER 1

SLIDE CHAPTER 1

### Views

Total Views
3,654
Views on SlideShare
3,652
Embed Views
2

Likes
2
133
0

### 1 Embed2

 http://www.techgig.com 2

### Categories

Uploaded via SlideShare as Microsoft PowerPoint

## Copy of dti2143/dam31303 chap 1 problem solving and program designPresentation Transcript

• Universiti Tun Hussien Onn Malaysia Faculty of Mechanical and Manufacturing Engineering
• Scenarios in real life
• 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
Program Design Method
• Go to the ATM machine.
• Insert ATM card.
• Select language.
• Enter pin number.
• Select withdrawal option from menu.
• Enter amount of money to withdraw.
• Take the money.
• Take the bank slip.
Example 2: Money withdrawal algorithm Program Design Method
• Algorithm Techniques Pseudocode Flowchart Program Design Method
• A text-based design tool that helps programmers to develop algorithm Pseudocode 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) Program Design Method Using natural language (communication language e.g: Malay/English) wording phrase
• Pseudocode RULES Program Design Method
• Consist of a statement of instructions in sequence
• Every step consists of keyword
• Every step should be written in different step, if continued,
• thru next row must be indented
• if/else for condition, while/do for repetition
• Every step must contain clear statement and easy to understand
• Use start for beginning of operation, and end/halt for finishing it.
• 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)
• Start
• get price of item
• get sales tax rate
• sales tax = price of item * sales tax rate
• Final price = price of item + sales tax
• display final price
• 7 halt/end
Program Design Method Examples
• if student's grade is greater than or equal to 60 print the statement &quot;passed&quot; else print the statement &quot;failed&quot; Examples 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 Program Design Method
• 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 . Examples Keyword? set means assign the value,e.g: total = 0 while is used whenever the process is to be continued Program Design Method
• Pseudocode
• 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
How? Chapter 1 Program Design Method
• Problem example 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 Chapter 1 Program Design Method Example 1:
• Given the value of x is 10 and a is 12, find the result of the following equation: y = 2x + a - 6 Example 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 Pseudocode Write a program! Keyword Program Design Method
• 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. 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 Pseudocode Write a program! Keyword? Program Design Method
• 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 Pseudocode Keyword Keyword Keyword Program Design Method
• start 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 add one to the grade counter Set the class average to the total divided by ten Print the class average end Pseudocode Keyword Keyword Keyword Program Design Method
• Question Program Design Method
• Flowchart 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
Use symbols to represent the steps Chapter 1b Program Design Method
• Flowchart Symbols Chapter 1b Program Design Method Start/Stop (oval) The terminator symbol marks the starting or ending point of the system. It usually contains the word &quot;Start&quot; or &quot;End.&quot; Action or Process (rectangle) A box can represent a single step (&quot;add two cups of flour&quot;), or and entire sub-process (&quot;make bread&quot;) within a larger process.
• Flowchart Symbols Chapter 1 Program Design Method 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).
• Flowchart Symbols Chapter 1 Program Design Method Flow Lines Lines indicate the sequence of steps and the direction of flow. On-Page Connector Indicates that the flow continues where a matching symbol (containing the same letter) has been placed in the same page.
• Flowchart Symbols Chapter 1 Program Design Method Off-Page Connector Indicates that the process continues on another page. Database / Disk Storage Input-Output Symbol Indicates input from or output to disk storage.
• Flowchart Example Chapter 1 Program Design Method
• Example 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. Flowchart Chapter 1 Program Design Method
• Chapter 1 Program Design Method Pseudocode and Flowchart Convention
• 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
• Flowchart Example Chapter 1 Program Design Method Read x Read a y = 2x + a - 6 Display y Start End
• Chapter 1 Program Design Method Pseudo code and Flowchart Convention
• 2. Selection Structure
•  Define two courses of action depending on the outcome condition
• ( true or false)
• Flowchart Chapter 1 Program Design Method Pseudocode
• How to go to BP Mall ?
• 1. Begin
• 2. Do you have a car ?
• 3. If yes,
• towards BP Mall
• 4. Or else
• go by bus
• 5. Reach BP Mall
• 6. End
• Program Design Method
• 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 Pseudo code and Flowchart Convention
• start 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 add one to the grade_counter Set the class average to the total divided by ten Print the class average end Pseudocode Chapter 1 Program Design Method Flowchart How ?
• 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 Try yourself! Convert to flowchar Convert to flowchart Chapter 1 Program Design Method
• 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 Try yourself! Program Design Method
• Question Chapter 1 Program Design Method