Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Employee {
- private:
- string firstName;
- string lastName;
- protected:
- float hourlyPay;
- int totalWorkingHours;
- public:
- Employee();
- Employee(string firstName, string lastName, int hourlyPay, int totalWorkingHours);
- Employee(const Employee& e);
- virtual float payout() const;
- const string getFirstName() const;
- void setFirstName(const string firstName);
- const string getLastName() const;
- void setLastName(const string lastName);
- float getHourlyPay() const;
- void setHourlyPay(float hourlyPay);
- int getTotalWorkingHours() const;
- void setTotalWorkingHours(int totalWorkingHours);
- Employee operator++();
- Employee operator++(int);
- friend ostream& operator<<(ostream& o, const Employee& e);
- bool operator==(const Employee& e);
- };
- Employee::Employee() : firstName(""), lastName(""), hourlyPay(0), totalWorkingHours(0) {
- }
- Employee::Employee(string firstName, string lastName, int hourlyPay, int totalWorkingHours) :
- firstName(firstName),
- lastName(lastName),
- hourlyPay(hourlyPay),
- totalWorkingHours(totalWorkingHours) {
- }
- Employee::Employee(const Employee &e) : firstName(e.firstName), lastName(e.lastName),
- hourlyPay(e.hourlyPay), totalWorkingHours(e.totalWorkingHours) {
- }
- float Employee::payout() const {
- return this->hourlyPay * this->totalWorkingHours;
- }
- const string Employee::getFirstName() const {
- return firstName;
- }
- void Employee::setFirstName(const string firstName) {
- this->firstName = firstName;
- }
- const string Employee::getLastName() const {
- return lastName;
- }
- void Employee::setLastName(const string lastName) {
- this->lastName = lastName;
- }
- float Employee::getHourlyPay() const {
- return hourlyPay;
- }
- void Employee::setHourlyPay(float hourlyPay) {
- this->hourlyPay = hourlyPay;
- }
- int Employee::getTotalWorkingHours() const {
- return totalWorkingHours;
- }
- void Employee::setTotalWorkingHours(int totalWorkingHours) {
- Employee::totalWorkingHours = totalWorkingHours;
- }
- ostream& operator<<(ostream &o, const Employee &e) {
- o << e.firstName << " " << e.lastName << " " << e.payout() << endl;
- return o;
- }
- bool Employee::operator==(const Employee &e) {
- if(*this == e) {
- return true;
- }
- return this->payout() == e.payout();
- }
- Employee Employee::operator++() {
- this->hourlyPay++;
- return *this;
- }
- Employee Employee::operator++(int) {
- Employee e = Employee(*this);
- this->hourlyPay++;
- return e;
- }
- class Manager : public Employee {
- private:
- Employee** employees;
- int numEmployees;
- public:
- Manager();
- Manager(string firstName, string lastName, int hourlyPay, int totalWorkingHours, Employee** employees = NULL, int numEmployees = 0);
- Manager(const Manager& m);
- float payout() const;
- Manager& operator+=(const Employee* e);
- };
- Manager::Manager() : Employee() {
- this->employees = NULL;
- this->numEmployees = 0;
- }
- Manager::Manager(string firstName, string lastName, int hourlyPay, int totalWorkingHours, Employee **employees = NULL,
- int numEmployees = 0) : Employee(firstName, lastName, hourlyPay, totalWorkingHours) {
- this->numEmployees = numEmployees;
- if(numEmployees != 0) {
- this->employees = new Employee*[numEmployees];
- for(int i = 0; i < numEmployees; i++) {
- this->employees[i] = new Employee(*employees[i]);
- }
- } else {
- this->employees = NULL;
- }
- }
- Manager::Manager(const Manager& m) : Employee(m.getFirstName(), m.getLastName(), m.hourlyPay, m.totalWorkingHours) {
- this->numEmployees;
- this->employees = new Employee*[numEmployees];
- for(int i = 0; i < numEmployees; i++) {
- this->employees[i] = new Employee(*employees[i]);
- }
- }
- float Manager::payout() const {
- return Employee::payout() + 5 * this->numEmployees * hourlyPay;
- }
- Manager& Manager::operator+=(const Employee *e) {
- Employee** temp = new Employee*[this->numEmployees + 1];
- for(int i = 0; i < this->numEmployees; i++) {
- temp[i] = new Employee(*this->employees[i]);
- }
- temp[this->numEmployees] = new Employee(*e);
- for(int i = 0; i < this->numEmployees; i++) {
- delete this->employees[i];
- }
- delete [] this->employees;
- this->employees = temp;
- return *this;
- }
- class Engineer : public Employee {
- private:
- string* projects;
- int numProjects;
- public:
- Engineer();
- Engineer(string firstName, string lastName, int hourlyPay, int totalWorkingHours, string* projects = NULL, int numProjects = 0);
- Engineer(const Engineer& e);
- float payout() const;
- Engineer& operator+=(const string& s);
- };
- Engineer::Engineer() : Employee() {
- }
- Engineer::Engineer(string firstName, string lastName, int hourlyPay, int totalWorkingHours, string *projects = NULL,
- int numProjects = 0) : Employee(firstName, lastName, hourlyPay, totalWorkingHours) {
- this->numProjects = numProjects;
- if(numProjects != 0) {
- this->projects = new string[numProjects];
- for(int i = 0; i < numProjects; i++) {
- this->projects[i] = projects[i];
- }
- }
- }
- Engineer::Engineer(const Engineer &e) : Employee(e.getFirstName(), e.getLastName(), e.hourlyPay, e.totalWorkingHours) {
- this->numProjects = e.numProjects;
- this->projects = new string[numProjects];
- for(int i = 0; i < numProjects; i++) {
- this->projects[i] = projects[i];
- }
- }
- float Engineer::payout() const {
- float base = Employee::payout();
- for(int i = 0; i < numProjects; i++) {
- base = (float) 1.1 * base;
- }
- return base;
- }
- Engineer& Engineer::operator+=(const string &s) {
- string* temp = new string[this->numProjects + 1];
- for(int i = 0; i < numProjects; i++) {
- temp[i] = this->projects[i];
- }
- temp[this->numProjects] = s;
- delete [] this->projects;
- this->projects = temp;
- return *this;
- }
- int main() {
- std::cout << "Hello, World!" << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement