// main.cpp
// CSI 2131 Lab 7 by Naim R. El-Far (naim@discover.uottawa.ca)

#include <iostream>
#include <fstream>
#include <string>
#include "StudentRecord.h"
#include "DataFile.h"
using namespace std;

int main() {
	//Print welcome message
	//---------------------
	cout << "Lab 7. 28/Feb/2006." << endl
		 << "-------------------" << endl
		 << endl;

	//Prompt user for data file name
	//------------------------------
	cout << "Please enter data file name (default: studentfile.txt): ";
	string dataFileName = "";
	getline(cin, dataFileName, '\n');
	if (dataFileName == "")
		dataFileName = "studentfile.txt";

	//Instantiate data file class with data file name
	//-----------------------------------------------
	DataFile studentDataFile(dataFileName);

	//Program loop: Retrieve records by RRN
	//-------------------------------------
	long int userInput = 0;
	while (true) {
		cout << "Please enter byte offset. Enter -1 to quit: ";
		cin >> userInput;

		if (userInput == -1) {
			cout << endl;
			break;
		}
		else {
			cout << endl
				 << "Retrieving record at offset " << userInput << "..." << endl;
			
			StudentRecord*	ptrToRetrievedRecord = new StudentRecord(studentDataFile.GetRecordByByteOffset(userInput));			
			ptrToRetrievedRecord->PrintRaw();
		}
	}

	//Successful termination
	//----------------------
	return 0;
}
