220 likes | 294 Views
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.
E N D
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. • 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 • 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 FILE LFN=Logical File Number, a reference number to be used in the solution. • Open LFN: It tells the computer that the data in the file called filename is to be used, starting at the first record. • Read LFN Record copies the next record into the internal memory or into a small holding memory called buffer memory. • Close LFN It tells the computer that the file will not be used anymore.
Flowchart Symbols Start or stop Process Input or output Decision Flow line Connector Off-page connector
Flowchart Symbols Process Module counter Automatic-counter loop A B S
SystemFlowcharts • 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. MONITOR KEYBOARD DISK DRIVE PROGRAM PRINTER
EXAMPLE OF A SYSTEMFLOWCHART MASTER FILE PROCESSPROGRAM NEW FILE REPORT
DESIGNING RECORDS RECORD DATA DICTIONARY FILENAME:MAILING LIST
Designing Records While 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 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 Init While Not EOF(1) F T Calc Print Read Wrap up End
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 1 Sales File Sales Total=0 Max Line Ct = 60 PageNo=1 Read Report Headings Exit
ALGORITHM AND FLOWCHART FOR READ MODULE Read 1.Read Record 2.Exit Read Read Record Exit
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 Write Report Headings Get Date Write Date LineCt=6 Column Headings Exit
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 Write Column 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
ALGORITHM AND FLOWCHART FOR PRINT MODULE Print If LineCt>= MaxLineCt PageBreak Print 1.IF LineCt>=MaxLineCt Then Process Page Break 2.Write Record Information 3.LineCt=LineCt+1 4.Exit T F Write RECORD Information LineCt= LineCt+1 Exit
ALGORITHM AND FLOWCHART FOR PAGEBREAK MODULE Page break • Page break • PageNo=PageNo+1 • Write Page Headings • LineCt=3 • Process Column headings • Exit Eject page PageNo= PageNo+1 Write Page Headings LineCt=3 Column Headings Exit
ALGORITHM AND FLOWCHART FOR WRAP-UPMODULE Wrap Up 1.Write Sales Total 2.Close 1 3.Print “Run Completed” 4.Exit Wrap up WRITE Sales Total Close 1 Print “Run Completed” 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.