home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK4 / SAMPLES / CPPTUTOR / EMPLOYEE.CP$ / EMPLOYEE
Encoding:
Text File  |  1991-12-11  |  1.3 KB  |  87 lines

  1. // EMPLOYEE.CPP
  2.  
  3. #include "employee.h"
  4. #include <string.h>
  5.  
  6. // Employee member functions
  7.  
  8. Employee::Employee( const char *nm )
  9. {
  10.     strncpy( name, nm, 30 );
  11.     name[29] = '\0';
  12. }
  13.  
  14. char *Employee::getName() const
  15. {
  16.     return name;
  17. }
  18.  
  19. // WageEmployee member functions
  20.  
  21. WageEmployee::WageEmployee( const char *nm )
  22.     : Employee( nm )
  23. {
  24.     wage = 0.0;
  25.     hours = 0.0;
  26. }
  27.  
  28. void WageEmployee::setWage( float wg )
  29. {
  30.     wage = wg;
  31. }
  32.  
  33. void WageEmployee::setHours( float hrs )
  34. {
  35.     hours = hrs;
  36. }
  37.  
  38. float WageEmployee::computePay() const
  39. {
  40.     return wage * hours;
  41. }
  42.  
  43. // SalesPerson member functions
  44.  
  45. SalesPerson::SalesPerson( const char *nm )
  46.     : WageEmployee( nm )
  47. {
  48.     commission = 0.0;
  49.     salesMade = 0.0;
  50. }
  51.  
  52. void SalesPerson::setCommission( float comm )
  53. {
  54.     commission = comm;
  55. }
  56.  
  57. void SalesPerson::setSales( float sales )
  58. {
  59.     salesMade = sales;
  60. }
  61.  
  62. float SalesPerson::computePay() const
  63. {
  64.     // Call base class's version of computePay
  65.     return WageEmployee::computePay() +
  66.            commission * salesMade;
  67. }
  68.  
  69. // Manager member functions
  70.  
  71. Manager::Manager( const char *nm )
  72.     : Employee( nm )
  73. {
  74.     weeklySalary = 0.0;
  75. }
  76.  
  77. void Manager::setSalary( float salary )
  78. {
  79.     weeklySalary = salary;
  80. }
  81.  
  82. float Manager::computePay() const
  83. {
  84.     return weeklySalary;
  85. }
  86.  
  87.