Laboratory 10: Handling Records by RRN
In this lab, you will learn
how to manipulate records in a file with fixed-length records.
You will learn how to jump
to a certain record (using its RRN) in order to read it or modify it.
Remember that "RRN" is the
"relative record number".
The first record has RRN=0,
the second has RRN=1, and so on.
-
Topics to be explained by your TA.
SOLUTION
YOUR TASK
-
Download the following files:
-
Create an empty project (lab10) and add the downloaded files.
Problem 1: Read the records of a file and write
them into another file in reverse order (last file first)
-
Include the code for the function InputPositioningByRRN(int RRN, istream&
input):
-
Your code should position the reading pointer in the right record according
to the RRN
-
Compile and run the project
-
Look at the modified/newly created output file
Problem 2: Change the name of student in a specified record
to a given name
-
Include the code for the function OutputPositioningByRRN(int RRN, ostream&
output):
-
Your code should position the writing pointer in the right record according
to the RRN
-
Include the code for the function ModifyStudentName(int rrn, ostream&
output, string newname). Your code should:
-
Use the function OutputPositioningByRRN(int RRN, ostream& output) to
seek to the appropriate student
-
Seek to the name field
-
Write the new name over the old one
-
Be careful. You have to write a 21-char string and a new line symbol
('\n' or endl);
-
In order to test your code include a function call in main() to change
the name of the student 5 (with RRN=4) in the newly created output file
to "New John Paul"
-
Compile and run the project
-
Look at the modified output file