Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.23 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Employee {
  6. private:
  7.     string firstName;
  8.     string lastName;
  9. protected:
  10.     float hourlyPay;
  11.     int totalWorkingHours;
  12. public:
  13.     Employee();
  14.     Employee(string firstName, string lastName, int hourlyPay, int totalWorkingHours);
  15.     Employee(const Employee& e);
  16.     virtual float payout() const;
  17.     const string getFirstName() const;
  18.     void setFirstName(const string firstName);
  19.     const string getLastName() const;
  20.     void setLastName(const string lastName);
  21.     float getHourlyPay() const;
  22.     void setHourlyPay(float hourlyPay);
  23.     int getTotalWorkingHours() const;
  24.     void setTotalWorkingHours(int totalWorkingHours);
  25.     Employee operator++();
  26.     Employee operator++(int);
  27.     friend ostream& operator<<(ostream& o, const Employee& e);
  28.     bool operator==(const Employee& e);
  29. };
  30.  
  31. Employee::Employee() : firstName(""), lastName(""), hourlyPay(0), totalWorkingHours(0) {
  32.  
  33. }
  34.  
  35. Employee::Employee(string firstName, string lastName, int hourlyPay, int totalWorkingHours) :
  36.                             firstName(firstName),
  37.                             lastName(lastName),
  38.                             hourlyPay(hourlyPay),
  39.                             totalWorkingHours(totalWorkingHours) {
  40.  
  41. }
  42.  
  43. Employee::Employee(const Employee &e) : firstName(e.firstName), lastName(e.lastName),
  44.                                 hourlyPay(e.hourlyPay), totalWorkingHours(e.totalWorkingHours) {
  45.  
  46. }
  47.  
  48. float Employee::payout() const {
  49.     return this->hourlyPay * this->totalWorkingHours;
  50. }
  51.  
  52. const string Employee::getFirstName() const {
  53.     return firstName;
  54. }
  55.  
  56. void Employee::setFirstName(const string firstName) {
  57.     this->firstName = firstName;
  58. }
  59.  
  60. const string Employee::getLastName() const {
  61.     return lastName;
  62. }
  63.  
  64. void Employee::setLastName(const string lastName) {
  65.     this->lastName = lastName;
  66. }
  67.  
  68. float Employee::getHourlyPay() const {
  69.     return hourlyPay;
  70. }
  71.  
  72. void Employee::setHourlyPay(float hourlyPay) {
  73.     this->hourlyPay = hourlyPay;
  74. }
  75.  
  76. int Employee::getTotalWorkingHours() const {
  77.     return totalWorkingHours;
  78. }
  79.  
  80. void Employee::setTotalWorkingHours(int totalWorkingHours) {
  81.     Employee::totalWorkingHours = totalWorkingHours;
  82. }
  83.  
  84. ostream& operator<<(ostream &o, const Employee &e) {
  85.     o << e.firstName << " " << e.lastName << " " << e.payout() << endl;
  86.     return o;
  87. }
  88.  
  89. bool Employee::operator==(const Employee &e) {
  90.     if(*this == e) {
  91.         return true;
  92.     }
  93.     return this->payout() == e.payout();
  94. }
  95.  
  96. Employee Employee::operator++() {
  97.     this->hourlyPay++;
  98.     return *this;
  99. }
  100.  
  101. Employee Employee::operator++(int) {
  102.     Employee e = Employee(*this);
  103.     this->hourlyPay++;
  104.     return e;
  105. }
  106.  
  107.  
  108.  
  109. class Manager : public Employee {
  110. private:
  111.     Employee** employees;
  112.     int numEmployees;
  113. public:
  114.     Manager();
  115.     Manager(string firstName, string lastName, int hourlyPay, int totalWorkingHours, Employee** employees = NULL, int numEmployees = 0);
  116.     Manager(const Manager& m);
  117.     float payout() const;
  118.     Manager& operator+=(const Employee* e);
  119. };
  120.  
  121. Manager::Manager() : Employee() {
  122.     this->employees = NULL;
  123.     this->numEmployees = 0;
  124. }
  125.  
  126. Manager::Manager(string firstName, string lastName, int hourlyPay, int totalWorkingHours, Employee **employees = NULL,
  127.                  int numEmployees = 0) : Employee(firstName, lastName, hourlyPay, totalWorkingHours) {
  128.     this->numEmployees = numEmployees;
  129.     if(numEmployees != 0) {
  130.         this->employees = new Employee*[numEmployees];
  131.         for(int i = 0; i < numEmployees; i++) {
  132.             this->employees[i] = new Employee(*employees[i]);
  133.         }
  134.     } else {
  135.         this->employees = NULL;
  136.     }
  137. }
  138.  
  139. Manager::Manager(const Manager& m) : Employee(m.getFirstName(), m.getLastName(), m.hourlyPay, m.totalWorkingHours) {
  140.     this->numEmployees;
  141.     this->employees = new Employee*[numEmployees];
  142.     for(int i = 0; i < numEmployees; i++) {
  143.         this->employees[i] = new Employee(*employees[i]);
  144.     }
  145. }
  146.  
  147. float Manager::payout() const {
  148.     return Employee::payout() + 5 * this->numEmployees * hourlyPay;
  149. }
  150.  
  151. Manager& Manager::operator+=(const Employee *e) {
  152.     Employee** temp = new Employee*[this->numEmployees + 1];
  153.     for(int i = 0; i < this->numEmployees; i++) {
  154.         temp[i] = new Employee(*this->employees[i]);
  155.     }
  156.     temp[this->numEmployees] = new Employee(*e);
  157.     for(int i = 0; i < this->numEmployees; i++) {
  158.         delete this->employees[i];
  159.     }
  160.     delete [] this->employees;
  161.     this->employees = temp;
  162.     return *this;
  163. }
  164.  
  165. class Engineer : public Employee {
  166. private:
  167.     string* projects;
  168.     int numProjects;
  169. public:
  170.     Engineer();
  171.     Engineer(string firstName, string lastName, int hourlyPay, int totalWorkingHours, string* projects = NULL, int numProjects = 0);
  172.     Engineer(const Engineer& e);
  173.     float payout() const;
  174.     Engineer& operator+=(const string& s);
  175. };
  176.  
  177. Engineer::Engineer() : Employee() {
  178.  
  179. }
  180.  
  181. Engineer::Engineer(string firstName, string lastName, int hourlyPay, int totalWorkingHours, string *projects = NULL,
  182.                    int numProjects = 0) : Employee(firstName, lastName, hourlyPay, totalWorkingHours) {
  183.     this->numProjects = numProjects;
  184.     if(numProjects != 0) {
  185.         this->projects = new string[numProjects];
  186.         for(int i = 0; i < numProjects; i++) {
  187.             this->projects[i] = projects[i];
  188.         }
  189.     }
  190. }
  191.  
  192. Engineer::Engineer(const Engineer &e) : Employee(e.getFirstName(), e.getLastName(), e.hourlyPay, e.totalWorkingHours) {
  193.     this->numProjects = e.numProjects;
  194.     this->projects = new string[numProjects];
  195.     for(int i = 0; i < numProjects; i++) {
  196.         this->projects[i] = projects[i];
  197.     }
  198. }
  199.  
  200. float Engineer::payout() const {
  201.     float base = Employee::payout();
  202.     for(int i = 0; i < numProjects; i++) {
  203.         base = (float) 1.1 * base;
  204.     }
  205.     return base;
  206. }
  207.  
  208. Engineer& Engineer::operator+=(const string &s) {
  209.     string* temp = new string[this->numProjects + 1];
  210.     for(int i = 0; i < numProjects; i++) {
  211.         temp[i] = this->projects[i];
  212.     }
  213.     temp[this->numProjects] = s;
  214.     delete [] this->projects;
  215.     this->projects = temp;
  216.     return *this;
  217. }
  218.  
  219. int main() {
  220.     std::cout << "Hello, World!" << std::endl;
  221.     return 0;
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement