Chapter 3 Planning Your Solution-mod.pptx

Full Transcript

PLANNING YOUR SOLUTION Chapter Three OVERVIEW ▪ Communicating with the Computer ▪ Organizing the Solution ▪ Analyzing the Problem ▪ Developing the IPO Chart ▪ Writing the Algorithms ▪ Drawing the Flowcharts ▪ Pseudocode ▪ Internal and External Documentation OBJECTIVES ▪ When you have finished this c...

PLANNING YOUR SOLUTION Chapter Three OVERVIEW ▪ Communicating with the Computer ▪ Organizing the Solution ▪ Analyzing the Problem ▪ Developing the IPO Chart ▪ Writing the Algorithms ▪ Drawing the Flowcharts ▪ Pseudocode ▪ Internal and External Documentation OBJECTIVES ▪ When you have finished this chapter, you should be able to: 1. List and describe the eight basic tools used in this book to aid in the development of a solution to a problem. 2. Use a problem analysis chart to consolidate data for a problem. 3. Use an IPO chart to designate the input, processing, module number, and output for a solution of a problem. 4. Use algorithms, flowcharts, and pseudocode to develop the instructions for each module in the solution of a problem. COMMUNICATING WITH THE COMPUTER ▪ Since the computer does not speak English as you do, you have to learn its system of communication or language. ▪ If the instructions you write are incorrect, the computer will give an error message, the wrong answer, or no answer at all. ▪ If the instructions are not properly sequenced, the computer will, nevertheless, execute them in the order given, and the result will be wrong. ▪ The meaning of an instruction (semantic) is essentially the same in any computer language or application. ▪ The differences between instructions from one language and another are in how they are set up (Syntax). COMMUNICATING WITH THE COMPUTER ▪ Syntax refers to the rules governing the computer operating system, the language, and the application. ▪ An error is called a bug. ▪ A bug must be found and corrected, a process called debugging. ▪ Many bugs are a result of syntax errors, but some are logic errors. ORGANIZING THE SOLUTION ▪ To analyze a problem and set up the most efficient solution, a programmer organizes the solution by using all or some of the following tools: ▪ problem analysis chart, which shows a beginning analysis of the problem; ▪ structure chart or interactivity chart, which shows the overall layout or structure of the solution; ▪ IPO chart, which shows the input, the processing, and the output; ▪ algorithms, which show the sequence of instructions comprising the solution; ▪ flowcharts, which are graphic representations of the algorithms ▪ pseudocode, which represents a language like solution ORGANIZING THE SOLUTION ▪ A coupling diagram shows the relationship between the modules and the data needed for the modules. ▪ The Data Dictionary lists all variable names and their definitions. ▪ UML (Unified Modeling Language) is a basic tool when using Object Oriented Programming structure. ▪ When the programmer does not use these tools during the problemsolving process, ▪ the solution takes longer to program, ▪ and the final program is less efficient, ▪ lacks readability, ▪ and increases programmer frustration. ANALYZING THE PROBLEM ▪ A good way to analyze a problem is to separate it into four parts, shown in the problem analysis chart (PAC) 1. The given data 2. The required results 3. The processing that is required in the problem 4. A list of solution alternatives ANALYZING THE PROBLEM CONT. EXAMPLE – PROBLEM ANALYSIS ▪ Calculate the gross pay of an employee given the hours worked and the rate of pay. The gross pay is calculated by multiplying the hours worked by the rate of pay. PROBLEM - PAC ▪ Problem 1: Write a Problem Analysis Chart (PAC) to convert the distance in miles to kilometers where 1.609 kilometers per mile. Dis_KM= Dis_Miles *1.609 ▪ Problem 2 Write a Problem Analysis Chart (PAC) to find an area of a circle where area = pi * radius * radius ▪ Problem 3 Write a Problem Analysis Chart (PAC) to compute and display the temperature inside the earth in Celsius and Fahrenheit. The relevant formulas are Celsius = 10 x (depth) + 20, Fahrenheit = 1.8 x (Celsius) + 32 DEVELOPING THE INTERACTIVITY CHART ▪ Interactivity Chart (structure chart) divides the processing into subtasks called modules and then to connect these modules together to show the interaction of processing between the modules. ▪ Each module should contain the tasks to accomplish one function, such as entering data, printing results, or calculating results. ▪ one module controls the flow to most of the other modules. This is called the Control or Main module. ▪ This breakdown enables you to view a complex problem in simpler parts and to program smaller, simpler parts of a program rather than one large, complex program. INTERACTIVITY CHART DEVELOPING THE IPO CHART ▪ The IPO (input-processing-output) chart extends and organizes the information in the problem analysis chart ▪ It shows in more detail what data items are input, what processing takes place on that data, and what information will be the end result, the output. The IPO chart also shows where in the solution the processing takes place. IPO CHART GROSS PAY – IPO CHART WRITING THE ALGORITHMS ▪ After using the interactivity chart and the IPO chart, the next step in organizing a solution is for the programmer to develop sets of instructions for the computer, called algorithms ▪ To complete all of the algorithms needed to solve a problem, the programmer writes a separate set of instructions for each module in the structure chart. ▪ The instructions cannot assume anything, cannot skip steps, must be executable one step at a time, and must be complete. ▪ The modules are taken from the interactivity chart, and the processing is taken from the IPO chart. ▪ The algorithms pull the interactivity chart and the IPO chart together to give a logical step-by step solution. WRITING ALGORITHM Control module uses an End since this is the end of the processing. The other modules use Exit because the processing continues. DRAWING THE FLOWCHARTS ▪ From the algorithms the programmer develops the flowcharts ▪ Flow chart is a graphic representations of the algorithms. ▪ The algorithms and the flowcharts are the final steps in organizing a solution. ▪ Using them, the programmer can test the solution for bugs and go on to code the problem into a computer language. ▪ A flowchart will show errors in logic not readily visible in the other charts. Also, a set of data can be tested easily using a flowchart. FLOWCHART SYMBOLS (1) FLOWCHART SYMBOLS (2) FLOWCHART SYMBOLS (3) FLOWCHART SYMBOLS (3) FLOWCHART SYMBOLS (3) FLOWCHART SYMBOLS (3) FLOWCHART SYMBOLS (3) GROSS PAY- CONTROL MODULE GROSS PAY – READ MODULE GROSS PAY – CALC MODULE GROSS PAY – PRINT MODULE RULES FOR DRAWING FLOWCHARTS RULES FOR DRAWING FLOWCHARTS PSEUDOCODE ▪ Pseudocode is similar to the algorithm without the numbers and somewhat condensed. INTERNAL AND EXTERNAL DOCUMENTATION ▪ Internal documentation consists of remarks written with the instructions to explain what is being done in the program. ▪ External documentation is made up of the manuals or help menus written about the solution.

Use Quizgecko on...
Browser
Browser