Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

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

4,633 views

Published on

SLIDE CHAPTER 1

Published in: Technology, Education
  • Be the first to comment

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

  1. 1. Universiti Tun Hussien Onn Malaysia Faculty of Mechanical and Manufacturing Engineering
  2. 2. Scenarios in real life <ul><li>Withdraw money from ATM machine </li></ul><ul><li>Register subjects through online system </li></ul><ul><li>Buy cold drinks from vending machine </li></ul><ul><li>Calculate the monthly salary payment </li></ul><ul><li>Calculate car loan interest </li></ul><ul><li>Determine odd and even numbers </li></ul><ul><li>Count the total visitor of a Web </li></ul><ul><li>Determine air velocity in physic lab </li></ul>Program Design Method
  3. 3. <ul><li>Go to the ATM machine. </li></ul><ul><li>Insert ATM card. </li></ul><ul><li>Select language. </li></ul><ul><li>Enter pin number. </li></ul><ul><li>Select withdrawal option from menu. </li></ul><ul><li>Enter amount of money to withdraw. </li></ul><ul><li>Take the money. </li></ul><ul><li>Take the bank slip. </li></ul>Example 2: Money withdrawal algorithm Program Design Method
  4. 4. Algorithm Techniques Pseudocode Flowchart Program Design Method
  5. 5. 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
  6. 6. Pseudocode RULES Program Design Method <ul><li>Consist of a statement of instructions in sequence </li></ul><ul><li>Every step consists of keyword </li></ul><ul><li>Every step should be written in different step, if continued, </li></ul><ul><li>thru next row must be indented </li></ul><ul><li>if/else for condition, while/do for repetition </li></ul><ul><li>Every step must contain clear statement and easy to understand </li></ul><ul><li>Use start for beginning of operation, and end/halt for finishing it. </li></ul>
  7. 7. <ul><li>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: </li></ul><ul><li>Input (get or read), process/calculate (=) and output (display) </li></ul><ul><li>Start </li></ul><ul><li>get price of item </li></ul><ul><li>get sales tax rate </li></ul><ul><li>sales tax = price of item * sales tax rate </li></ul><ul><li>Final price = price of item + sales tax </li></ul><ul><li>display final price </li></ul><ul><li>7 halt/end </li></ul>Program Design Method Examples
  8. 8. 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
  9. 9. 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
  10. 10. Pseudocode <ul><li>Write the pseudo code based on the </li></ul><ul><ul><li>IPO (input/process/ </li></ul></ul><ul><li>output) which you have identified during the analyzing </li></ul><ul><li>phase </li></ul><ul><li>Identify the keyword(s) based on the IPO </li></ul>How? Chapter 1 Program Design Method
  11. 11. 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:
  12. 12. 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
  13. 13. 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
  14. 14. 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
  15. 15. 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
  16. 16. Question Program Design Method
  17. 17. Flowchart Schematic representation of an algorithm or process <ul><li>Helps to visualize the content/steps better or to find flaws in process </li></ul><ul><li>Illustrate the steps in the process </li></ul>Use symbols to represent the steps Chapter 1b Program Design Method
  18. 18. 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.
  19. 19. 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).
  20. 20. 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.
  21. 21. 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.
  22. 22. Flowchart Example Chapter 1 Program Design Method
  23. 23. 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
  24. 24. Chapter 1 Program Design Method Pseudocode and Flowchart Convention <ul><ul><li>1. Sequence Structure </li></ul></ul><ul><ul><ul><li> a series of steps or statements that are executed in order. </li></ul></ul></ul>begin Statement_1 Statement_2 … Statement_n end Statement 1 Statement 2 Statement..n
  25. 25. Flowchart Example Chapter 1 Program Design Method Read x Read a y = 2x + a - 6 Display y Start End
  26. 26. Chapter 1 Program Design Method Pseudo code and Flowchart Convention <ul><ul><li>2. Selection Structure </li></ul></ul><ul><ul><ul><li> Define two courses of action depending on the outcome condition </li></ul></ul></ul><ul><ul><ul><li>( true or false) </li></ul></ul></ul>
  27. 27. Flowchart Chapter 1 Program Design Method Pseudocode <ul><li>How to go to BP Mall ? </li></ul><ul><ul><li>1. Begin </li></ul></ul><ul><ul><li>2. Do you have a car ? </li></ul></ul><ul><ul><li>3. If yes, </li></ul></ul><ul><ul><li>drive your car </li></ul></ul><ul><ul><li>towards BP Mall </li></ul></ul><ul><ul><li>4. Or else </li></ul></ul><ul><ul><li>go by bus </li></ul></ul><ul><ul><li>5. Reach BP Mall </li></ul></ul><ul><ul><li>6. End </li></ul></ul>
  28. 28. Program Design Method <ul><ul><li>3 . Repetition Control Structures </li></ul></ul><ul><ul><ul><li> Specifies a block of one or more statements that are repeatedly </li></ul></ul></ul><ul><ul><ul><li>executed until a condition is satisfied . </li></ul></ul></ul>while condition loop-body end_while Pseudo code and Flowchart Convention
  29. 29. 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 ?
  30. 30. 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
  31. 31. 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
  32. 32. Question Chapter 1 Program Design Method

×