Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 7 CASE Control Structure © 2008 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved. Marilyn Bohl/Maria Rynn Tools for Structured.

Similar presentations


Presentation on theme: "Chapter 7 CASE Control Structure © 2008 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved. Marilyn Bohl/Maria Rynn Tools for Structured."— Presentation transcript:

1 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

2 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.

3 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.

4 Inventory Control Example

5 Master File Update Using Nested IFs (Partial Flowchart)‏

6 Master File Update Using Nested IFs (Partial Pseudocode)‏

7 Inventory Control Example Solution 1: Nested IFTHENELSE Control Structure  IFTHENELSE We have to make four test, which amounts to a nesting level of four.

8 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.

9 Master File Update Using CASE (Partial Flowchart)‏

10 Master File Update Using CASE (Partial Flowchart) cont.

11 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.

12 Master File Update Using CASE (Partial Pseudocode)‏

13 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.

14 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.

15 Op Code Problem (Flowchart)‏

16 Op Code Problem (Flowchart) cont.

17 Sales Problem without Modules (Flowchart)‏

18 Sales Problem without Modules (Flowchart) cont.

19 Sales Problem without Modules (Pseudocode)‏

20

21 Sample Problem 7.3 Sales Problem Using Modules  Place all the steps within each CASE path in a separate.

22 Sales Problem Using Modules (Structure Chart)‏

23 Sales Problem Using Modules— Overall Control (Flowchart)‏

24 Sales Problem Using Modules— Overall Control (Flowchart) cont.

25 Sales Problem Using Modules— Overall Control (Pseudocode)‏

26 Sales Problem Using Modules— Process Class 1

27 Sales Problem Using Modules— Process Class 2

28 Sales Problem Using Modules— Process Class 3

29 Sales Problem Using Modules— Process Class 4

30 Sales Problem Using Modules— Process Invalid Class

31 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.

32 Sales Problem with Totals (Structure Chart)‏

33 Sales Problem with Totals—Overall Control (Flowchart)‏

34 Sales Problem with Totals—Overall Control (Flowchart) cont.

35 Sales Problem with Totals—Overall Control (Pseudocode)‏

36 Sales Problem with Totals—Process Initialization

37 Sales Problem with Totals—Process a Detail Record (Flowchart)‏

38 Sales Problem with Totals—Process a Detail Record (Flowchart) cont.

39 Sales Problem with Totals—Process Detail Record (Pseudocode)‏

40 Sales Problem with Totals—Process Heading

41 Sales Problem with Totals—Process Class 1

42 Sales Problem with Totals—Process Class 2

43 Sales Problem with Totals—Process Class 3

44 Sales Problem with Totals—Process Class 4

45 Sales Problem with Totals—Process Invalid Class

46 Sales Problem with Totals—Process Totals

47 Sales Problem with Totals—Process Totals cont.

48 Enrichment Visual Basic  Graphical interface for the op code problem.

49 Op Code Problem (Visual Basic— Screen 1)‏

50 Op Code Problem (Visual Basic— Screen 2)‏

51 Op Code Problem (Visual Basic— Screen 3)‏

52 Op Code Problem (Visual Basic— Screen 4)‏

53 Op Code Problem (Visual Basic— Screen 5)‏

54 Op Code Problem (Visual Basic— Screen 6)‏

55 Enrichment SELECT CASE and END SELECT are used in stead of the pseudocode keywords CASENTRY and ENDCASE. ELSE replaces the word other.

56 Op Code Problem (Visual Basic-- btnComute_Click)‏

57 Enrichment Another solution to this same problem.

58 Op Code Problem (Visual Basic— Screen 7)‏

59 Op Code Problem (Visual Basic— Screen 8)‏

60 Op Code Problem (Visual Basic— Screen 9)‏

61 Op Code Problem (Visual Basic— radAdd_Click)‏

62 Op Code Problem (Visual Basic— radSubtract_Click)‏

63 Op Code Problem (Visual Basic— radMultiply_Click)‏

64 Op Code Problem (Visual Basic— radDivide_Click)‏


Download ppt "Chapter 7 CASE Control Structure © 2008 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved. Marilyn Bohl/Maria Rynn Tools for Structured."

Similar presentations


Ads by Google