//////////////////////////////////////////////////////////////////////////////// // Proj1_aux.C // // CMSC 341 Fall 2001 - Project 1 // // Kyu Bae 212-04-5868 Section 201 // // kyu_bae@yahoo.com / kbae1@umbc.edu // // created: 1 September 2001 // // current: 17 September 2001 // //////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// // Proj1_aux file contains three functions to help main driver. Here is where // files are read and called into proper functions to load into the vector // container. /////////////////////////////////////////////////////////////////////////////// #include #include "Proj1_aux.H" /////////////////////////////////////////////////////////////////////////////// // getCmdLine(): // check for command line operation, need to three arguements to start the // program. it will check for three file names and if not provided it will // abort. : Proj1 // Param argc: argc is integer type. this is # of files entered at command // line. // Param argv: array of file names. this will give the actual file names // at particular index position. // Param p: boolean to set perishable to true // Param e: boolean to set equipment to true // Param truckCmds: ifstream object to open the file and read the file // Pre-cond: arguement has to be three file names. if not it will abort. /////////////////////////////////////////////////////////////////////////////// void getCmdLine(int argc, char** argv, bool &p, bool &e, ifstream &truckCmds) { if (argc != 3) { cerr << "Invalid number of command line argument" << endl << "Usage is Proj1

" << endl << "Try again!! Program aborting" << endl; exit(1); } if(!strcmp(argv[1], "perishable")) p = true; if(!strcmp(argv[1], "equipment")) e = true; truckCmds.open(argv[2]); if(!truckCmds) { cerr << "cannot open " << argv[2] << "for input" << endl << "Program terminating" << endl; exit(1); } } /////////////////////////////////////////////////////////////////////////////// // deliverPerishableGoods(): // when perishable is called, it will open the perishable.dat file and start // read the items on the file. after reading the file it will call proper // functions it asked. if wrong command is entered it will exit the program // Param truck: truck is object of Truck class to create truck list. // Param truckCmds: object of ifstream to open the file and write to temp // Pre-cond: perishable has to be set to true. /////////////////////////////////////////////////////////////////////////////// void deliverPerishableGoods (Truck &truck, ifstream &truckCmds) { string cmdStr; string tmpStr1, tmpStr2; int tmpInt; while (truckCmds >> cmdStr) { cout << "Cmd: " << cmdStr << " "; if (strcmp(cmdStr.c_str(), "DRIVE") == 0) { truckCmds >> tmpStr1 >> tmpInt; cout << tmpStr1 << " " << tmpInt << endl; truck.drive(tmpStr1, tmpInt); } else if (strcmp(cmdStr.c_str(), "PRINT") == 0) { cout << endl << truck << endl; } else if (strcmp(cmdStr.c_str(), "LOAD") == 0) { truckCmds >> tmpStr1 >> tmpStr2 >> tmpInt ; cout << tmpStr1 << " " << tmpStr2 << " " << tmpInt << endl; PerishableGoods goodItem(tmpStr1, tmpStr2, tmpInt); truck.load(goodItem); } else if (strcmp(cmdStr.c_str(), "DELIVER") == 0) { truckCmds >> tmpStr1 >> tmpStr2 >> tmpInt; cout << tmpStr1 << " " << tmpStr2 << " " << tmpInt << endl; PerishableGoods goodItem2(tmpStr1, tmpStr2, tmpInt); truck.deliver(goodItem2); } else { cout << "WRONG COMMANDS !!" << endl << "ABORTING!!" < &truck, ifstream &truckCmds) { string cmdStr; string tmpStr1, tmpStr2; int tmpInt; while (truckCmds >> cmdStr) { cout << cmdStr << " : "; if (strcmp(cmdStr.c_str(), "DRIVE") == 0) { truckCmds >> tmpStr1 >> tmpInt; cout << tmpStr1 << " " << tmpInt << endl; truck.drive(tmpStr1, tmpInt); } else if (strcmp(cmdStr.c_str(), "PRINT") == 0) { cout << endl << truck << endl; } else if (strcmp(cmdStr.c_str(), "LOAD") == 0) { truckCmds >> tmpStr1 >> tmpInt; cout << tmpStr1 << " " << tmpInt << endl; EquipmentGoods equipment(tmpStr1, tmpInt); truck.load(equipment); } else if (strcmp(cmdStr.c_str(), "DELIVER") == 0) { truckCmds >> tmpStr1 >> tmpInt; cout << tmpStr1 << " " << tmpInt << endl; EquipmentGoods equipment2(tmpStr1, tmpInt); truck.deliver(equipment2); } else { cout << "WRONG COMMANDS !!" << endl << "ABORTING!!" <