COP 1002 - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

COP 1002

Description:

Total number of defective parts for each plant. Trailer Record: Plant Code = 9 ... Print Names/credit for more than 60 credits, otherwise do nothing (NULL ELSE) ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 24
Provided by: nova94
Category:
Tags: cop | names | plant

less

Transcript and Presenter's Notes

Title: COP 1002


1
COP 1002
  • Chapter 6
  • By Ali Fazelpour

2
Review of DOWHILE
  • Counter Controlled Loop
  • Header Record Logic
  • Similarity
  • Test at the beginning of Loop
  • Both based on counter
  • Steps to be repeated in the TRUE Path
  • Number of times to repeat is known in advance
  • Difference
  • First input record (the header record) specifies
    the no. of times to execute the loop

3
DOWHILE Issue
  • What if we do not know the number of times to be
    repeated in advance
  • E.g., No. of Customers to do shopping today
  • No. of defective parts to be received today
  • Lets modify the structure to accommodate the new
    situation

4
Trailer Record Logic (TRL)
  • Trailer Record Logic Trailer Record (Last Input
    Record) to control the loop
  • This record is a signal to the computer that no
    more data to process
  • Trailer record contains some data that differs
    from the rest of the input.

5
Trailer Record Logic (TRL)
  • This data will be used in the loop test to
    determine when all input has been processed.
  • What type of Information in the Trailer Record
    It depends on the Algorithm
  • It differs from algorithm to algorithm
  • E.g., Student File Name, SSN, and so on
  • SSN 000-00-000 is a good trailer data
  • Dummy data Trailer data

6
Problem 6.1 Defective Parts
  • Problem Description
  • A manufacture produces a large number of parts in
    two plants
  • Some parts are defective and will be returned to
    the headquarter
  • Input Plant code, Part , Part type and returned
    date
  • Plant Code is 1,2

7
Problem 6.1
  • A program that reads data and prints the
    following output
  • Total number of defective parts for each plant
  • Trailer Record Plant Code 9
  • Fig. 6.1 ( page 102)
  • Fig. 6.2 (Page 103)

8
Problem 6.1
  • Psuedocode Fig 6.3 (Page 104)
  • Heading Lines
  • Detail Lines
  • Total Lines
  • Priming Read and Loop Read

9
Problem 6.2 Defective Parts Using Modules
  • Problem description
  • The same as problem 6.1
  • Modular Approach
  • Structure Chart Fig. 6.4 (Page 107)
  • Flowchart Fig. 6.5 (Page 107) Main Module

10
Problem 6.2 Defective Parts Using Modules
  • Flowchart Pseudocode Fig. 6.7 (Page 108)
    Process Heading Module
  • Flowchart Pseudocode Fig. 6.8 (Page 108)
    Process Initialization Module
  • Flowchart Pseudocode Fig. 6.9 (Page 108)
    Process Totals Module
  • Flowchart Fig. 6.10 (Page 109) Process Detail
    Record Module
  • Pseudocode Fig. 6.11 (Page 109) Process Detail
    Record Module

11
Automatic End-of-File processing
  • Not necessary to have a trailer record
  • because most programming languages have a
    build-in function to recognize the end of file
  • Instead of checking for a trailer value, check
    for EOF
  • Flowchart Fig 6.12/ EOF Priming/Loop Read (Page
    110)
  • Pseudocode (Fig. 6.13 Page 111)
  • Tests are changed
  • Rather than testing for a specific value as
    trailer record, we replace it with EOF Test

12
Problem 6.3 Defective Parts with Multiple
headings
  • Output heading on every page of the report, not
    just the first page
  • Number each page
  • Use EOF Processing approach

13
Problem 6.3
  • SOLUTION
  • Output the headings at the top of every page
  • Counter (LINECNT) to keep track of the number of
    detail lines that printed on each page
  • LINECNT 0 each time a detail line printed
    increase the LINECNT by 1
  • LINECNT gt 55 Start new page and print the
    headings
  • PAGECNT to keep track of page number
  • PAGECNT 1, increment by 1 every time we have a
    new page

14
Problem 6.3
  • STRUCTURE CHART Fig. 6.14 (Page 112)
  • PROCESS HEADING module is not controlled by mail
    module any more
  • It is controlled by PROCESS A DETAIL RECORD
    Module
  • Because we need to check if we have enough room
    to print detail record in the current page,
    otherwise go to next page
  • Checking for LINECNT gt 55

15
Problem 6.3
  • Flowchart for Main Module Fig. 6.15 (Page 113)
  • No call to PROCESS HEADING MODULE, because it is
    not controlled by main module any more

16
Problem 6.3
  • Pseudocode for Main module (Fig. 6.16/Page 113)
  • Start/Stop
  • Priming READ/Loop Read

17
Problem 6.3
  • Flowchart Pseudocode Fig. 6.17 (Page 114)
    Process Initialization Module
  • Flowchart Pseudocode Fig. 6.18 (Page 114)
    Process Totals Module
  • Flowchart Fig. 6.19 (Page 115) Process Detail
    Module
  • Pseudocode Fig. 6.20 (Page 115) Process Detail
    Module
  • Flowchart Pseudocode Fig. 6.21 (Page 116)
    Process Heading Module

18
Multiple Headings Summary
  • Two additional counters
  • Initialization/Increment-Decrement/Testing
  • LINECNT of lines being printed on each page
  • PAGECNT of pages being printed

19
Multiple Heading Summary
  • Flowchart Fig. 6.22 (Page 117) Multiple
    Heading Summary
  • B000 Process Initialization Module
  • MAXLINES 55 Named Constant Its value does
    NOT change during program execution
  • Refer to MAXLINES instead of a constant such as
    55
  • Advantage of Named Constant Flexibility
  • B010 process a detail Record Module
  • Refer to MAXLINES instead of 55
  • C000 Process Heading Module

20
Problem 6.4
  • Problem description
  • Input Names, Address, Credits
  • Print Names/credit for more than 60 credits,
    otherwise do nothing (NULL ELSE)
  • Trailer Record Negative credit
  • Headings on each page and page number

21
Problem 6.4
  • Structure Chart
  • Fig 6.23 (Page 118)
  • Flowchart Fig 6.24 (Page 119) - Main Module
  • Pseudocode Fig 6.25 (Page 119) Main Module

22
Problem 6.4
  • Flowchart Fig 6.26 (Page 120) Detail Record
    Module
  • Pseudocode Fig 6.27 (Page 121) Detail Record
    Module
  • Flowchart Pseudocode Fig 6.28 (Page 121)
    Process Initialization Module
  • Flowchart Pseudocode Fig 6.29 (Page 121)
    Process Heading Module

23
DOWHILE Summary
Write a Comment
User Comments (0)
About PowerShow.com