
[Audio] Lecture 13 & 14 MODULAR PROGRAMMING & PROBLEM SOLVING TECHNIQUES Pusat Asasi Sains, Universiti Malaya.
[Audio] LEARNING OUTCOME: At the end of this topic, students should be able to: Identify input, process and output from a given problem. To analyze the problem using Problem Analysis Chart (PAC) Use an IPO chart to designate the input, processing, and output for a solution of a problem Solve problem using flow chart..
[Audio] TYPES OF PROBLEMS IN NATURE ALGORITHMIC SOLUTIONS Solutions for the given problems can be reached by completing the series of action in steps ‘Computer dominated’ HEURISTIC SOLUTIONS Solutions require reasoning built on knowledge & experience with process of trial & error. ‘Human dominated’ as naturally having emotional factors, i.e. unsatisfactory & uncertainty. Innovation ~ Artificial Intelligence & fifth-generation languages (5GL)..
[Audio] Problem Solving. Problem Solving.
[Audio] . Input a list of data source provided to the problem Problem??? Separate into three components Output a list of the output required Processing a list of actions needed to produce the required outputs.
[Audio] Problem Solving in Programming Programming is a process of problem solving Problem solving techniques Analyze the problem Outline the problem requirements Specify what the solution should do Design steps, called an algorithm, to solve the problem (the general solution) Verify that your solution really solves the problem.
[Audio] Organising Problems Certain organisational tools can help us to solve problems :- Problem Analysis Charts – a beginning analysis of the problem Structure/Interactivity Charts – shows the overall layout or structure of the solution.
[Audio] Organising Problems IPO Chart – shows the input, the processing and the output Algorithm – show the sequence of instructions comprising the solution Flowcharts – graphic representations of the algorithms.
[Audio] What is PAC? PAC (Problem Analysis Chart) According to Sprankle and Hubbard, (2012), the initial step for a programs need to do when get a problem is to analyze and understand the requirements. To easily analyze the problem, a Problem Analysis Chart (PAC) was introduced. This chart have four section: — The given data — The required result — The processing involved — A list of solution alternative.
[Audio] Problem Analysis Chart (PAC) separates the problem in 4 parts Given Data Required Results Section 1:Data given in the problem or provided by user-Data, constants, variables Section 2:Requirements to produce the output-information and format required Processing required Solution alternatives Section 3:List of processing required – equations, or searching or sorting techniques Section 4: List of ideas for the solution..
[Audio] Example1: Write a Problem Analysis Chart (PAC) to convert any Number in distance in miles to kilometers per mile. (1mile = 1.609km) Given Data Required Results Processing required Solution alternatives.
[Audio] Example 2: Write a Problem Analysis Chart (PAC) to find an area of a circle where area = pi * radius * radius Given Data Required Results Processing required Solution alternatives.
[Audio] Example 3: Write a problem analysis chart (PAC) that asks a user to enter the distance of a trip in miles, the miles per gallon estimate for the user’s car, and the average cost of a gallon of gas. Calculate and display the number of gallons of gas needed and the estimated cost of the trip. Given Data Required Results Processing required Solution alternatives.
[Audio] . Try This!!! PROBLEM: A program is required to find the volume of a cube. Please construct the PAC for this problem. Given Data Processing Required Required Result Solution Alternative.
[Audio] . Extends information in PAC and modules in Have 4 parts What is IPO? IPO (Input — Processing - Output) Emphasizing the three components of problem (input, processing and output).
[Audio] Input Process Output (IPO) Analysis The IPO is used to analyze problems and develop algorithms Used to organize and summarize the results of a problem analysis It shows where in the solution the processing takes place.
[Audio] 2.Input Process Output (IPO) Analysis Represented using IPO chart Input Processing Output All input data (from Section 1 of the PAC) All processing steps (from sections 3 and 4 of the PAC) Processing items: All output requirements (from sections 1 and 2 of the PAC) Algorithm:.
[Audio] 2.Input Process Output (IPO) Analysis Input : Process : Output : To do the IPO Analysis, start with: Output (Display the results) Input (Read the data) Process (Perform the computation) Identify.
[Audio] 2. Input Process Output (IPO) Analysis Output should answer the following question: What does the user want to see printed on the printer, displayed on the screen, or stored in a file?.
[Audio] 2. Input Process Output (IPO) Analysis Input should answer the following question: What information will the computer need to know to print, display, or store the output items?.
[Audio] 2. Input Process Output (IPO) Analysis Processing item: An intermediate value that the algorithm uses when processing the input into the output.
[Audio] Analyze the Problem What is it you are trying to accomplish? What outcome you are trying to arrive at? List the Inputs and Outputs Often you work backwards from the Output List the Outputs, and then figure out what Inputs you need in order to arrive at the Output.
[Audio] Example1: Write an Input Process Output (IPO) to convert any Number in distance in miles to kilometers per mile. (1mile = 1.609km) Analyze the Problem Problem Analysis: Input: Process: Output:.
[Audio] IPO chart: Input Processing Output Processing items: Algorithm:.
[Audio] Example 2: Write an Input Process Output (IPO) to find an area of a circle where area = pi * radius * radius Analyze the Problem Problem Analysis: Input: Process: Output:.
[Audio] IPO chart: Input Processing Output Processing items: Algorithm:.
[Audio] Example 3: Write an Input Process Output (IPO) that asks a user to enter the distance of a trip in miles, the miles per gallon estimate for the user’s car, and the average cost of a gallon of gas. Calculate and display the number of gallons of gas needed and the estimated cost of the trip. Analyze the Problem Problem Analysis: Input: Process: Output:.
[Audio] IPO chart: Input Processing Output Processing items: Algorithm:.
[Audio] What is Flow Chart? Program flowcharts show the sequence of instructions in a single program or subroutine. Different symbols are used to draw each type of flowchart. A Flowchart shows logic of an algorithm emphasizes individual steps and their interconnections e.g. control flow from one action to the next.
[Audio] 3. Flow Chart Graphical representation of an algorithm. Special-purpose symbols connected by arrows (flow lines)..
[Audio] Four Flowchart Structures Sequence Selection Repetition Case.
[Audio] . Flowchart Symbols Terminal symbol - indicates the beginning and end points of an algorithm. Process symbol - shows an instruction other than input, output or selection. Input-output symbol - shows an input or an output operation. Disk storage 1/0 symbol - indicates input from or output to disk storage. Printer output symbol - shows hardcopy printer output..
[Audio] . O I Flowchart Symbols cont... Selection symbol - shows a selection process for two-way selection. Off-page connector - provides continuation of a logical path on another page. On-page connector - provides continuation of logical path at another point in the same page. Flow lines - indicate the logical sequence of execution steps in the algorithm..
[Audio] Sequence Structure a series of actions are performed in sequence The pay-calculating example was a sequence flowchart..
[Audio] Example1: Write a Flowchart to solve the problem of converting any Number in distance in miles to kilometers per mile. (1mile = 1.609km).
[Audio] Example 2: Write a Problem Analysis Chart (PAC) to find an area of a circle where area = pi * radius * radius pi - pi=22/7.
[Audio] Example 3: Write a problem analysis chart (PAC) that asks a user to enter the distance of a trip in miles, the miles per gallon estimate for the user’s car, and the average cost of a gallon of gas. Calculate and display the number of gallons of gas needed and the estimated cost of the trip..
[Audio] Selection Structure One of two possible actions is taken, depending on a condition..
[Audio] Selection Structure A new symbol, the diamond, indicates a yes/no question. If the answer to the question is yes, the flow follows one path. If the answer is no, the flow follows another path YES NO.
[Audio] Selection Structure In the flowchart segment below, the question “is x < y?” is asked. If the answer is no, then process A is performed. If the answer is yes, then process B is performed. YES NO x < y? Process B Process A.
[Audio] Selection Structure The flowchart segment below shows how a decision structure is expressed in C++ as an if/else statement. Flowchart C++ Code YES NO x < y? a= x + y a= x * 2 if (x < y) a = x * 2; else a = x + y;.
[Audio] Selection Structure The flowchart segment below shows a decision structure with only one action to perform. It is expressed as an if statement in C++ code. YES NO x < y? Calculate a as x times 2. if (x < y) a = x * 2;.
[Audio] Example1: Write a Flowchart to solve the problem of ADD two numbers if number One less than number Two and MULTIPLY two numbers if number One greater than number Two. Data Processing Output Processing item: Algorithm:.
[Audio] Repetition Structure A repetition structure represents part of the program that repeats. This type of structure is commonly known as a loop..
[Audio] Repetition Structure Notice the use of the diamond symbol. A loop tests a condition, and if the condition exists, it performs an action. Then it tests the condition again. If the condition still exists, the action is repeated. This continues until the condition no longer exists. Yes No.
[Audio] Repetition Structure In the flowchart segment, the question “is x < y?” is asked. If the answer is yes, then Process A is performed. The question “is x < y?” is asked again. Process A is repeated as long as x is less than y. When x is no longer less than y, the repetition stops and the structure is exited. x < y? Process A YES NO.
[Audio] Repetition Structure The flowchart segment below shows a repetition structure expressed in C++ as a while loop. Flowchart C++ Code while (x < y) x++; x < y? Add 1 to x YES NO.
[Audio] Controlling a Repetition Structure The action performed by a repetition structure must eventually cause the loop to terminate. Otherwise, an infinite loop is created. In this flowchart segment, x is never changed. Once the loop starts, it will never end. QUESTION: How can this flowchart be modified so it is no longer an infinite loop? x < y? Display x YES NO.
[Audio] Controlling a Repetition Structure ANSWER: By adding an action within the repetition that changes the value of x. x < y? Display x Add 1 to x YES NO.
[Audio] A Pre-Test Repetition Structure This type of structure is known as a pre-test repetition structure. The condition is tested BEFORE any actions are performed. NO.