Presentation on theme: "Chapter 3 Planning Your Solution"— Presentation transcript:
1 Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer
2 Overview Communicating with the Computer Organizing the Solution with ToolsTesting the SolutionCoding the Solution
3 Objectives List and describe development tools Use problem analysis chartUse interactivity chartUse IPO chartUse algorithms (flowcharts and pseudocode)Describe importance of documentation
4 Communicating with Computer We use programming language to communicate with a computerDifferent type of programming language applies different syntax.Syntax: the rules governing the computer operating system, language and applicationBug : Coding error in a computer programDebugging: Process to find and correct the coding errors (bugs)
5 Organizing Solution with Tools Four (4) categories of tools can be used to solve problems on a computer:Problem Analysis Chart (PAC)Interactivity Chart / Structure ChartIPO ChartAlgorithmFlowchartpseudocode
6 Problem Analysis Chart (PAC) Shows a beginning analysis of the problemProgrammer will try to understand and analyze requirements of the problemAllows programmer to glean only facts from the problemSeparated into four (4) parts:The given dataThe required resultsThe processing that is required in the problemA list of solution alternatives
9 Interactivity Chart / Structure Chart Shows the overall layout or structure of the solutionDivide the processing identified into subtasks called modulesthese modules are connected together to show the interaction of processing between modulesEach module contain tasks for one function, not more than 20 instructionsExample of function:Enter dataPrint resultcalculate result
10 Interactivity Chart (Cont.) All modules are being controlled by a Control or Main ModuleThe breakdown (in the format of chart) allows programmer to view a complex problem in a few simpler parts.
11 Example of Interactivity Chart Do you know what are these symbols???Triangle on upper left of box??Circle in chart??Diamond shape after Module2??
12 Basic Interactivity Chart for the Payroll Problem The control module, read module, calculation module, and print module are BASIC to most programs.From there, add other modules as needed along with the addition of processing symbols to show:DuplicatesDecisionRepetition in a loop
13 Completed Interactivity Chart – The Payroll Problem
14 IPO ChartExtends and organizes information in problem analysis chart (PAC)Consists of four (4) main sections:InputProcessingModule referenceOutput
15 Is the sequence logical?? Why?? IPO Chart (Cont.)Shows more detail/information about:What data items are input??What processing takes place on each specific data??What information is output??Sequence of completing IPO Chart:OutputInputProcessingIs the sequence logical?? Why??
17 Algorithm Shows the sequence of instructions, which will form solution A good algorithm’s criteria:Instructions cannot assume anythingCannot skip stepsMust be executable one step at a timeMust be 100% completeTwo types of algorithm representation:FlowchartPseudocode
18 FlowchartGraphical representation of algorithm, which shows the flow of the processing from the beginning to the end of a solution.A flowchart always starts at the top of the page and flows to the bottomThere are flowchart symbols for use with various types of processing.
23 Calc Module in the Payroll Problem Flowchart –Calc Module in the Payroll Problem
24 Flowchart and Pseudocode for Print Module in the Payroll Problem
25 Overall Flowchart - The Payroll Problem How to simplify this flowchart??
26 Pseudocode Algorithm which is represented in simple English form Each instruction is written on a separate lineStarts with “Start/Begin” and terminates with “End”Keywords and instructions are written from top to bottom, with only ONE entry and ONE exit.Groups of statements are formed into module, and each module is given a specific name (however, this is optional).
27 Pseudocode (Cont.) Important keywords: A computer can receive informationKeyword: Read, GetA computer can show informationKeyword: Display, Print, WriteA computer can perform arithmetic calculation
28 Pseudocode (Cont.) A computer can assign value to memory location Keyword: Set, InitializeA computer can compare two variables to decide which action to be takenKeyword; IF….ELSE…..END_IFA computer can repeat a group of action.Keyword: WHILE…END_WHILE, REPEAT…..UNTIL
29 Overall Pseudocode – The Payroll Problem Begin REPEAT Get Hours, PayRate GrossPay = Hours * PayRate Display GrossPay UNTIL NoMoreEmployee = True End
30 Exercise (1)Try to organize solution for problem illustrated below, with the help of FOUR (4) tools that you have learnt in this chapter.Build a program that read the value of the height, width and length of a box from the user and print its volume.
31 Exercise (2)Try to organize solution for problem in pp.76, PROBLEMS, Q6 with the help of FOUR (4) tools that you have learnt in this chapter.
32 Documentation Consists of two main types: Internal documentation External documentation
33 Internal Documentation For programmersMade up of remarks written with the instructions to explain what is being done in the computer program, so that it can b easily understood by other programmersExample:what is the main purpose of developing this programWhat are the meaning of certain code blocksStatus of program development??
34 External Documentation For end usersMade up of manuals or help menus written about the solutions.Example:Tutorial which shows the steps to use programInstallation instructionHelp files??
35 Testing the Solutionto make sure that the solution meets requirements of userto check for errors in logic or in setup of the expressions and equations.programmer selects test data (a set of values for input data)and works them through every step in the solution.Example: to test expression X/YTest data for X and Y should be any numbers other than 1. WHY??
36 Coding the SolutionTo be performed after the completion of analyzing problem and organizing the solution.A process of converting algorithm into real program by using appropriate type of programming languagePython : to be covered in practical class