Clearly Visual Basic Programming with Visual Basic 2008
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 3 First You Need to Plan the Party
Objectives • Identify the output and input in a problem description • Plan an algorithm using pseudocode and flowcharts • Desk-check an algorithm Clearly Visual Basic: Programming with Visual Basic 2008 2
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 are the problem’s output and its input Clearly Visual Basic: Programming with Visual Basic 2008 3
Clearly Visual Basic: Programming with Visual Basic 2008 4
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 2008 5
Clearly Visual Basic: Programming with Visual Basic 2008 6
Clearly Visual Basic: Programming with Visual Basic 2008 7
Clearly Visual Basic: Programming with Visual Basic 2008 8
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 2008 9
Clearly Visual Basic: Programming with Visual Basic 2008 10
Step 2 – Plan the Algorithm (continued) • 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 2008 11
Clearly Visual Basic: Programming with Visual Basic 2008 12
Clearly Visual Basic: Programming with Visual Basic 2008 13
Clearly Visual Basic: Programming with Visual Basic 2008 14
Clearly Visual Basic: Programming with Visual Basic 2008 15
Step 3 – Desk-Check the Algorithm • Desk-checking (hand-tracing) – Programmer reviews algorithm while seated at his or her desk • 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 2008 16
Clearly Visual Basic: Programming with Visual Basic 2008 17
Go to Page 33 Desk Checking State Income Tax $23, 000 and 3% State Income Tax $23, 000 *. 03 = $690 $14, 000 * >02 = $280 Desk Check CD Purchase 20* $10. 50 = $210. 00 (Club Price) 20 * $14. 99 = $299. 80 (Regular Price) Total Savings = $89. 80 Clearly Visual Basic: Programming with Visual Basic 2008 19
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 2008 20
Summary (continued) • 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 2008 21
Review Questions- Page 37 1. Programmers refer to the items needed as: Input, output, processing or Purpose 2. The calculation instruction in an algorithm should state: only what is to be calculated, only how to calculate something, both what is to be calculated and how to calculate it 3. Most algorithms for this flow: (arrange the following) Entering the input items: Displaying, Printing or Storing the output items: Processing the output items 4. In a flowchart, what symbol represents an instruction that gets information from the user: enter, process, input/output, start/stop 5. When desk-checking an algorithm, set up a table that contains: one column for each input and one column for each output one column for each input and one column for each processing item, and one column for each input item, one column for each processing item, and one column for each output item
Review Answers- Page 37 1. Input 2. Both what is to be calculated and how to calculate it 3. Most algorithms for this flow: (arrange the following) Entering the input items: Processing the output items Displaying, Printing or Storing the output items: 4. Input/output 5. one column for each input item, one column for each processing item, and one column for each output item
Page 38 Exercise 3 Output: tip credit card charge Input: total bill liquor charge tip percentage Algorithm: 1. enter the total bill, liquor charge, and tip percentage 2. calculate the tip by subtracting the liquor charge from the total bill, and then multiplying the remainder by the tip percentage 3. calculate credit card charge by adding the tip to the total bill 4. display the tip and the credit card charge Desk-check table total billliquor charge tip percentage tip credit card charge 50 5. 2 9 59 15 0. 15 2. 25 17. 25 Clearly Visual Basic: Programming with Visual Basic 2008 24
Page 39 - Problem 7 Output total fee Input: base fee charge per miles driven Algorithm: 1. enter the base fee, charge per mile, and miles driven 2. calculate the rental fee by multiplying the charge per mile by the miles driven, and then adding the base fee to the result 3. display the rental fee Desk-check table rental fee base fee charge per miles driven 250 50. 2 1000 185 60. 25 500 Clearly Visual Basic: Programming with Visual Basic 2008 25
Page 39: Number 8 Output: total bill Processing: room charge ($55 * Number of Days) entertainment tax (Room Charge * Entertainment Percent) Input: per-night rate ($55) nights stayed entertainment tax rate room service charge telephone charge Algorithm: 1. enter the per-night rate, nights stayed, entertainment tax rate, room service charge, and telephone charge 2. calculate the room charge by multiplying the per-night rate by the nights stayed 3. calculate the entertainment tax my multiplying the room charge by the entertainment tax rate 4. calculate the total bill by adding together the room charge, entertainment tax, room service charge, and telephone charge DESK CHECK nights stayed entertainment tax rate room service charge telephone charge 2 . 05 10 5 room charge entertainment tax room service charge telephone charge total bill 110 5. 50 10 5 130. 50 Total Bill = $130. 50 Clearly Visual Basic: Programming with Visual Basic 2008 26
- Slides: 26