Here is the question....
Write a base class Worker and derived classes HourlyWorker and SalariedWorker. Every worker has a name and a salary rate. Write a virtual function ComputePay (in hour) that computes weekly pay for every worker. An hourly worker gets paid the hourly wages for the actual number of hours worked. The hours are at most 40 per week. If it is greater than 40, the worker gets 1.5 times of the hourly rate for excess hour. Te salaried worker gets paid the hourly wage for 40 hours, no matter what the actual number of hours is .
And here is the little code I have so far. The int main() was given to me, and I need to write the base worker class and the two derived classes. But I am lost. Thanks for any help!
Code:
#include <iostream>
using namespace std;
class Worker
{
public:
{
virtual compute_Pay(float hours);} //this doesn't like to compile correctly
//hourly and salaried functions
}
}
class hourly: public Worker
{
compute_Pay; //need to add the computer_Pay in here, salaried, and worker.
//and functions that calculate hourly guys with/without overtime
}
class Salaried: public Worker
{
compute_Pay=; //also need to add functions that calculate just salaried guys
};
int main()
{
HourlyWorker a("Sam", 20);
HourlyWorker b("Mary", 15);
SalariedWorker c("Tom", 30);
SalariedWorker d("Pat", 40);
cout << "Hourly worker " << a.get_name() << " earns $" << a.get_salary();
cout << " and worked 20 hours for a pay of $" << a.compute_pay(20) << "\n";
cout << "Hourly worker " << b.get_name() << " earns $" << b.get_salary();
cout << " and worked 50 hours for a pay of $" << b.compute_pay(50) << "\n";
cout << "Salaried worker " << c.get_name() << " earns $" << c.get_salary();
cout << " and worked 20 hours for a pay of $" << c.compute_pay(20) << "\n";
cout << "Salaried worker " << d.get_name() << " earns $" << d.get_salary();
cout << " and worked 50 hours for a pay of $" << d.compute_pay(50) << "\n";
system("pause");
return 0;
}