/* Bucketfile.cpp * * This is the cpp file for the bucketfile. * */ #include "Bucketfile.h" // the header for the student class #include #include #include #include // for setw, setiosflags, etc... using namespace std; // First constructor // This sets up the elements of student. Bucketfile::Bucketfile() { // Initialize maxKeysize = 5; numKeys = 0; depthBucket = 0; keys0 = 0; keys1 = 0; keys2 = 0; keys3 = 0; keys4 = 0; recAddr0 = 0; recAddr1 = 0; recAddr2 = 0; recAddr3 = 0; recAddr4 = 0; numKeys_length=2; depthBucket_length=4; keys_length=8; recAddr_length=4; recsize = numKeys_length + depthBucket_length + (keys_length + recAddr_length)*maxKeysize + 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. Bucketfile::~Bucketfile() { } // Accessors for the Numkeys int Bucketfile::getNumKeys() const { return numKeys; } void Bucketfile::setNumKeys(int newnumKeys) { numKeys = newnumKeys; } // Accessors for the DepthBucket int Bucketfile::getDepthBucket() const { return depthBucket; } void Bucketfile::setDepthBucket(int newdepthBucket) { depthBucket = newdepthBucket; } // Accessors for the Keys0 long int Bucketfile::getKeys0() const { return keys0; } void Bucketfile::setKeys0(long int newkeys0) { keys0 = newkeys0; } // Accessors for the Keys1 long int Bucketfile::getKeys1() const { return keys1; } void Bucketfile::setKeys1(long int newkeys1) { keys1 = newkeys1; } // Accessors for the Keys2 long int Bucketfile::getKeys2() const { return keys2; } void Bucketfile::setKeys2(long int newkeys2) { keys2 = newkeys2; } // Accessors for the Keys long int Bucketfile::getKeys3() const { return keys3; } void Bucketfile::setKeys3(long int newkeys3) { keys3 = newkeys3; } // Accessors for the Keys long int Bucketfile::getKeys4() const { return keys4; } void Bucketfile::setKeys4(long int newkeys4) { keys4 = newkeys4; } // Accessors for the RecAddr0 int Bucketfile::getRecAddr0() const { return recAddr0; } void Bucketfile::setRecAddr0(int newrecAddr0) { recAddr0 = newrecAddr0; } // Accessors for the RecAddr1 int Bucketfile::getRecAddr1() const { return recAddr1; } void Bucketfile::setRecAddr1(int newrecAddr1) { recAddr1 = newrecAddr1; } // Accessors for the RecAddr2 int Bucketfile::getRecAddr2() const { return recAddr2; } void Bucketfile::setRecAddr2(int newrecAddr2) { recAddr2 = newrecAddr2; } // Accessors for the RecAddr3 int Bucketfile::getRecAddr3() const { return recAddr3; } void Bucketfile::setRecAddr3(int newrecAddr3) { recAddr3 = newrecAddr3; } // Accessors for the RecAddr4 int Bucketfile::getRecAddr4() const { return recAddr4; } void Bucketfile::setRecAddr4(int newrecAddr4) { recAddr4 = newrecAddr4; } // seek to the appropriate record for reading void Bucketfile::InputPositioningByRRN(int RRN, istream& input) { input.seekg(RRN * recsize, ios::beg); } // seek to the appropriate position for writing void Bucketfile::OutputPositioningByRRN(int RRN, ostream& output) { output.seekp(RRN * recsize, ios::beg); } // modify the name of a student stored in a file void Bucketfile::ModifyBucketFileNumKeys(int RRN, ostream& output, int NumKeys) { // seek to the appropriate student OutputPositioningByRRN(RRN,output); // seek to the name field output.seekp(0, ios::cur); // write the new name over the old one //output << setw(numKeys_length) << setiosflags(ios::left) << NumKeys << endl; output << setw(numKeys_length) << setiosflags(ios::left)<< NumKeys; } // modify the name of a student stored in a file void Bucketfile::ModifyBucketFileDepthBucket(int RRN, ostream& output, int DepthBucket) { // seek to the appropriate student OutputPositioningByRRN(RRN,output); // seek to the name field output.seekp(numKeys_length, ios::cur); // write the new name over the old one output << setw(depthBucket_length) << setiosflags(ios::left) << DepthBucket; } // modify the name of a student stored in a file void Bucketfile::ModifyBucketFileKey(int rrn, ostream& output,long key,int position) { // seek to the appropriate student OutputPositioningByRRN(rrn,output); // seek to the name field output.seekp(numKeys_length + depthBucket_length + (keys_length + recAddr_length)*position, ios::cur); // write the new name over the old one output << setw(keys_length) << setiosflags(ios::left) << key; } // modify the name of a student stored in a file void Bucketfile::ModifyBucketFileRecAddr(int RRN, ostream& output, int recAddr,int position) { // seek to the appropriate student OutputPositioningByRRN(RRN,output); // seek to the name field output.seekp(numKeys_length + depthBucket_length + keys_length + (keys_length + recAddr_length)*position, ios::cur); // write the new name over the old one output << setw(recAddr_length) << setiosflags(ios::left) << recAddr; } // modify the line to a void line void Bucketfile::ModifyBucketFileToVoid(int RRN, ostream& output) { // seek to the appropriate student OutputPositioningByRRN(RRN,output); // write the new name over the old one output <