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 / employee.h < prev    next >
C/C++ Source or Header  |  2005-06-16  |  4KB  |  112 lines

  1. //                       employee.h
  2. //
  3. // An employee class - first inheritance example
  4.  
  5. class employee {
  6. public:
  7.     employee();
  8.     // PRECONDITION:  none.
  9.     //
  10.     // POSTCONDITION: name is initialized to the null 
  11.     //                string; salary is set to 0 and 
  12.     //                groupno is set to 0.
  13.  
  14.     employee( const employee& e );
  15.     // PRECONDITION:  none.
  16.     //
  17.     // POSTCONDITION: the constructed object is a copy of e.
  18.  
  19.     employee( char * n, int s, int g );
  20.     // PRECONDITION:  n should be a null terminated string; 
  21.     //                s should be >= 0, and g should be a 
  22.     //                non-negative integer that represents a 
  23.     //                group number.
  24.     //
  25.     // POSTCONDITION: name will be set to n. salary will be 
  26.     //                the maximum of s and 0; groupno will 
  27.     //                be maximum of g and 0.
  28.  
  29.     ~employee();
  30.     // PRECONDITION:  none.
  31.     //
  32.     // POSTCONDITION: the employee is properly destroyed.
  33.  
  34.     // Mutators
  35.     bool salary_set( int s );
  36.     // PRECONDITION:  s must be non-negative.
  37.     //
  38.     // POSTCONDITION: if s is non-negative, salary has 
  39.     //                been set to s and true is returned. 
  40.     //                If s<0, salary is unchanged and 
  41.     //                false is returned.
  42.  
  43.     void change_group( int g );
  44.     // PRECONDITION:  g must be a non-negative integer that
  45.     //                represents a group number.
  46.     // POSTCONDITION: groupno has been set to g.
  47.  
  48.     // Accessors
  49.     int get_group() const { return groupno; }
  50.     // PRECONDITION:  none.
  51.     //
  52.     // POSTCONDITION: the group number is returned.
  53.  
  54.     const char * get_name() const { return name; }
  55.     // PRECONDITION:  none.
  56.     //
  57.     // POSTCONDITION: the name is returned.
  58.  
  59.     int get_salary() const { return salary; }
  60.     // PRECONDITION:  none.
  61.     //
  62.     // POSTCONDITION: the current salary is returned.
  63.     // Utility Functions
  64.  
  65.     void print() const;
  66.     // PRECONDITION:  none.
  67.     //
  68.     // POSTCONDITION: the employee information will be displayed
  69.     //                on standard output.
  70.  
  71.     // Operations
  72.     employee& operator= ( const employee& emp );
  73.     // PRECONDITION:  none.
  74.     //
  75.     // POSTCONDITION: The invoking object will have the same
  76.     //                values as emp.
  77.  
  78. private:
  79.     int salary;
  80.     char *name;
  81.     int groupno;
  82. };
  83.  
  84. class manager: public employee {                     // Note 1
  85. public:
  86.     manager( char * n, int s, int g, int o );
  87.     // PRECONDITION:  n must be a null terminated string. s 
  88.     //                and g should be non-negative integers. 
  89.     //                o should represent an office number.
  90.     // POSTCONDITION: a manager object has been created 
  91.     //                with name n, salary s, group g, 
  92.     //                office o, and num_in_group equal to 0.
  93.  
  94.     bool set_group( employee& e );
  95.     // PRECONDITION:  none. 
  96.     //
  97.     // POSTCONDITION: If the return value is true, e has 
  98.     //                been added to the group. If the return 
  99.     //                value is false, e was not added to the group.
  100.  
  101.     void print() const;                              // Note 2
  102.     // PRECONDITION:  none.
  103.     //
  104.     // POSTCONDITION: the manager information and the manager's 
  105.     //                group have been displayed on standard output.
  106.  
  107. private:
  108.     employee *group[10];
  109.     int office;
  110.     int num_in_group;
  111. };
  112.