SlideShare a Scribd company logo
1 of 43
Programming Logic and Design
Eighth Edition
Chapter 7
File Handling and Applications
Objectives
In this chapter, you will learn about:
• Computer files
• The data hierarchy
• Performing file operations
• Control break logic
• Merging files
• Master and transaction file processing
• Random access files
2Programming Logic and Design, Eighth Edition
Understanding Computer Files
• Computer file
– A collection of data stored on permanent storage devices
such as your computer’s hard drive, a hard drive on the
cloud, DVDs, USB drives, and reels of magnetic tape
– Text files (numbers, names, salaries) that can be read by a
text editor
– Binary files (images and music)
• File size measured in bytes
– Byte (one character), kilobyte (thousands of bytes),
megabyte (millions of bytes), gigabyte (billions of bytes),
terabyte (trillions of bytes)
3Programming Logic and Design, Eighth Edition
Understanding Computer Files (continued)
4Programming Logic and Design, Eighth Edition
Figure 7-1 Three stored files showing their names, dates of modification, type, and
sizes
Understanding Computer Files (continued)
• Organizing files
– Directories and folders
• Organization units on storage devices
– Path
• Combination of disk drive plus the complete hierarchy of
directories
• Example: C:LogicSampleFilesPayrollData.dat
5Programming Logic and Design, Eighth Edition
Understanding the Data Hierarchy
• Data hierarchy
– Describes the relationships between data components
– Consists of:
• Characters – Letters number and special symbols
• Fields – Data items representing a single attribute of a
record
• Records – Groups of fields that go together for some logical
reason
• Files – Groups of related records
6Programming Logic and Design, Eighth Edition
Performing File Operations
• Use data files in your programs
– Declaring a file identifier
InputFile employeeData
OutputFile updatedData
– Opening a file
open employeeData "EmployeeData.dat"
– Reading from a file and processing the data
input name from employeeData
input address from employeeData
input payRate from employeeData
7Programming Logic and Design, Eighth Edition
Performing File Operations (continued)
8Programming Logic and Design, Eighth Edition
Figure 7-2 How employee data in a readable comma-delimited file might appear in a text reader
Performing File Operations (continued)
9Programming Logic and Design, Eighth Edition
Figure 7-3 Reading three data items from a storage device into memory
Performing File Operations (continued)
– Sequential file
• Program reads all the records in this file from beginning to end,
processing them one t a time
– Sorting
• The process of placing records in order by the value in a specific
field or fields
– Writing data to a file
output name, address, payRate to employeeData
– Closing a file
• Always close every file you open
10Programming Logic and Design, Eighth Edition
11
Figure 7-4 Flowchart and pseudocode for a program that uses files (Continues)
Programming Logic and Design, Eighth Edition
A Program that
Performs File
Operations
12
Figure 7-4 Flowchart and pseudocode for a program that uses files (continued)
Programming Logic and Design, Eighth Edition
A Program that
Performs File
Operations (continued)
Backup file - a copy kept in
case values need to be
restored to their original
state
The backup copy is called a
parent file and the newly
revised copy is a child file
Understanding Control Break Logic
• A control break is a temporary detour in the logic of
a program
– A control break program uses a change in a value to
initiate special actions or processing
– A control break report groups similar data together
• Input records must be in sequential order
13Programming Logic and Design, Eighth Edition
Understanding Sequential Files and
Control Break Logic (continued)
14Programming Logic and Design, Eighth Edition
Figure 7-5 A control break report with totals after each state
Understanding Control Break Logic
(continued)
15Programming Logic and Design, Eighth Edition
• Examples of control break reports
– All employees listed in order by department number, with
a new page started for each department
– All books for sale in a bookstore listed in order by
category (such as reference or self-help), with a count
following each category of book
– All items sold in order by date of sale, with a different ink
color for each new month
Understanding Control Break Logic
(continued)
– Single-level control break
• A detour based on the value of a single variable
• Uses a control break field to hold the previous value
16Programming Logic and Design, Eighth Edition
17Programming Logic and Design, Eighth Edition
Figure 7-6 Mainline logic and
getReady() module for
the program that produces
clients by state report
Understanding
Control Break
Logic (continued)
18Programming Logic and Design, Eighth Edition
Figure 7-7 The produceReport() and controlBreak() modules for the program that
produces clients by state
Understanding
Control Break
Logic (continued)
19Programming Logic and Design, Eighth Edition
Figure 7-8 The finishUp()module for the program that produces clients by state report
Understanding Control Break Logic
(continued)
Merging Sequential Files
• Merging files
– Combining two or more files while maintaining the
sequential order
• Examples
– A file of current employees in ID number order, and a file
of newly hired employees also in ID number order
– A file of parts manufactured in the Northside factory in
part-number order, and a file of parts manufactured in the
Southside factory also in part-number order
20Programming Logic and Design, Eighth Edition
Merging Sequential Files (continued)
• Two conditions required for merging files
– Each file has the same record layout
– Sorted in the same order based on the same field
• Ascending order (lowest to highest values)
• Descending order (highest to lowest values)
21Programming Logic and Design, Eighth Edition
Merging Sequential Files (continued)
Figure 7-9 Sample data contained in
two customer files
22Programming Logic and Design, Eighth Edition
Figure 7-10 Merged customer
file
• Mainline logic similar to other file-processing
programs, except for handling two files
• With two input files, must determine when both files
are at eof
– Define a flag variable to indicate that both files have
reached eof
– Must define two input files
– Read one record from each input file
23Programming Logic and Design, Eighth Edition
Merging Sequential Files (continued)
24Programming Logic and Design, Eighth Edition
Figure 7-11 Mainline logic of a program that merges files
Merging
Sequential
Files (continued)
25Programming Logic and Design, Eighth Edition
Figure 7-12 The getReady()
method for a program that
merges files, and the
methods it calls (Continues)
Merging
Sequential
Files (continued)
26Programming Logic and Design, Eighth Edition
Merging
Sequential
Files (continued)
Figure 7-12 The getReady()
method for a program that
merges files, and the
methods it calls
27Programming Logic and Design, Eighth Edition Figure 7-13 Start of merging process
Merging Sequential Files (continued)
28Programming Logic and Design, Eighth Edition Figure 7-14 Continuation of merging process
Merging Sequential Files (continued)
29Programming Logic and Design, Eighth Edition
Figure 7-15 The mergeRecords()
and finishUp() modules for
the file-merging program
Merging
Sequential
Files (continued)
Master and Transaction File
Processing
• Some related files have a master-transaction
relationship
• Master file
– Holds complete and relatively permanent data
• Transaction file
– Contains temporary data to be used to update the master
file
• Update the master file
– Changes to values in its fields based on transactions
30Programming Logic and Design, Eighth Edition
Master and Transaction File
Processing (continued)
• Examples
– A library maintains a master file of all patrons and a
transaction file with information about each book or other
items checked out
– A college maintains a master file of all students and a
transaction file for each course registration
– A telephone company maintains a master file of every
telephone line (number) and a transaction file with
information about every call
31Programming Logic and Design, Eighth Edition
Master and Transaction File
Processing (continued)
• Updating approaches
– Change information in master file
– Copy master file and change new version
• Begin with both files sorted in the same order on the
same field
32Programming Logic and Design, Eighth Edition
Figure 7-16 Mainline logic for the master-transaction program
33Programming Logic and Design, Eighth Edition
Master and
Transaction
File
Processing
(continued)
Figure 7-17 The
housekeeping() module for
the master-transaction
program, and the modules
it calls (Continues)
34Programming Logic and Design, Eighth Edition
Master and
Transaction
File
Processing
(continued)
Figure 7-17 The housekeeping() module for the master-
transaction program, and the modules it calls
35Programming Logic and Design, Eighth Edition
Master and
Transaction
File
Processing
(continued)
Figure 7-18 The updateRecords()
module for the master-transaction
program
36Programming Logic and Design, Eighth Edition
Master and
Transaction
File
Processing
(continued)
Master and Transaction File
Processing (continued)
37Programming Logic and Design, Eighth Edition
Figure 7-19 Sample data for the file-matching program
Master and Transaction File
Processing (continued)
38Programming Logic and Design, Eighth Edition
Figure 7-20 The finishUp() module for the master-transaction program
Random Access Files
• Batch processing
– Involves performing the same tasks with many records,
one after the other
– Uses sequential files
• Real-time applications
– Require that a record be accessed immediately while a
client is waiting
• Interactive program
– A program in which the user makes direct requests
39Programming Logic and Design, Eighth Edition
Random Access Files (continued)
• Random access files
– Records can be located in any order
– Instant access files
• Locating a particular record directly
– Also known as direct access files
40Programming Logic and Design, Eighth Edition
Random Access Files (continued)
41Programming Logic and Design, Eighth Edition
Figure 7-21 Accessing a record in a sequential file and in a random access file
Summary
• Computer file
– A collection of data stored on a nonvolatile device in a
computer system
• Data items are stored in a hierarchy
• Using a data file
– Declare, open, read, write, close
• Sequential file: records stored in some order
• Merging files combines two or more files
– Maintains the same sequential order
42Programming Logic and Design, Eighth Edition
Summary
• Master files
– Hold permanent data
– Updated by transaction files
• Real-time applications
– Require random access files
– Records stored in any order
– Records accessed immediately
43Programming Logic and Design, Eighth Edition

More Related Content

Similar to CIS110 Computer Programming Design Chapter (7)

CIS110 Computer Programming Design Chapter (1)
CIS110 Computer Programming Design Chapter  (1)CIS110 Computer Programming Design Chapter  (1)
CIS110 Computer Programming Design Chapter (1)Dr. Ahmed Al Zaidy
 
chapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdfchapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdfBernardVelasco1
 
05 project setup v1.00_en
05 project setup v1.00_en05 project setup v1.00_en
05 project setup v1.00_enconfidencial
 
reverse engineering.ppt
reverse engineering.pptreverse engineering.ppt
reverse engineering.pptNaglaaFathy42
 
Address Binding Scheme
Address Binding SchemeAddress Binding Scheme
Address Binding SchemeRajesh Piryani
 
Pullareddy_tavva_resume.doc
Pullareddy_tavva_resume.docPullareddy_tavva_resume.doc
Pullareddy_tavva_resume.docT Pulla Reddy
 
CPIS351-chapter9.ppt contains about system analysis and design
CPIS351-chapter9.ppt contains about system analysis and designCPIS351-chapter9.ppt contains about system analysis and design
CPIS351-chapter9.ppt contains about system analysis and designNaglaaAbdelhady
 
R programming for data science
R programming for data scienceR programming for data science
R programming for data scienceSovello Hildebrand
 
How to use Parquet as a Sasis for ETL and Analytics
How to use Parquet as a Sasis for ETL and AnalyticsHow to use Parquet as a Sasis for ETL and Analytics
How to use Parquet as a Sasis for ETL and AnalyticsDataWorks Summit
 
PRESS MANAGEMENT Documentation
PRESS MANAGEMENT DocumentationPRESS MANAGEMENT Documentation
PRESS MANAGEMENT Documentationanuj_rakheja
 
Scaling Application on High Performance Computing Clusters and Analysis of th...
Scaling Application on High Performance Computing Clusters and Analysis of th...Scaling Application on High Performance Computing Clusters and Analysis of th...
Scaling Application on High Performance Computing Clusters and Analysis of th...Rusif Eyvazli
 

Similar to CIS110 Computer Programming Design Chapter (7) (20)

CIS110 Computer Programming Design Chapter (1)
CIS110 Computer Programming Design Chapter  (1)CIS110 Computer Programming Design Chapter  (1)
CIS110 Computer Programming Design Chapter (1)
 
Resume_Vellaiyan
Resume_VellaiyanResume_Vellaiyan
Resume_Vellaiyan
 
chapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdfchapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdf
 
SE.pdf
SE.pdfSE.pdf
SE.pdf
 
Chap-07-1.ppt
Chap-07-1.pptChap-07-1.ppt
Chap-07-1.ppt
 
05 project setup v1.00_en
05 project setup v1.00_en05 project setup v1.00_en
05 project setup v1.00_en
 
reverse engineering.ppt
reverse engineering.pptreverse engineering.ppt
reverse engineering.ppt
 
Cost effort.ppt
Cost effort.pptCost effort.ppt
Cost effort.ppt
 
Cs111 ch01 v4
Cs111 ch01 v4Cs111 ch01 v4
Cs111 ch01 v4
 
Address Binding Scheme
Address Binding SchemeAddress Binding Scheme
Address Binding Scheme
 
James hall ch 14
James hall ch 14James hall ch 14
James hall ch 14
 
Pullareddy_tavva_resume.doc
Pullareddy_tavva_resume.docPullareddy_tavva_resume.doc
Pullareddy_tavva_resume.doc
 
Computers in management
Computers in managementComputers in management
Computers in management
 
CPIS351-chapter9.ppt contains about system analysis and design
CPIS351-chapter9.ppt contains about system analysis and designCPIS351-chapter9.ppt contains about system analysis and design
CPIS351-chapter9.ppt contains about system analysis and design
 
NiW: Notebooks into Workflows
NiW: Notebooks into WorkflowsNiW: Notebooks into Workflows
NiW: Notebooks into Workflows
 
R programming for data science
R programming for data scienceR programming for data science
R programming for data science
 
How to use Parquet as a Sasis for ETL and Analytics
How to use Parquet as a Sasis for ETL and AnalyticsHow to use Parquet as a Sasis for ETL and Analytics
How to use Parquet as a Sasis for ETL and Analytics
 
Architecture presentation 4
Architecture presentation 4Architecture presentation 4
Architecture presentation 4
 
PRESS MANAGEMENT Documentation
PRESS MANAGEMENT DocumentationPRESS MANAGEMENT Documentation
PRESS MANAGEMENT Documentation
 
Scaling Application on High Performance Computing Clusters and Analysis of th...
Scaling Application on High Performance Computing Clusters and Analysis of th...Scaling Application on High Performance Computing Clusters and Analysis of th...
Scaling Application on High Performance Computing Clusters and Analysis of th...
 

More from Dr. Ahmed Al Zaidy

Chapter 14 Exploring Object-based Programming
Chapter 14 Exploring Object-based ProgrammingChapter 14 Exploring Object-based Programming
Chapter 14 Exploring Object-based ProgrammingDr. Ahmed Al Zaidy
 
Chapter 13 Programming for web forms
Chapter 13 Programming for web formsChapter 13 Programming for web forms
Chapter 13 Programming for web formsDr. Ahmed Al Zaidy
 
Chapter 12 Working with Document nodes and style sheets
Chapter 12 Working with Document nodes and style sheetsChapter 12 Working with Document nodes and style sheets
Chapter 12 Working with Document nodes and style sheetsDr. Ahmed Al Zaidy
 
Chapter 11 Working with Events and Styles
Chapter 11 Working with Events and StylesChapter 11 Working with Events and Styles
Chapter 11 Working with Events and StylesDr. Ahmed Al Zaidy
 
Chapter 10 Exploring arrays, loops, and conditional statements
Chapter 10 Exploring arrays, loops, and conditional statementsChapter 10 Exploring arrays, loops, and conditional statements
Chapter 10 Exploring arrays, loops, and conditional statementsDr. Ahmed Al Zaidy
 
Chapter 9 Getting Started with JavaScript
Chapter 9 Getting Started with JavaScriptChapter 9 Getting Started with JavaScript
Chapter 9 Getting Started with JavaScriptDr. Ahmed Al Zaidy
 
Chapter 8 Enhancing a website with multimedia
Chapter 8 Enhancing a website with multimediaChapter 8 Enhancing a website with multimedia
Chapter 8 Enhancing a website with multimediaDr. Ahmed Al Zaidy
 
Chapter 7 Designing a web form
Chapter 7 Designing a web formChapter 7 Designing a web form
Chapter 7 Designing a web formDr. Ahmed Al Zaidy
 
Chapter 6 Working with Tables and Columns
Chapter 6 Working with Tables and ColumnsChapter 6 Working with Tables and Columns
Chapter 6 Working with Tables and ColumnsDr. Ahmed Al Zaidy
 
Chapter 5 Designing for the mobile web
Chapter 5 Designing for the mobile webChapter 5 Designing for the mobile web
Chapter 5 Designing for the mobile webDr. Ahmed Al Zaidy
 
Chapter 4 Graphic Design with CSS
Chapter 4 Graphic Design with CSSChapter 4 Graphic Design with CSS
Chapter 4 Graphic Design with CSSDr. Ahmed Al Zaidy
 
Chapter 3 Designing a Page Layout
Chapter 3 Designing a Page LayoutChapter 3 Designing a Page Layout
Chapter 3 Designing a Page LayoutDr. Ahmed Al Zaidy
 
Chapter 2 Getting Started with CSS
Chapter 2 Getting Started with CSSChapter 2 Getting Started with CSS
Chapter 2 Getting Started with CSSDr. Ahmed Al Zaidy
 
Chapter 1 Getting Started with HTML5
Chapter 1 Getting Started with HTML5Chapter 1 Getting Started with HTML5
Chapter 1 Getting Started with HTML5Dr. Ahmed Al Zaidy
 
testing throughout-the-software-life-cycle-section-2
testing throughout-the-software-life-cycle-section-2testing throughout-the-software-life-cycle-section-2
testing throughout-the-software-life-cycle-section-2Dr. Ahmed Al Zaidy
 
Chapter 14 Business Continuity
Chapter 14 Business ContinuityChapter 14 Business Continuity
Chapter 14 Business ContinuityDr. Ahmed Al Zaidy
 
Chapter 13 Vulnerability Assessment and Data Security
Chapter 13 Vulnerability Assessment and Data SecurityChapter 13 Vulnerability Assessment and Data Security
Chapter 13 Vulnerability Assessment and Data SecurityDr. Ahmed Al Zaidy
 

More from Dr. Ahmed Al Zaidy (20)

Chapter 14 Exploring Object-based Programming
Chapter 14 Exploring Object-based ProgrammingChapter 14 Exploring Object-based Programming
Chapter 14 Exploring Object-based Programming
 
Chapter 13 Programming for web forms
Chapter 13 Programming for web formsChapter 13 Programming for web forms
Chapter 13 Programming for web forms
 
Chapter 12 Working with Document nodes and style sheets
Chapter 12 Working with Document nodes and style sheetsChapter 12 Working with Document nodes and style sheets
Chapter 12 Working with Document nodes and style sheets
 
Chapter 11 Working with Events and Styles
Chapter 11 Working with Events and StylesChapter 11 Working with Events and Styles
Chapter 11 Working with Events and Styles
 
Chapter 10 Exploring arrays, loops, and conditional statements
Chapter 10 Exploring arrays, loops, and conditional statementsChapter 10 Exploring arrays, loops, and conditional statements
Chapter 10 Exploring arrays, loops, and conditional statements
 
Chapter 9 Getting Started with JavaScript
Chapter 9 Getting Started with JavaScriptChapter 9 Getting Started with JavaScript
Chapter 9 Getting Started with JavaScript
 
Chapter 8 Enhancing a website with multimedia
Chapter 8 Enhancing a website with multimediaChapter 8 Enhancing a website with multimedia
Chapter 8 Enhancing a website with multimedia
 
Chapter 7 Designing a web form
Chapter 7 Designing a web formChapter 7 Designing a web form
Chapter 7 Designing a web form
 
Chapter 6 Working with Tables and Columns
Chapter 6 Working with Tables and ColumnsChapter 6 Working with Tables and Columns
Chapter 6 Working with Tables and Columns
 
Chapter 5 Designing for the mobile web
Chapter 5 Designing for the mobile webChapter 5 Designing for the mobile web
Chapter 5 Designing for the mobile web
 
Chapter 4 Graphic Design with CSS
Chapter 4 Graphic Design with CSSChapter 4 Graphic Design with CSS
Chapter 4 Graphic Design with CSS
 
Chapter 3 Designing a Page Layout
Chapter 3 Designing a Page LayoutChapter 3 Designing a Page Layout
Chapter 3 Designing a Page Layout
 
Chapter 2 Getting Started with CSS
Chapter 2 Getting Started with CSSChapter 2 Getting Started with CSS
Chapter 2 Getting Started with CSS
 
Chapter 1 Getting Started with HTML5
Chapter 1 Getting Started with HTML5Chapter 1 Getting Started with HTML5
Chapter 1 Getting Started with HTML5
 
Integer overflows
Integer overflowsInteger overflows
Integer overflows
 
testing throughout-the-software-life-cycle-section-2
testing throughout-the-software-life-cycle-section-2testing throughout-the-software-life-cycle-section-2
testing throughout-the-software-life-cycle-section-2
 
Fundamental of testing
Fundamental of testingFundamental of testing
Fundamental of testing
 
Chapter 15 Risk Mitigation
Chapter 15 Risk MitigationChapter 15 Risk Mitigation
Chapter 15 Risk Mitigation
 
Chapter 14 Business Continuity
Chapter 14 Business ContinuityChapter 14 Business Continuity
Chapter 14 Business Continuity
 
Chapter 13 Vulnerability Assessment and Data Security
Chapter 13 Vulnerability Assessment and Data SecurityChapter 13 Vulnerability Assessment and Data Security
Chapter 13 Vulnerability Assessment and Data Security
 

Recently uploaded

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 

Recently uploaded (20)

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 

CIS110 Computer Programming Design Chapter (7)

  • 1. Programming Logic and Design Eighth Edition Chapter 7 File Handling and Applications
  • 2. Objectives In this chapter, you will learn about: • Computer files • The data hierarchy • Performing file operations • Control break logic • Merging files • Master and transaction file processing • Random access files 2Programming Logic and Design, Eighth Edition
  • 3. Understanding Computer Files • Computer file – A collection of data stored on permanent storage devices such as your computer’s hard drive, a hard drive on the cloud, DVDs, USB drives, and reels of magnetic tape – Text files (numbers, names, salaries) that can be read by a text editor – Binary files (images and music) • File size measured in bytes – Byte (one character), kilobyte (thousands of bytes), megabyte (millions of bytes), gigabyte (billions of bytes), terabyte (trillions of bytes) 3Programming Logic and Design, Eighth Edition
  • 4. Understanding Computer Files (continued) 4Programming Logic and Design, Eighth Edition Figure 7-1 Three stored files showing their names, dates of modification, type, and sizes
  • 5. Understanding Computer Files (continued) • Organizing files – Directories and folders • Organization units on storage devices – Path • Combination of disk drive plus the complete hierarchy of directories • Example: C:LogicSampleFilesPayrollData.dat 5Programming Logic and Design, Eighth Edition
  • 6. Understanding the Data Hierarchy • Data hierarchy – Describes the relationships between data components – Consists of: • Characters – Letters number and special symbols • Fields – Data items representing a single attribute of a record • Records – Groups of fields that go together for some logical reason • Files – Groups of related records 6Programming Logic and Design, Eighth Edition
  • 7. Performing File Operations • Use data files in your programs – Declaring a file identifier InputFile employeeData OutputFile updatedData – Opening a file open employeeData "EmployeeData.dat" – Reading from a file and processing the data input name from employeeData input address from employeeData input payRate from employeeData 7Programming Logic and Design, Eighth Edition
  • 8. Performing File Operations (continued) 8Programming Logic and Design, Eighth Edition Figure 7-2 How employee data in a readable comma-delimited file might appear in a text reader
  • 9. Performing File Operations (continued) 9Programming Logic and Design, Eighth Edition Figure 7-3 Reading three data items from a storage device into memory
  • 10. Performing File Operations (continued) – Sequential file • Program reads all the records in this file from beginning to end, processing them one t a time – Sorting • The process of placing records in order by the value in a specific field or fields – Writing data to a file output name, address, payRate to employeeData – Closing a file • Always close every file you open 10Programming Logic and Design, Eighth Edition
  • 11. 11 Figure 7-4 Flowchart and pseudocode for a program that uses files (Continues) Programming Logic and Design, Eighth Edition A Program that Performs File Operations
  • 12. 12 Figure 7-4 Flowchart and pseudocode for a program that uses files (continued) Programming Logic and Design, Eighth Edition A Program that Performs File Operations (continued) Backup file - a copy kept in case values need to be restored to their original state The backup copy is called a parent file and the newly revised copy is a child file
  • 13. Understanding Control Break Logic • A control break is a temporary detour in the logic of a program – A control break program uses a change in a value to initiate special actions or processing – A control break report groups similar data together • Input records must be in sequential order 13Programming Logic and Design, Eighth Edition
  • 14. Understanding Sequential Files and Control Break Logic (continued) 14Programming Logic and Design, Eighth Edition Figure 7-5 A control break report with totals after each state
  • 15. Understanding Control Break Logic (continued) 15Programming Logic and Design, Eighth Edition • Examples of control break reports – All employees listed in order by department number, with a new page started for each department – All books for sale in a bookstore listed in order by category (such as reference or self-help), with a count following each category of book – All items sold in order by date of sale, with a different ink color for each new month
  • 16. Understanding Control Break Logic (continued) – Single-level control break • A detour based on the value of a single variable • Uses a control break field to hold the previous value 16Programming Logic and Design, Eighth Edition
  • 17. 17Programming Logic and Design, Eighth Edition Figure 7-6 Mainline logic and getReady() module for the program that produces clients by state report Understanding Control Break Logic (continued)
  • 18. 18Programming Logic and Design, Eighth Edition Figure 7-7 The produceReport() and controlBreak() modules for the program that produces clients by state Understanding Control Break Logic (continued)
  • 19. 19Programming Logic and Design, Eighth Edition Figure 7-8 The finishUp()module for the program that produces clients by state report Understanding Control Break Logic (continued)
  • 20. Merging Sequential Files • Merging files – Combining two or more files while maintaining the sequential order • Examples – A file of current employees in ID number order, and a file of newly hired employees also in ID number order – A file of parts manufactured in the Northside factory in part-number order, and a file of parts manufactured in the Southside factory also in part-number order 20Programming Logic and Design, Eighth Edition
  • 21. Merging Sequential Files (continued) • Two conditions required for merging files – Each file has the same record layout – Sorted in the same order based on the same field • Ascending order (lowest to highest values) • Descending order (highest to lowest values) 21Programming Logic and Design, Eighth Edition
  • 22. Merging Sequential Files (continued) Figure 7-9 Sample data contained in two customer files 22Programming Logic and Design, Eighth Edition Figure 7-10 Merged customer file
  • 23. • Mainline logic similar to other file-processing programs, except for handling two files • With two input files, must determine when both files are at eof – Define a flag variable to indicate that both files have reached eof – Must define two input files – Read one record from each input file 23Programming Logic and Design, Eighth Edition Merging Sequential Files (continued)
  • 24. 24Programming Logic and Design, Eighth Edition Figure 7-11 Mainline logic of a program that merges files Merging Sequential Files (continued)
  • 25. 25Programming Logic and Design, Eighth Edition Figure 7-12 The getReady() method for a program that merges files, and the methods it calls (Continues) Merging Sequential Files (continued)
  • 26. 26Programming Logic and Design, Eighth Edition Merging Sequential Files (continued) Figure 7-12 The getReady() method for a program that merges files, and the methods it calls
  • 27. 27Programming Logic and Design, Eighth Edition Figure 7-13 Start of merging process Merging Sequential Files (continued)
  • 28. 28Programming Logic and Design, Eighth Edition Figure 7-14 Continuation of merging process Merging Sequential Files (continued)
  • 29. 29Programming Logic and Design, Eighth Edition Figure 7-15 The mergeRecords() and finishUp() modules for the file-merging program Merging Sequential Files (continued)
  • 30. Master and Transaction File Processing • Some related files have a master-transaction relationship • Master file – Holds complete and relatively permanent data • Transaction file – Contains temporary data to be used to update the master file • Update the master file – Changes to values in its fields based on transactions 30Programming Logic and Design, Eighth Edition
  • 31. Master and Transaction File Processing (continued) • Examples – A library maintains a master file of all patrons and a transaction file with information about each book or other items checked out – A college maintains a master file of all students and a transaction file for each course registration – A telephone company maintains a master file of every telephone line (number) and a transaction file with information about every call 31Programming Logic and Design, Eighth Edition
  • 32. Master and Transaction File Processing (continued) • Updating approaches – Change information in master file – Copy master file and change new version • Begin with both files sorted in the same order on the same field 32Programming Logic and Design, Eighth Edition
  • 33. Figure 7-16 Mainline logic for the master-transaction program 33Programming Logic and Design, Eighth Edition Master and Transaction File Processing (continued)
  • 34. Figure 7-17 The housekeeping() module for the master-transaction program, and the modules it calls (Continues) 34Programming Logic and Design, Eighth Edition Master and Transaction File Processing (continued)
  • 35. Figure 7-17 The housekeeping() module for the master- transaction program, and the modules it calls 35Programming Logic and Design, Eighth Edition Master and Transaction File Processing (continued)
  • 36. Figure 7-18 The updateRecords() module for the master-transaction program 36Programming Logic and Design, Eighth Edition Master and Transaction File Processing (continued)
  • 37. Master and Transaction File Processing (continued) 37Programming Logic and Design, Eighth Edition Figure 7-19 Sample data for the file-matching program
  • 38. Master and Transaction File Processing (continued) 38Programming Logic and Design, Eighth Edition Figure 7-20 The finishUp() module for the master-transaction program
  • 39. Random Access Files • Batch processing – Involves performing the same tasks with many records, one after the other – Uses sequential files • Real-time applications – Require that a record be accessed immediately while a client is waiting • Interactive program – A program in which the user makes direct requests 39Programming Logic and Design, Eighth Edition
  • 40. Random Access Files (continued) • Random access files – Records can be located in any order – Instant access files • Locating a particular record directly – Also known as direct access files 40Programming Logic and Design, Eighth Edition
  • 41. Random Access Files (continued) 41Programming Logic and Design, Eighth Edition Figure 7-21 Accessing a record in a sequential file and in a random access file
  • 42. Summary • Computer file – A collection of data stored on a nonvolatile device in a computer system • Data items are stored in a hierarchy • Using a data file – Declare, open, read, write, close • Sequential file: records stored in some order • Merging files combines two or more files – Maintains the same sequential order 42Programming Logic and Design, Eighth Edition
  • 43. Summary • Master files – Hold permanent data – Updated by transaction files • Real-time applications – Require random access files – Records stored in any order – Records accessed immediately 43Programming Logic and Design, Eighth Edition