/* Written by Jeff Souza at the University of Ottawa
*
*
* CS 3050 Lab 2
*
*
*
*/
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip> // for setw, setiosflags, etc...
using namespace std;
// the number of records to read in
const int num_records = 10;
// the number of fields in each record
const int num_fields = 5;
// the length of the record length indicator
const int length_ind_size = 2;
// output length for each field
const int output_lengths[] = {12,12,5,3,4};
// read a record by its RRN
string readRecordbyRRN(int, istream&);
// write a record using the report format
void writeRecord(string, ostream&);
// main method
int main( )
{
fstream input; // input stream
fstream output; // output stream
string rec;
char inputname[40]; // input filename
char outputname[40]; // output filename
cout << "What is the input file name? ";
cin >> inputname;
cout << "What is the output (report) file name? ";
cin >> outputname;
// open the input file for input, of course
input.open(inputname, ios::in);
// Check to make sure that we could open the files properly!
if (input.fail()) {
cerr << "Could not open file ";
cerr << inputname;
cerr << ".\n";
return 1;
}
// open the output for output
output.open(outputname, ios::out);
// outout the header of the report
output << "LAST NAME FIRST NAME MONTH DAY YEAR" << endl;
output << "------------ ------------ ----- --- ----" << endl;
// reads records in reverse order and copy the in output
for (int i=num_records;i>0; i--){
rec = readRecordbyRRN(i, input);
writeRecord(rec, output);
}
cout << endl << "Program completed successfully !!" << endl;
cout << "Check output file out." << endl << endl;
input.close();
output.close();
return 0;
}
// read a student from a istream by its RRN
string readRecordbyRRN(int rrn, istream& input)
{
// INCLUDE YOUR CODE HERE
return "";
}
// write a student in the ostream
void writeRecord(string r, ostream& output)
{
// INCLUDE YOUR CODE HERE
}