Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include #include Employee.h #include Hourly.h #include Salary.h #include Manager.h using namespace std ; void printEmployee (Employee * emp) { cout < < Employee info
#include#include #include "Employee.h" #include "Hourly.h" #include "Salary.h" #include "Manager.h" using namespace std; void printEmployee(Employee * emp) { cout << "Employee info" << endl; cout << emp->toString(); cout << "Employee pay: $" << emp->calculatePay() << endl; Manager * mgr = dynamic_cast (emp); if (mgr != NULL) { cout << "Bonus: $" << mgr->getBonus() << endl; } cout << endl << endl; } int main() { Hourly firstEmployee("John", "Smith", "123-45-6789", "888-888-8888", 30, 27); Salary secondEmployee("Henry", "Jones", "711-50-7589", "999-999-999", 50000); Manager thirdEmployee("Edward", "Johnson", "931-45-9010", "555-555-555", 50000, 5000); cout << "Size of first object: " << sizeof(firstEmployee) << endl; cout << "Size of first object pointer: " << sizeof(&firstEmployee) << endl; printEmployee(&firstEmployee); printEmployee(&secondEmployee); printEmployee(&thirdEmployee); cout << endl; system("pause"); return 0; } #pragma once #include #include #include #include "Salary.h" using namespace std; class Manager : public Salary { private: double bonus; public: float calculatePay(); string toString(); double getBonus(); Manager(string fname, string lname, string ssn, string phone, double annualSalary, double bonus); }; #include "Manager.h" float Manager::calculatePay() { return (Salary::annualSalary + bonus) / 52.0; } string Manager::toString() { stringstream output; output << Salary::toString(); output << fixed << setprecision(2); output << "Total Weekly Pay With Bonus: $" << calculatePay() << endl; output << "Bonus: $" << bonus << endl; return output.str(); } double Manager::getBonus() { return bonus; } Manager::Manager(string fname, string lname, string ssn, string phone, double annualSalary, double bonus) : Salary(fname, lname, ssn, phone, annualSalary) { this->bonus = bonus; } #pragma once #include #include using namespace std; class Employee { protected: string fname; string lname; string ssn; string phone; public: virtual float calculatePay() = 0; virtual string toString(); Employee(string fname, string lname, string ssn, string phone); }; #include "Employee.h" float Employee::calculatePay() { return 0.0; } string Employee::toString() { stringstream output; output << "Employee name: " << fname << " " << lname << endl; output << "Employee's SSN: " << ssn << endl; output << "Employee's Phone Number: " << phone << endl; return output.str(); } Employee::Employee(string fname, string lname, string ssn, string phone) { this->fname = fname; this->lname = lname; this->ssn = ssn; this->phone = phone; } #pragma once #include #include #include #include "Employee.h" using namespace std; class Hourly : public Employee { private: float rate; float hours; public: float calculatePay(); string toString(); Hourly(string fname, string lname, string ssn, string phone, float rate, float hours); }; #include "Hourly.h" float Hourly::calculatePay() { return hours * rate; } string Hourly::toString() { stringstream output; output << Employee::toString(); output << fixed << setprecision(2); output << "Total Amount Payed: $" << hours * rate << endl; return output.str(); } Hourly::Hourly(string fname, string lname, string ssn, string phone, float rate, float hours) : Employee(fname, lname, ssn, phone) { this->rate = rate; this->hours = hours; } #pragma once #include #include #include #include "Employee.h" using namespace std; class Salary : public Employee { protected: double annualSalary; public: float calculatePay(); string toString(); Salary(string fname, string lname, string ssn, string phone, double annualSalary); }; #include "Salary.h" float Salary::calculatePay() { return annualSalary / 52.0; } string Salary::toString() { stringstream output; output << Employee::toString(); output << fixed << setprecision(2); output << "Total Weekly Pay: $" << annualSalary / 52.0 << endl; output << "Total Annual Salary:"<< annualSalary << endl; return output.str(); } Salary::Salary(string fname, string lname, string ssn, string phone, double annualSalary) : Employee(fname, lname, ssn, phone) { }
Help me fix my code and please stop reporting me. I only need help fixing this issue. thank you.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started