Programming Logic and Design Fourth Edition Comprehensive Chapter

  • Slides: 44
Download presentation
Programming Logic and Design Fourth Edition, Comprehensive Chapter 7 Control Breaks Programming Logic and

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

Objectives • Understand control break logic • Perform single-level control breaks • Use control

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 Programming Logic and Design, Introductory, Fourth Edition 2

Objectives (continued) • Perform multiple-level control breaks • Perform page breaks Programming Logic and

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

Understanding Control Break Logic • Control break: temporary detour in program logic • Control

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 Programming Logic and Design, Introductory, Fourth Edition 4

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

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

Understanding Control Break Logic (continued) • Input records must be organized in sequential order

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 Programming Logic and Design, Introductory, Fourth Edition 6

Performing a Single-Level Control Break to Start a New Page • Developing the application:

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

Performing a Single-Level Control Break to Start a New Page (continued) Programming Logic and

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

Performing a Single-Level Control Break to Start a New Page (continued) • Developing the

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 Programming Logic and Design, Introductory, Fourth Edition 9

Performing a Single-Level Control Break to Start a New Page (continued) Programming Logic and

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

Performing a Single-Level Control Break to Start a New Page (continued) Programming Logic and

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

Performing a Single-Level Control Break to Start a New Page (continued) Programming Logic and

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

Performing a Single-Level Control Break to Start a New Page (continued) • If record’s

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

Performing a Single-Level Control Break to Start a New Page (continued) • Developing the

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

Performing a Single-Level Control Break to Start a New Page (continued) Programming Logic and

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

Using Control Data Within A Heading In a Control Break Module • Control data

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

Using Control Data Within A Heading In a Control Break Module (continued) Programming Logic

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

Using Control Data Within A Footer In a Control Break Module • Footer: message

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 Programming Logic and Design, Introductory, Fourth Edition 18

Using Control Data Within A Footer In a Control Break Module (continued) • When

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 Programming Logic and Design, Introductory, Fourth Edition 19

Using Control Data Within A Footer In a Control Break Module (continued) Programming Logic

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

Performing Control Breaks with Totals • Developing the application: – The input file Programming

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

Performing Control Breaks with Totals (continued) • Developing the application: – The desired output

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

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

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

Performing Control Breaks with Totals (continued) • Desired output: sort and total by category

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

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

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

Performing Control Breaks with Totals (continued) • Processing each record: – If category matches,

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 Programming Logic and Design, Introductory, Fourth Edition 26

Performing Control Breaks with Totals (continued) • For last record: – Print total for

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

Performing Multiple-Level Control Breaks • Summary report: group totals, not detail records • Multiple-level

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 Programming Logic and Design, Introductory, Fourth Edition 28

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

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

Performing Multiple-Level Control Breaks (continued) • Need two control break modules (city and state)

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 Programming Logic and Design, Introductory, Fourth Edition 30

Performing Multiple-Level Control Breaks (continued) • State break processing: – – – Process the

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 Programming Logic and Design, Introductory, Fourth Edition 31

Performing Multiple-Level Control Breaks (continued) • Must check for state break before city break

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 Programming Logic and Design, Introductory, Fourth Edition 32

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

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

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

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

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

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

Performing Multiple-Level Control Breaks (continued) • Within each break module, check if you need

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 Programming Logic and Design, Introductory, Fourth Edition 36

Performing Page Breaks • Control break logic can be used to start a new

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 Programming Logic and Design, Introductory, Fourth Edition 37

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

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

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

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

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

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

Performing Page Breaks (continued) • start. New. Page() module: – Does not perform a

Performing Page Breaks (continued) • start. New. Page() 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) Programming Logic and Design, Introductory, Fourth Edition 41

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

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

Summary • Control break: a change in a variable’s value causes special actions to

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 Programming Logic and Design, Introductory, Fourth Edition 43

Summary (continued) • For multiple-level control breaks, test for a majorlevel break before a

Summary (continued) • For multiple-level control breaks, test for a majorlevel 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 Programming Logic and Design, Introductory, Fourth Edition 44