Laboratory work 3. Working with files using C

advertisement
Laboratory work 3. Working with files using C
1. Theoretical Part




To start work with files you are to use fopen() function indicating necessary mode of dealing
with file: “r” – reading, “w” – writing, “a” – appending etc.
For data transfer use fwrite(), fread(), fprintf(),fscanf() and other functions. First two provide
more fast access since they don’t transform information from binary to symbol representation.
After finishing to work with file you are to close it with fclose().
For more details look textbooks, for example, Kumar R., Agrawal R. Programming in ANSI C. –
St. Paul: West Publishing Company, 1992. – 452 p. ISBN 0-314-89563-9, Chapter 10.
2. Practical Part
You are to:
 Design necessary data structures for representation meta data about data bases. Assume that each
data base is kept in its own directory. Tables of such data base are represented by files with
correspondent names, for example, table “students” is stored in the file “students.dat” of the
respective directory. Meta information about attributes of data file is stored in the file with the
same name and “.frm” extension, for example, meta information for table “students” must be
kept in the same directory under the name “students.frm”. Assume that data files may contain
information of the following types:
- integer in 2 and 4 bytes;
- real in 4 and 8 bytes;
- character string in not more than 100 bytes
 Develop menu driven C program providing:
- creation of the new data base (new directory in the predefined directory, for example, in
c:\myDBMS\data);
- viewing of the names of existing data bases (directories);
- creation of the new table with storing meta data about it in the file with respective name
and “.frm” extension;
- viewing of the table’s meta information
- modifying of meta information for some data fields represented in “.frm” files;
- deleting of meta information for some data fields represented in “.frm” files (use
shifting).

Using developed program:
- create data base “cmpe”;
- create in this data base “cmpe” tables for keeping such information as: students names,
surnames, id-numbers, courses names, courses ids, instructors names, surnames,
semesters, total grade, letter grade. You are to keep this information not in the one table,
but have several connected tables.
3. Sample
Sample file containing C program for manipulations with files and databases – lab3.cpp
4. Grading
It is a fully graded lab
Download