|
|
Problem Solving Techniques C Chapter 2 EC201 MOHD ZEID ABU BAKAR ELECTRICAL ENGINEERING DEPARTMENT SULTAN IDRISSHAH POLYTECHNIC
At the end of lesson, students should be able : OBJECTIVES Chapter 2 C List the stages involved in problem solving List & explain the elements (Input, Process, Output) of problem analysis. Determine the Input, Process & Output for a given problem. List, explain & apply the various design tools: Pseudocode Flowchart IPO Chart ZEDZ@PSIS
cont: OBJECTIVES Chapter 2 C Use the design tools to solve a given problem. Identify & explain the various types of errors Syntax Error Run-Time Error Logical Error ZEDZ@PSIS
PROBLEM SOLVING PHASE ? Chapter 2 C ZEDZ@PSIS Process of system development
PROBLEM SOLVING PHASE ? Chapter 2 C ZEDZ@PSIS Understand the problem: - Input Output - Process
PROBLEM SOLVING PHASE ? Chapter 2 C ZEDZ@PSIS Develop the solution (algorithm): - Pseudocode Flowchart - IPO Chart Algorithm – steps to solve problem by using a computer. TIPS!
PROBLEM SOLVING PHASE ? Chapter 2 C ZEDZ@PSIS Converting design to computer codes. e.g. Flowchart C program
PROBLEM SOLVING BY IPO TABLE Chapter 2 C How to create an IPO table: Establish input & output components Establish the actions required ZEDZ@PSIS
PROBLEM SOLVING BY IPO TABLE Chapter 2 C Step by step: Underline all the input values that must be entered by the user. Underline the output values that should be generated by the program. Underline all the verbs. Write the input variable names in the input column. Write the output variable names in the output column. Write the processing steps in the process column. ZEDZ@PSIS
PROBLEM SOLVING BY IPO TABLE Chapter 2 C Example 1: A program is required to get three numbers, add them together and display the total on the screen. ZEDZ@PSIS
PROBLEM SOLVING BY IPO TABLE Chapter 2 C Example 2: A program is required to get the maximum & minimum temperature readings from the user. Then calculate & display the average temperature. ZEDZ@PSIS
PROBLEM SOLVING BY PSEUDO CODE Chapter 2 C Pseudo code: Artificial & informal language Not an actual programming language Each line of code represent a step / process. Two types of pseudo codes: Similar to natural language Similar to programming language ZEDZ@PSIS
ADVANTAGES OF PSEUDO CODE Chapter 2 C Pseudo code: Modifying & converting a pseudo code to a programming language is easier than converting a flowchart ZEDZ@PSIS
PSEUDO CODE Chapter 2 C ZEDZ@PSIS
PSEUDO CODE Chapter 2 C ZEDZ@PSIS 1. Start 2. Step1 3. Step2 4. : 5. : 6. Step n 7. Stop Sequence Structure Simple direct solution
PSEUDO CODE Chapter 2 C ZEDZ@PSIS 1. Start 2. Read A & B 3. Multiply A & B puts in C 4. Display C 5. End Sequence Structure Sample Write a program that accept two numbers & display the multiplication of the number. Read A, B Calculate C = A*B Display C Stop - NATURAL LIKE - - PROGRAMMING LIKE -
PSEUDO CODE Chapter 2 C ZEDZ@PSIS n. If condition true n.1 true statement 1 n.2 true statement 2 : n.n true statement n m. Else m.1 false statement 1 m.2 false statement 2 : m.n false statement n Selection Structure Problem that require process of selection between 2 or more variables
PSEUDO CODE Chapter 2 C ZEDZ@PSIS 1. Start 2. Read A and B 3. If A is less than B 3.1 big = B 3.2 small = A 4. Else 4.1 big = A 4.2 small = B 5. Display big and small 6. End Selection Structure Sample Write a program that accept two numbers & differentiate between the bigger & smaller number. Read A, B If A < B big = B small = A Else big = A small = B Display big, small Stop - NATURAL LIKE - - PROGRAMMING LIKE -
PSEUDO CODE Chapter 2 C ZEDZ@PSIS : n-2 statement n-2 n-1 statement n-1 n go to step n-2 n+1 statement n+1 n+2 statement n+2 : : Repetition Structure Problem that requires iteration of similar processes
PSEUDO CODE Chapter 2 C ZEDZ@PSIS 1. Initialized Sum to 0 2. Set Counter to 0 3. If counter > 5 go to 5 3.1 Ask user to enter Number 3.2 Increment counter by 1 3.3 Sum = Sum + Num 4. Go to 3 5. Display Sum 6. End Repetition Structure Sample Sum up 5 numbers entered by user and display the value Sum = 0 Counter = 0 While Counter < 5 Ask user to enter Num Counter = Counter + 1 Sum = Sum + Num Display Sum Stop - NATURAL LIKE - - PROGRAMMING LIKE -
Summary: Design tools - pseudocode - flowchart - IPO table
| URL: |
No comments posted yet
Comments