home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch12 / invItem.h < prev    next >
C/C++ Source or Header  |  2005-06-16  |  3KB  |  68 lines

  1. //                          invItem.h
  2. //
  3. // Declaration of the invItem class
  4. class invItem {
  5. public:
  6.     invItem();                                       // Note 2
  7.     // PRECONDITION:  none
  8.     //
  9.     // POSTCONDITION: The data members of the object have
  10.     //                been initialized to default values.
  11.  
  12.     invItem( const invItem& item );                  // Note 3
  13.     // PRECONDITION:  none
  14.     //
  15.     // POSTCONDITION: the constructed object is a copy of item.
  16.  
  17.     invItem( char *the_id, int the_num = 0 );        // Note 4
  18.     // PRECONDITION:  none
  19.     //
  20.     // POSTCONDITION: the object is constructed with id equal the_id 
  21.     //                andnum_available equal the_num.
  22.  
  23.     ~invItem();                                      // Note 5
  24.     // PRECONDITION:  none
  25.     //
  26.     // POSTCONDITION: the object has been properly destroyed.
  27.  
  28.     bool changeNum( int change_amt );                // Note 6
  29.     // PRECONDITION:  change_amt should be the amount by which the
  30.     //                number in the inventory has changed.
  31.     // POSTCONDITION: If change_amt is positive, num_available 
  32.     //                will be incremented by change_amt and 
  33.     //                true will be returned. If change_amt is 
  34.     //                negative, the return value will be true 
  35.     //                if num_available+change_amt
  36.     //                is greater or equal to 0. The new value 
  37.     //                of num_available will be num_available + 
  38.     //                change_amt. If change_amt is negative and 
  39.     //                num_available+change_amt is also negative,
  40.     //                the return value will be false and
  41.     //                change_amt will remain unchanged.
  42.  
  43.     bool changeId( char *newId );                    // Note 7
  44.     // PRECONDITION:  newId should be a null terminated 
  45.     //                C style string.
  46.     // POSTCONDITION: The id has been changed to newId; the return
  47.     //                value is true.
  48.  
  49.     const char * getId() const { return id; }        // Note 8
  50.     // PRECONDITION:  none
  51.     //
  52.     // POSTCONDITION: the return value is the item's id.
  53.  
  54.     int whatsLeft() const { return num_available; }    
  55.     // PRECONDITION:  none
  56.     //
  57.     // POSTCONDITION: the return value is num_available
  58.  
  59.     void display();
  60.     // PRECONDITION:  none
  61.     //
  62.     // POSTCONDITION: the id and number in inventory
  63.     //                have been displayed on standard output
  64.  
  65. private:
  66.     char *id;                                        // Note 1
  67.     int num_available;
  68. };