/* * CSI2131 Winter 2005 * * Assignment#2 Solution : The main function * * Shantanu Das * * This is the main program that inputs the filenames from command line, * opens the files and creates objects of the other classes. * * The following classes are used : Record, SimpIndex, DataFile, and Operations */ #include "Index.h" #include "DataFile.h" #include "IndexedDatafile.h" #include #include using namespace std; // main method ... uses command line arguments int main(int argc,char* argv[]) { fstream dfile; // datafile stream fstream opfile; // operations file stream // check for the correct number of arguments. if(argc!=3){ cerr << "USAGE: " << argv[0] << " " << endl; return 1; } // open the file for input dfile.open(argv[1], ios::in|ios::out|ios::binary|ios::app); // Check to make sure that we could open the file properly! if (dfile.fail()) { cerr << "Could not open file "; cerr << argv[1]; cerr << ".\n"; return 1; } // open the output file in binary mode opfile.open(argv[2], ios::in); // Check to make sure that we could open the file properly! if (opfile.fail()) { cerr << "Could not open file "; cerr << argv[2]; cerr << ".\n"; return 1; } int num = 0; DataFile df(dfile); IndexedDatafile indf(df); num = indf.createIndex(); cout << "Executing Operations from "<< argv[2] << endl; num = indf.executeOp(opfile); cout << num << " Operations executed successfully !" << endl; dfile.close(); // Close the files opfile.close(); // Program completed successfully! */ return 0; }