//////////////////////////////////////////////////////////////////////////////// // Truck.H // // CMSC341 Fall 2001 -Project 1 // // Kyu Bae 212-04-5868 Section 201 // // kyu_bae@yahoo.com /kbae1@umbc.edu // // created: 1 September 2001 // // current: 16 September 2001 // //////////////////////////////////////////////////////////////////////////////// //header files #ifndef _TRUCK_H #define _TRUCK_H #include "vector.H" #include "string.H" //////////////////////////////////////////////////////////////////////////////// // Truck carries a homogeneous collection of goods. It will have unlimited // capacity, the number of goods. the actual number of goods increases as // goods are loaded and decreses as they are delivered. The Truck has three // data members, totalMiles, listOfGoods, currentLocation. several operatons // are done to truck , load, deliver, drive etc. Template was used here // for two kinds of goods. It will be either "perishable" or "equipment". // They are using same Truck class functions. // Author: kyu bae // Version: 11 september 2001 /////////////////////////////////////////////////////////////////////////////// template class Truck { public: ////////////////////////////////////////////////////////////////////////// // default constructor: // totalMiles is 0 and currentLocation is at Depot ///////////////////////////////////////////////////////////////////////// Truck(); //////////////////////////////////////////////////////////////////////// // copy constructor: // maked a copy of Truck object with same data members. // Param rhs: another Truck to copy //////////////////////////////////////////////////////////////////////// Truck(const Truck & rhs); /////////////////////////////////////////////////////////////////////// // Destructor: ////////////////////////////////////////////////////////////////////// ~Truck(); ////////////////////////////////////////////////////////////////////// // Assignment operator: // assgin tr to this Truck. This is also called from the copy // constructor. This just assigns object's data members. // Param tr: tr is the Truck to assign the rvalue // return: this Truck after assigning the data members ////////////////////////////////////////////////////////////////////// const Truck& operator= (const Truck & tr); ///////////////////////////////////////////////////////////////////// // print three data members: tell its current location and total // miles of truck drove. // Param out: ostream's object to write and call operator << ///////////////////////////////////////////////////////////////////// void print (ostream &out) const; ////////////////////////////////////////////////////////////////////// // load items to truck. Check if they are same item and if they are // not same add the item to Truck. // Param item: item of Object to Truck // Pre-cond: item has to be different, one of three data types has // be different. ///////////////////////////////////////////////////////////////////// void load (const Object & item); ///////////////////////////////////////////////////////////////////// // deliver item to destination and delete the item from the Truck // Param item: item of Object to Truck // Pre-cond: item has to be on the TRuck in order to deliver ///////////////////////////////////////////////////////////////////// void deliver (const Object & item); ////////////////////////////////////////////////////////////////////// // drive to destination and keep track of how many miles you have // driven and currentLocation. // Param destination : assign destination to current location // Param miles : miles to totalmiles // Pre-cond: if asked to go same place, tell you are there already. ////////////////////////////////////////////////////////////////////// void drive (string destination, int miles); ///////////////////////////////////////////////////////////////////// // accessor: checking if the vector is empty. // return: boolean for empty or not.. //////////////////////////////////////////////////////////////////// bool isEmpty() const; /////////////////////////////////////////////////////////////////// // mutator: making the vector empty. resizing the vector listOfGoods // to zero. truck become empty. deleting all the items /////////////////////////////////////////////////////////////////// void MakeEmpty(); private: int totalMiles; //miles truck has driven vector listOfGoods; //items of goods are kept in vector class string currentLocation; //where truck is at currently. }; ///////////////////////////////////////////////////////////////////////// // output operator: // print object by calling the print function // Param out: out the stream to which to write rTruck // Param rTruck: rTruck is Object to write // return: ostream ///////////////////////////////////////////////////////////////////////// template ostream & operator << (ostream &out, const Truck &rTruck); #include "Truck.C" //for g++ template has to be included like this #endif