/* Directoryfile.cpp * * This is the cpp file for the Directoryfile. * */ #include "Directoryfile.h" // the header for the class #include #include #include #include // for setw, setiosflags, etc... using namespace std; // First constructor // This sets up the elements Directoryfile::Directoryfile() { // Initialize key = 0; key_length=4; recsize = key_length + 2; } // The destructor for the Bucketfile class. // We didn't allocate any memory using the "new" keyword, so we // don't have anything to do here. Directoryfile::~Directoryfile() { } // Accessors for int Directoryfile::getKey() const { return key; } void Directoryfile::setKey(int newKey) { key = newKey; } // seek to the appropriate record for reading void Directoryfile::InputPositioningByRRN(int RRN, istream& input) { input.seekg(RRN * recsize, ios::beg); } // seek to the appropriate position for writing void Directoryfile::OutputPositioningByRRN(int RRN, ostream& output) { output.seekp(RRN * recsize, ios::beg); } //read a student from a istream void Directoryfile::readDirectoryfile(int rrn, istream& input) { //Directoryfile& buck; string key_str; string directory_line; // seek to the appropriate student InputPositioningByRRN(rrn, input); // read in a line from fine getline(input,directory_line,'\n'); // get the number and last name and first name and credits and CGPA strings key_str = directory_line.substr(0,key_length); // convert the numKeys and depthBucket string into int. key = atoi((key_str.c_str())); // set number and lastname and firstname and credits and CGPA for student s setKey(key); }