This post was published long ago, when I was a student and an amateur blogger. The links might be broken and content may not be useful anymore. Please read this content keeping its age in mind.

FILE STRUCTURES LAB

Semester : 6

Subject Code : O6ISL67

Experiment No.  :  2


Objective   of the Experiment :
To make objects persistet by writing them to file . To maintain identity of fields and records , add delimiters to fields  and make  records  of fixed length.
Build two separate classes Student and FixedLengthBuffer (Record size =75). Write  overloaded insertion and extraction operators for reading and displaying  student data  . Implement  Pack() , UnPack() ,Read(), Write () methods for performing Buffer and file  opeartions.Use ‘ | ‘ as field Delimiter.
Class should have constructor to initialize buffer and student objects.

Procedure  in main :
1.    Create Student object and initialize
2.    Create buffer object and initialize
3.    Open file in write mode
4.    Read data for student
5.    Pack the student object into buffer
6.    Write the buffer to file
7.    Repeat step 4-6 for 15 students
8.    Close  the file.
9.    Open the file in read mode
10.    Read a record into buffer
11.    Unpack the fields and restore the state of an Object
12.    Display student record
13.    Repeat steps 10-12 for all the records stored in the file
14.    Close the file.


Buffer Contents                                               Record  USN  Name              Address            Semester
11 | student1 |Belgaum |1…………….        1                11         student1      Belgaum          1
12 |student2 |bangalore |2……………    2               12         student2     bangalore       2