210 likes | 488 Views
Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition. Chapter 2 First You Need to Plan the Party (Problem-Solving Process). Objectives. After studying Chapter 2, you should be able to: Identify the output and input in a problem specification
E N D
Clearly Visual Basic: Programming with Visual Basic 2010 2nd Edition Chapter 2 First You Need to Plan the Party (Problem-Solving Process)
Objectives After studying Chapter 2, you should be able to: • Identify the output and input in a problem specification • Plan an algorithm using pseudocode and flowcharts • Desk-check an algorithm Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
How Do Programmers Solve Problems? • You cannot solve a problem unless you understand it • You cannot understand a problem unless you analyze it • Most important components of any problem • Problem’s output and its input Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
How Do Programmers Solve Problems? (cont’d.) Figure 2-1 Steps for solving a problem using a computer Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
Step 1 – Analyze the Problem • Identify output • What does the user want to see printed on paper, displayed on the screen, or stored in a file? • Identify input • What information will the computer need to know to print, display, or store the output items? • Analysis step is most difficult problem-solving step Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
Step 1 – Analyze the Problem (cont’d.) Figure 2-2 Problem specification for Addison Smith Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
Step 1 – Analyze the Problem (cont’d.) Figure 2-3 Output and input items for the Addison Smith problem Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
Step 1 – Analyze the Problem (cont’d.) Figure 2-4 Problem specification for Aiden Turner Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
Step 1 – Analyze the Problem (cont’d.) Figure 2-5 Output and input items for the Aiden Turner problem Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
Step 2 – Plan the Algorithm • Pseudocode • False code, not standardized • Cannot be understood by a computer • Used by programmers when planning an algorithm • Flowchart • Uses standardized symbols to visually depict an algorithm Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
Step 2 – Plan the Algorithm (cont’d.) Figure 2-6 Output, input, and algorithm items for the Addison Smith problem Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
Step 2 – Plan the Algorithm (cont’d.) • Flowchart symbols • Oval: start/stop symbol • Parallelogram: input/output symbol • Rectangle: process symbol • Flowlines • Connect symbols • Processing item • Intermediate value that algorithm uses when processing input into output Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
Figure 2-7 Flowchart for the Addison Smith problem’s algorithm Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
Figure 2-8 Output, input, and algorithm for the Aiden Turner problem Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
Figure 2-9 A different solution to the Aiden Turner problem Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
Figure 2-10 Flowchart for the algorithm shown in Figure 2-9 Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
Step 3 – Desk-Check the Algorithm • Desk-checking • Also called hand-tracing • Follow each of the algorithm’s instructions by hand • Choose sample data for input values • Manually compute expected output values • Valid data • Data that algorithm is expecting user to enter • Invalid data • Data that algorithm is not expecting user to enter Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
Figure 2-11 Addison Smith solution and desk-check table Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
Figure 2-16 Aiden Turner solution and desk-check table Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
Summary • First three steps in the problem-solving process • Analyze the problem • Plan the algorithm • Desk-check the algorithm • Programmers use tools to organize their thoughts • Pseudocode • Flowcharts Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition
Summary (cont’d.) • Algorithm • Enter data • Process data • Display, print, or store data • Calculation instructions in an algorithm • Specify what is to be calculated and how to perform calculation • After completing analysis and planning steps: • Programmer desk-checks algorithm Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition