Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Logic and Design Fourth Edition, Introductory Chapter 7 Control Breaks.

Similar presentations


Presentation on theme: "Programming Logic and Design Fourth Edition, Introductory Chapter 7 Control Breaks."— Presentation transcript:

1 Programming Logic and Design Fourth Edition, Introductory Chapter 7 Control Breaks

2 Programming Logic and Design, Introductory, Fourth Edition2 Objectives Understand control break logic Perform single-level control breaks Use control data within a heading in a control break module Use control data within a footer in a control break module Perform control breaks with totals

3 Programming Logic and Design, Introductory, Fourth Edition3 Objectives (continued) Perform multiple-level control breaks Perform page breaks

4 Programming Logic and Design, Introductory, Fourth Edition4 Understanding Control Break Logic Control break: temporary detour in program logic Control break program: –Program in which a change in a variable’s value causes special or unusual processing to occur –Helps organize output from processing data records –When a grouping variable is changed, special actions such as subtotals and new subheadings may occur Control break report: report with items in groups, including subtotals by group

5 Programming Logic and Design, Introductory, Fourth Edition5 Understanding Control Break Logic (continued)

6 Programming Logic and Design, Introductory, Fourth Edition6 Understanding Control Break Logic (continued) Input records must be organized in sequential order based on the grouping field Sorting: rearranging records in a particular order

7 Programming Logic and Design, Introductory, Fourth Edition7 Performing a Single-Level Control Break to Start a New Page Developing the application: –The input file

8 Programming Logic and Design, Introductory, Fourth Edition8 Performing a Single-Level Control Break to Start a New Page (continued)

9 Programming Logic and Design, Introductory, Fourth Edition9 Performing a Single-Level Control Break to Start a New Page (continued) Developing the application: –Program contains a single-level control break –Based on the department number variable Control break field: saves the information needed to determine when a break should occur

10 Programming Logic and Design, Introductory, Fourth Edition10 Performing a Single-Level Control Break to Start a New Page (continued)

11 Programming Logic and Design, Introductory, Fourth Edition11 Performing a Single-Level Control Break to Start a New Page (continued)

12 Programming Logic and Design, Introductory, Fourth Edition12 Performing a Single-Level Control Break to Start a New Page (continued)

13 Programming Logic and Design, Introductory, Fourth Edition13 If record’s value differs from control break field value –Print headings for a new page –Update the control break field Performing a Single-Level Control Break to Start a New Page (continued)

14 Programming Logic and Design, Introductory, Fourth Edition14 Performing a Single-Level Control Break to Start a New Page (continued) Developing the application: –The finish() module

15 Programming Logic and Design, Introductory, Fourth Edition15 Performing a Single-Level Control Break to Start a New Page (continued)

16 Programming Logic and Design, Introductory, Fourth Edition16 Using Control Data Within A Heading In a Control Break Module Control data can be used as part of page heading

17 Programming Logic and Design, Introductory, Fourth Edition17 Using Control Data Within A Heading In a Control Break Module (continued)

18 Programming Logic and Design, Introductory, Fourth Edition18 Using Control Data Within A Footer In a Control Break Module Footer: message printed at end of page or section Control data can be used as part of a page footer

19 Programming Logic and Design, Introductory, Fourth Edition19 Using Control Data Within A Footer In a Control Break Module (continued) When a control break occurs, the program must: –Print the footer for the previous group –Print the heading for the new group –Update the control break field For the very last group, the program must: –Print the footer for the last group –Not print another heading First heading and last footer must be handled separately from the others

20 Programming Logic and Design, Introductory, Fourth Edition20 Using Control Data Within A Footer In a Control Break Module (continued)

21 Programming Logic and Design, Introductory, Fourth Edition21 Performing Control Breaks with Totals Developing the application: –The input file

22 Programming Logic and Design, Introductory, Fourth Edition22 Performing Control Breaks with Totals (continued) Developing the application: –The desired output

23 Programming Logic and Design, Introductory, Fourth Edition23 Performing Control Breaks with Totals (continued)

24 Programming Logic and Design, Introductory, Fourth Edition24 Performing Control Breaks with Totals (continued) Desired output: sort and total by category –Two variables needed to manage grouping and totals

25 Programming Logic and Design, Introductory, Fourth Edition25 Performing Control Breaks with Totals (continued)

26 Programming Logic and Design, Introductory, Fourth Edition26 Performing Control Breaks with Totals (continued) Processing each record: –If category matches, increase category total by 1 –If category does not match: Print total for previous category Add category total to grand total Reset category counter to 0 Update control break field

27 Programming Logic and Design, Introductory, Fourth Edition27 Performing Control Breaks with Totals (continued) For last record: –Print total for previous category –Add category total to grand total –Print grand total

28 Programming Logic and Design, Introductory, Fourth Edition28 Performing Multiple-Level Control Breaks Summary report: group totals, not detail records Multiple-level control break: breaks occur for more than one change in condition

29 Programming Logic and Design, Introductory, Fourth Edition29 Performing Multiple-Level Control Breaks (continued)

30 Programming Logic and Design, Introductory, Fourth Edition30 Performing Multiple-Level Control Breaks (continued) Need two control break modules (city and state) City break processing: –Print totals for previous city –Add city count to state count –Reset city count to 0 –Update control break field for city

31 Programming Logic and Design, Introductory, Fourth Edition31 Performing Multiple-Level Control Breaks (continued) State break processing: –Process the city break module first –Print totals for previous state –Add state count to grand total –Reset state count to 0 –Update control break field for state

32 Programming Logic and Design, Introductory, Fourth Edition32 Performing Multiple-Level Control Breaks (continued) Must check for state break before city break –When city changes, state might also change –When state changes, city must also change –Could have the same city names in different states

33 Programming Logic and Design, Introductory, Fourth Edition33 Performing Multiple-Level Control Breaks (continued)

34 Programming Logic and Design, Introductory, Fourth Edition34 Performing Multiple-Level Control Breaks (continued)

35 Programming Logic and Design, Introductory, Fourth Edition35 Performing Multiple-Level Control Breaks (continued)

36 Programming Logic and Design, Introductory, Fourth Edition36 Performing Multiple-Level Control Breaks (continued) Within each break module, check if you need to: –Perform the lower-level break (if any) –Perform control break processing for previous group –Roll up the current-level totals to next higher level –Reset the current-level totals to 0 –Perform any control break processing for new group –Update the control break field

37 Programming Logic and Design, Introductory, Fourth Edition37 Performing Page Breaks Control break logic can be used to start a new page based on number of lines printed Must maintain a count of lines printed Break when line count reaches a predetermined value Line-counter: a variable used to count printed lines

38 Programming Logic and Design, Introductory, Fourth Edition38 Performing Page Breaks (continued)

39 Programming Logic and Design, Introductory, Fourth Edition39 Performing Page Breaks (continued)

40 Programming Logic and Design, Introductory, Fourth Edition40 Performing Page Breaks (continued)

41 Programming Logic and Design, Introductory, Fourth Edition41 Performing Page Breaks (continued) startNewPage() module: –Does not perform a lower-level break –Does not perform any control break processing for previous group –Does not roll up current-level totals –Does not reset current-level totals –Does perform control break processing for new group by printing page headings –Does update the control break field (line counter)

42 Programming Logic and Design, Introductory, Fourth Edition42 Performing Page Breaks (continued)

43 Programming Logic and Design, Introductory, Fourth Edition43 Summary Control break: a change in a variable’s value causes special actions to occur Control break field: holds data from a previous record to compare to the current record Control data can be used in a heading or footer Control break report contains and prints totals for each group, as well as grand totals

44 Programming Logic and Design, Introductory, Fourth Edition44 Summary (continued) For multiple-level control breaks, test for a major- level break before a minor-level break In a control break, check if lower-level breaks need to be processed Page breaks can be handled based on line counters


Download ppt "Programming Logic and Design Fourth Edition, Introductory Chapter 7 Control Breaks."

Similar presentations


Ads by Google