Question: Need help with c++ lab. Here are the instructions: Create a C++ project, and call it Week 5Inheritance. Now, let's realize the UML class diagram,

Need help with c++ lab. Here are the instructions:

Create a C++ project, and call it Week 5Inheritance. Now, let's realize the UML class diagram, which means let's take the UML class diagram to code.

Create an Employee class using a separate header file and implementation file. Review your UML class diagram for the attributes and behaviors

The calculatePay() method should return 0.0f.

The toString() method should return the attribute values ("state of the object").

Create an Hourly class using a separate header file and implementation file.

The Hourly class needs to inherit from the Employee class

The calculatePay() method should return the pay based on the number of hours worked and the pay rate. Remember to calculate overtime!

Create a Salary class using a separate header file and implementation file.

The Salary class needs to inherit from the Employee class.

The calculatePay() method should return the annualSalary divided by 52.0f because there are 52 weeks in the year.

Create a Manager class using a separate header and implementation file.

The Manager class needs to inherit from the Salary class (yes, a Child class can be a Parent class).

The calculatePay() method should use the Salary's calculatePay() method plus the bonus divided by 52.0f (base pay plus bonus).

This is what I have so far, must be in c++.

Source.cpp:

#include

#include

#include

using namespace std;

int main()

{

string Hourly::toString()

{

string ss;

cout << "PayRate :" << hourlyRate << endl;

cout << "Hours Worked:" << hoursWorked << endl;

return ss.str();

}

}

Manager.h:

#pragma once

#include

#include "Salary.h"

using namespace std;

class Manager : public Salary {

private:

float bonus;

public:

Manager(float a, float b) : Salary(a)

{

bonus = b;

}

float calculatePay();

string toString();

};

Manager.cpp

#include "Manager.h"

using namespace std;

float Manager::calculatePay() {

return Salary::calculatePay + bonus / 52.0;

}

string Salary::toString() {

string ss;

cout << "Bonus: $" << bonus;

return Salary::toString() + "/n" + ss;

}

Salary.h:

#pragma once

#include

#include "Employee.h"

using namespace std;

class Salary : public Employee {

private:

float annualSalary;

public:

Salary(float a);

float calculatePay();

string toString();

};

Salary.cpp:

#include "Salary.h"

using namespace std;

Salary::Salary(float a) {

annualSalary = a;

}

float Salary::calculatePay() {

return annualSalary / 52.0;

}

string Salary::toString()

{

string ss;

cout << "Annual Salary: $" << annualSalary;

return ss;

};

Hourly.h:

#pragma once

#include

#include "Employee.h"

using namespace std;

class Hourly : Employee

{

double payRate;

double hours;

public:

Hourly();

~Hourly();

string toString() override;

float calculatePay() override;

};

Hourly.cpp:

#include "Hourly.h"

#include "Employee.h"

#include

#include

#include

using namespace std;

Hourly::Hourly(double hoursWorked, double hourlyRate)

{

hours = hoursWorked;

payRate = hourlyRate;

}

Hourly::~Hourly()

{

}

float Hourly::calculatePay()

{

//payRate and hours can be used

float totalPay;

float overTimePay;

if (hours > 40)

{

overTimePay = 40 * payRate * (hours - 40);

totalPay = overTimePay + 40 * payRate;

}

else

{

totalPay = payRate * hours;

}

return totalPay;

}

string Hourly::toString()

{

return "state of the object";

}

Employee.h:

#pragma once

#include

#include

#include

using namespace std;

class Employee

{

public:

Employee();

~Employee();

virtual float calculatePay();

virtual std::string toString();

};

Employee.cpp:

#include "Employee.h"

#include

#include

#include

using namespace std;

Employee::Employee()

{

}

Employee::~Employee()

{

}

float Employee::calculatePay()

{

return 0.0;

}

string Employee::toString()

{

return "state of the object";

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!