home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / SAMPLES / BROWSER / PAYFUNC.H < prev    next >
Text File  |  1993-04-30  |  3KB  |  117 lines

  1. /* @(#)27    1.3  src/samples/payfunc.h, samples, brs110, 930429 92/11/20 22:04:20 */
  2. /*********************************************
  3. *** payfunc.h -- functions for payroll.cpp ***
  4. *********************************************/
  5.  
  6. // Constructor definition for class manager.
  7. employee::employee(char * n, int id)
  8. {
  9.   name = n;               // Initializing
  10.   employee_id = id;
  11. };
  12.  
  13. // Constructor definition for class manager.
  14. // Note different way to initialize.
  15.  
  16. manager::manager(char *n, int id, double sal)
  17.     : employee(n, id), salary(sal){}
  18.  
  19. // Definition of the pay function for class manager.
  20. double manager::pay()
  21. {
  22.   return salary/12 ; 
  23. // Definition of the print function for class manager. 
  24. void manager::print()
  25. {
  26.   cout << name << " with employee number "
  27.        << employee_id << " makes " << salary
  28.        << " per year.\n"
  29.        << name << " made " << pay() 
  30.        << "  dollars this month.\n\n";
  31. }
  32.  
  33. // Constructor definition for class regular_emp.
  34.  
  35. regular_emp::regular_emp(char *n, int id,
  36.              double wg, double hrs)
  37.             : employee(n, id)
  38. {
  39.   wage = wg;
  40.   hours = hrs;
  41. }
  42.  
  43. // Definition of pay function for class regular_emp. 
  44. double regular_emp::pay()
  45. {
  46.   return  wage*hours;
  47. }
  48.  
  49. // Definition of the print function for class regular_emp.
  50. void regular_emp::print()
  51. {
  52.   cout << name << " with employee number "
  53.        << employee_id << " makes " << wage
  54.        << " dollars per hour\n"
  55.        << " and worked " << hours << " hours this month. \n"
  56.        << name <<" made " << pay()  
  57.        << "  dollars this month.\n\n";
  58. }
  59.  
  60. // Functions for class sales_person
  61.  
  62. // Constructor definition for class sales_person.
  63. sales_person::sales_person(char *n, int id,
  64.                double comm, double nts)
  65.   :employee(n, id), commission(comm), units(nts){}
  66.  
  67. //   Definition of pay function for class sales_person. 
  68. double sales_person::pay()
  69. {
  70.   return (commission*units);
  71. }
  72.  
  73. // Definition of the print function for class sales_person.
  74. void sales_person::print()
  75. {
  76.   cout << name << " with employee number "
  77.        << employee_id << " works for a straight commission of "
  78.        << commission << " dollars per unit sold and sold "
  79.        << units << " units this month.\n"
  80.        << name <<" made " << pay()  
  81.        << "  dollars this month.\n\n";
  82. }
  83.  
  84. // Functions for class sales_mgr.
  85.  
  86. // Constructor definition for class sales_mgr.
  87. sales_mgr::sales_mgr(char *n, int id,
  88.   double sal, double comm, double nts)
  89.   :manager(n, id, sal),
  90.    sales_person(n, id, comm, nts)
  91.  { name = n;
  92.    employee_id = id;
  93.    salary = sal;
  94.    commission = comm;
  95.    units = nts;
  96.  }
  97.  
  98. //   Definition of pay function for class sales_mgr.
  99. double sales_mgr::pay()
  100. { return (manager::pay() + sales_person::pay());}
  101.  
  102. // Definition of the print function for class sales_mgr.
  103. void sales_mgr::print()
  104. {
  105.   cout << name << " with employee number "
  106.        << employee_id << " makes " << salary
  107.        << " per year and earns a commission of "
  108.        << commission << " dollars per unit sold.\n"
  109.        << name << " was responsible for sales of "
  110.        << units << " units this month.\n"
  111.        << name <<" made " << pay()  
  112.        << "  dollars this month.\n\n";
  113. }
  114.  
  115. /**** End of comp_func.h (function definitions).  ****/
  116.