file concepts
DESCRIPTION
FILE CONCEPTS. The data used by the program cannot reside in main memory as it is volatile hence kept as files in the external memory. - PowerPoint PPT PresentationTRANSCRIPT
The data used by the program cannot reside in main memory as it is
volatile hence kept as files in the external memory.
A computer file is a block of arbitrary information, or resource for
storing information, which is available to a computer program and is
made up of Individual sets of data called records which in turn are
made up of indivisible units of data called fields
Ex: Student file -the data corresponding to a single student is a
record and the roll no., name, dob, mark are the fields.
Primary key: Field that uniquely identifies a record in file.
Secondary Key: The keys other than the primary key which has a
unique value for each record are called secondary keys.
FILE CONCEPTS
FILE CONCEPTS
• The data, information and programs are stored in external medium as FILES –program files and data files.
• BUFFER-Temporary memory while transfering files from external to internal storage.
THREE ALGORITHMIC INSTRUCTIONS TO MANIPULATE A FILELFN=Logical File Number, a reference number to be used in the solution.1. Open LFN: It tells the computer that the data in the file called filename
is to be used, starting at the first record.2. Read LFN Record copies the next record into the internal memory or
into a small holding memory called buffer memory.3. Close LFN It tells the computer that the file will not be used anymore.
Start or stop
Process
Input or output
Connector
Decision
Flow line
Off-page connector
Flowchart Symbols
Process Module
Automatic-counter loop
Flowchart Symbols
counter
A B
S
System Flowcharts
• A system flowchart indicates the flow of data throughout the entire system.
• It includes where the data are coming from keyboard, disk drive, etc., the name of the program to be processed, and where the information is to go disk drive, tape drive, printer,etc.
KEYBOARDMONITOR
PROGRAM DISK DRIVE
PRINTER
EXAMPLE OF A SYSTEMFLOWCHART
MASTERFILE
REPORT
PROCESSPROGRAM
NEWFILE
DESIGNING RECORDS
FILENAME:MAILING LIST
Field
Number
Item Description
Field Name
Field
Length
Data
type
# of Decimal
Comment
1 Last Name LNameln 15 C
2 FirstName FNameln 10 C
3 Street
address
StAddressln
20 C
4 City Cityln 20 C
5 State Stateln 2 C
6 Zipcode ZipCodeln 10 C
7 Telephone number
Telenoln 12 C
RECORD DATA DICTIONARY
RECORD LAYOUT
1 LNameIn 15 16 LNameIn 25 26 StAddressln 45
46
Cityln 65
66 Stateln 67
68 ZipCodeln 77
78 Telenoln
89
Designing RecordsWhile designing a records , there are many items to consider such as the number of items and their order, data types, and lengths, and the total record length
1.The number of fields is the number of items you listed under the Item Description.
2.The order of the fields is determined by the order of importance of the data.
3.The name of the fields should correspond to the item descriptions of the data.
4.The data type of each field is determined by the requirements of the solution
5.The length of the field is largely determined by the number of characters in the field.
6.Records are normally stored in external memory in blocks or section of a specific length.
Sequential Access File Applications
Processing Sequential-Access Files» EOF» Primer Read» Designing Output records» Headings and Line Counters
Algorithm And Flowchart Of Control Module For Sales Problem
Control Module
1.Process Init
2.While NOT EoF(1)
1.Process Calc
2.Process Print
3.Process Read
While End
3.Process Wrap-up
4.End
Control
Init
WhileNot EOF(1)
Calc
Read
Wrap up
End
F
T
ALGORITHM FOR INIT MODULE
Init
1.Open 1, Sales file
2.Sales Total = 0
3.MaxLineCt = 60
4.PageNo = 1
5.Process Read
6.Process Report Headings
7.Exit.
FLOWCHART FOR INIT MODULE
Init
Open 1Sales File
Read
PageNo=1
Report Headings
Max Line Ct= 60
Sales Total=0
Exit
Read
1.Read Record
2.Exit
Read
Exit
ReadRecord
ALGORITHM AND FLOWCHART FOR READ MODULE
Report Readings
1.Write Report Readings
2.Get Date from System
3.Write Date
4.Line Ct=6
5.Process Column Headings
6.Exit
ALGORITHM FOR REPORT HEADINGS MODULE
FLOWCHART FOR REPORT HEADINGS MODULE
Report Headings
LineCt=6
Column Headings
WriteDate
GetDate
Exit
WriteReport
Headings
ALGORITHM AND FLOWCHART FOR COLUMN HEADINGS MODULE
Column Headings
1.Write Column Headings
(including the space
before and after)
2.LineCt=LineCt+3
3.Exit.
Column Headings
WriteColumn
Headings
LineCt=LineCt+3
Exit
ALGORITHM AND FLOWCHART FOR CALC MODULE
CALC
1.SalesTotal=Sales Total +Sales
2.Exit
Calc
Sales Total=SalesTotal+Sales
EXit
1.IF LineCt>=MaxLineCt
Then
Process Page Break
2.Write Record
Information
3.LineCt=LineCt+1
4.Exit
If LineCt>=MaxLineCt
Write RECORD Information
LineCt=LineCt+1
Exit
PageBreakT
F
ALGORITHM AND FLOWCHART FOR PRINT
MODULE
ALGORITHM AND FLOWCHART FOR PAGEBREAK MODULE
Page break
Eject page
LineCt=3
Write Page Headings
PageNo=PageNo+1
Exit
Column Headings
1. Page break
2. PageNo=PageNo+1
3. Write Page Headings
4. LineCt=3
5. Process Column headings
6. Exit
ALGORITHM AND FLOWCHART FOR WRAP-UPMODULE
Wrap Up
1.Write Sales Total
2.Close 1
3.Print “Run Completed”
4.Exit
WRITE
Sales Total
Close 1
“Run
Completed”
Wrap up
Exit
Control Breaks
Control breaks are used to give subtotals for a group of similar records
Multiple Control Breaks
Multiple Control Breaks involve subtotals on more than
one field. Error Handling
For data validation, finding errors in the data records.
Null Files
Another problem that arises when you are working with files is to how to deal with the empty file or null file.