Handling Variable-Length Records and Formating Output
This lab is designed to help you learn
how to manipulate records in a file with variable-length records.
You will learn how to jump
to a certain record (using its RRN) in order to read it; the records
begin
with a length indicator which should be used
to skip through records
sequentially.
The first record has RRN=0,
the second has RRN=1, and so on. In addition, you will learn
how to use c++ formating methods to create a report. This lab is based
on an assignment created by Lucia Moura and Jeff Souza at the
University of Ottawa
To help understand the seek
commands, you can start with the following code as a basis for
experimentation:
#include <fstream>
using namespace std;
int main() {
fstream myfile;
myfile.open("test.txt",
ios::in|ios::out|ios::trunc);
myfile << "Welcome to
CS3050,\nFile Structures.";
myfile.seekp(11,ios::beg);
myfile
<<'M'<<'a'<<'t'<<'h';
myfile.seekp(4,ios::cur);
myfile <<'T';
myfile.seekp(-2,ios::end);
myfile <<'Z';
myfile.close();
return 0;
}
For
the part of the lab to be turned in:
- Download the following files:
Task: Read the records of the file and write
them
into another file by using the specified report format
- Include the code for the function readRecordbyRRN(int,
istream&):
- Your code should read the right record to a string according to
the RRN
- Include the code for the function writeRecord(string,
ostream&):
- Your code should write this record in the output file with the
report format
- Use Record Format and Report Format
specifications described
below in your implementation
- Compile and run the project
- Look at the newly created report file, it should look exactly as
in Report
Format
SPECIFICATIONS
Record Format
XXLAST-NAME|FIRST-NAME|MONTH|DAY|YEAR|
XX = record length
| = field
separator
Example:
26Smith|James|Dec|17|1973|
Report Format
LAST
NAME
FIRST NAME MONTH DAY
YEAR
<------- HEADER
------------
------------
----- --- ---- <-------
HEADER
McDonald
Bill Out
13
1978 <-------
RECORD
Spellman
Sabrina Feb 11
1970
.
Johnson
Ashley Dec 30
1974
.
Joe
Billy Nov
07
1966
.
Miller
Scott Jun
28
1972
William
John Dec
12
1973
Shelling
Anthony May 29 1969
Elk
Ann
Mar
06 1976
Dupont
Michel Feb 22 1970
Smith
James Dec
17
1973
<-------
RECORD
<---------->
<---------->
<---> <-> <-->
12
12
5 3 4 (lengths in output_lengths
array)