Chapter 7 CASE Control Structure © 2008 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved. Marilyn Bohl/Maria Rynn Tools for Structured and Object-Oriented Design, 7e
Introduction We must provide flexibility in a solution algorithm, incorporating within the program an ability to process not only a variable number of inputs but also whatever type of input is provided. In business applications, large numbers of records are kept for reference purposes as relatively permanent data. Transaction file or detail file Current activities, or transactions, to be process against the master file.
Inventory Control Example Inventory-control stock status records of the numbers of various part types available for manufacturing planning. A transaction file is a temporary file containing data that is used to up date a master file.
Inventory Control Example
Master File Update Using Nested IFs (Partial Flowchart)
Master File Update Using Nested IFs (Partial Pseudocode)
Inventory Control Example Solution 1: Nested IFTHENELSE Control Structure IFTHENELSE We have to make four test, which amounts to a nesting level of four.
Inventory Control Example Solution 2: CASE Control Structure CASE control structure generalizes the basic IFTHENELSE pattern, extending it from a two- valued operation to a multiple-valued one. CASE control structure serves as an alternative for the nested IFTHENELSE, it cannot be used in place of a sequential IFTHENELSE pattern. Do not confuse CASE with computer-assisted software engineering. CASE is simply the name of a particular kind of control structure.
Master File Update Using CASE (Partial Flowchart)
Master File Update Using CASE (Partial Flowchart) cont.
Inventory Control Example For processing efficiency, the test most likely to reveal a true outcome should be made first, the next most likely one second, and so on. Minimize the number of tests actually carried out on any one pass. Other appears by the last flowline to indicate what processing should occur if none of the preceding conditions is true.
Master File Update Using CASE (Partial Pseudocode)
Sample Problem 7.1 Op Code Problem Design an algorithm to accept three values as input. First input value A (addition), S (subtraction), M (multiplication), or D (division) Other two input values will be numbers. The computer is to perform a computation on the two numbers.
Sample Problem 7.1 A single variable cannot be named to represent both numeric quantities and alphabetic data. Character strings Alphabetic data values. Character-string constant Set once and never changes during program execution. A value that is input during processing, is a character string, but it is not a character-string constant.
Op Code Problem (Flowchart)
Op Code Problem (Flowchart) cont.
Sales Problem without Modules (Flowchart)
Sales Problem without Modules (Flowchart) cont.
Sales Problem without Modules (Pseudocode)
Sample Problem 7.3 Sales Problem Using Modules Place all the steps within each CASE path in a separate.
Sales Problem Using Modules (Structure Chart)
Sales Problem Using Modules— Overall Control (Flowchart)
Sales Problem Using Modules— Overall Control (Flowchart) cont.
Sales Problem Using Modules— Overall Control (Pseudocode)
Sales Problem Using Modules— Process Class 1
Sales Problem Using Modules— Process Class 2
Sales Problem Using Modules— Process Class 3
Sales Problem Using Modules— Process Class 4
Sales Problem Using Modules— Process Invalid Class
Sample Problem 7.4 Sales Problem with Totals Process several records. Output a daily sales commission report. Report and column headings are to be output. Pages are to be numbered, and up to 55 detail lines. Five total lines are to be output on the last page of the report. End-of-file will be indicated by 0000.
Sales Problem with Totals (Structure Chart)
Sales Problem with Totals—Overall Control (Flowchart)
Sales Problem with Totals—Overall Control (Flowchart) cont.
Sales Problem with Totals—Overall Control (Pseudocode)
Sales Problem with Totals—Process Initialization
Sales Problem with Totals—Process a Detail Record (Flowchart)
Sales Problem with Totals—Process a Detail Record (Flowchart) cont.
Sales Problem with Totals—Process Detail Record (Pseudocode)
Sales Problem with Totals—Process Heading
Sales Problem with Totals—Process Class 1
Sales Problem with Totals—Process Class 2
Sales Problem with Totals—Process Class 3
Sales Problem with Totals—Process Class 4
Sales Problem with Totals—Process Invalid Class
Sales Problem with Totals—Process Totals
Sales Problem with Totals—Process Totals cont.
Enrichment Visual Basic Graphical interface for the op code problem.
Op Code Problem (Visual Basic— Screen 1)
Op Code Problem (Visual Basic— Screen 2)
Op Code Problem (Visual Basic— Screen 3)
Op Code Problem (Visual Basic— Screen 4)
Op Code Problem (Visual Basic— Screen 5)
Op Code Problem (Visual Basic— Screen 6)
Enrichment SELECT CASE and END SELECT are used in stead of the pseudocode keywords CASENTRY and ENDCASE. ELSE replaces the word other.
Op Code Problem (Visual Basic-- btnComute_Click)
Enrichment Another solution to this same problem.
Op Code Problem (Visual Basic— Screen 7)
Op Code Problem (Visual Basic— Screen 8)
Op Code Problem (Visual Basic— Screen 9)
Op Code Problem (Visual Basic— radAdd_Click)
Op Code Problem (Visual Basic— radSubtract_Click)
Op Code Problem (Visual Basic— radMultiply_Click)
Op Code Problem (Visual Basic— radDivide_Click)