Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

on microsoft visual studio C++ Scenario/Summary The objective of the lab is to t

ID: 3848882 • Letter: O

Question

on microsoft visual studio C++

Scenario/Summary

The objective of the lab is to take the UML Class diagram and enhance last week's Employee class by making the following changes:

Create a class called Salaried that is derived from Employee.

Create a class called Hourly that is also derived from Employee.

Override the base class calculatePay() method.

Override the displayEmployee() method.

STEP 1: Understand the UML Diagram

Notice the change in UML diagram. It is common practice to leave out the accessors and mutators (getters and setters) from UML class diagrams, since there can be so many of them. Unless otherwise specified, it is assumed that there is an accessor (getter) and a mutator (setter) for every class attribute.

STEP 2: Create the Project

Create a new project and name it CIS247C_WK5_Lab_LASTNAME. Copy all the source files from the Week 4 project into the Week 5 project.

Before you move on to the next step, build and execute the Week 5 project.

STEP 3: Modify the Employee Class

Using the updated Employee class diagram, modify the attributes to be protected.

Delete the iEmployee interface class, and remove the reference from the Employee class.

STEP 4: Create the Salaried Class

Using the UML Diagrams from Step 1, create the Salaried classes, ensuring to specify that the Salary class inherits from the Employee class.

For each of the constructors listed in the Salaried class, ensure to invoke the appropriate base class constructor and pass the correct arguments to the base class constructor. This will initialize the protected attributes and update the numEmployees counter.

The valid management levels are 0, 1, 2, and 3, and should be implemented as a constant.

Override the calculatePay method to add a 10 percent bonus for each of the management levels (i.e., bonus percentage = managementLevel * .10). The bonus percentage should be implemented as a constant.

Override the displayEmployee() method to add the management level to the employee information.

STEP 5: Create the Hourly Class

Using the UML Diagrams from Step 1, create the Hourly classes, ensuring to specify that the Hourly class inherits from the Employee class.

For each of the constructors listed in the Hourly class, ensure to invoke the appropriate base class constructor and pass the correct arguments to the base class constructor. This will initialize the protected attributes and update the numEmployees counter.

The valid category types are "temporary", "part time", and "full time".

The provided hours must be more than 0 hours and less than 50 hours, and the limits should be implemented as constants.

The provided wage must be between 10 and 75, and the limits should be implemented as constants.

Override the calculatePay method by multiplying the wages by the number of hours.

Override the Employee setAnnualSalary method and set the annual salary by multiplying the weekly pay by 50.

Override the displayEmployee() method to add the category to the hourly employee information.

STEP 6: Modify the Main Method

Using previous weeks' assignments as an example, create at least one Employee, Hourly, and Salaried employee.

For each object created, display the number of employees created.

For each object created, write statements to exercise each of the public methods listed in the Class diagram.

For each object created, invoke the object's displayEmployee() method to display the employee's information.

For employee, the following information needs to be displayed:

For salaried employee, the following information needs to be displayed:

For hourly employee, the following information needs to be displayed:

STEP 7: Compile and Test

When done, compile and run your code.

Then, debug any errors until your code is error-free.

Check your output to ensure that you have the desired output, modify your code as necessary, and rebuild.

Below is the complete sample program output for your reference.

Benefit Employee healthinsurance string #firstName string -lifeinsurance double #lastName string vacation int #gender char +Benefit #dependents int +Benefit (in hins String, in lins double, in vac: nt #annual salary double display Benefits Void #benefit Benefit static numEmployees int 30 +Employee() +Employee (in fname string, in Iname string, in gen char, in dep int, in benefits Benefit) static getNumEmployees nt +Calculate Pay() double display Employee Void Salaried MIN MANAGEMENT LEVEL int 0 MAX MANAGEMENT LEVEL int 3 BONUS PERCENT double 10 management eve nt +Salaried +Salaried(in fname string, in Iname string, in gen char, in dep int, in sal double, in ben Benefit, in manLevel int) +Salaried in sal double, in manLevel nt +CalculatePay() double +displayEmployee() void Hour MIN WAGE double 10 MAX WAGE double 75 MIN HOURS double 0 -MAX HOURS: double 50 -wage double -hours double category: string +Hour +Hourly(in w double, in hours double, in category: string age +Hourly n fname string, in Iname string, in gen char, in dep int, in age double n hours double, in ben Benefit, in category: string +Calculate Pay() double display Employee Void

Explanation / Answer

#include <iostream>
#include <string>
#include <stdlib.h>
#include <iomanip>
using namespace std;
const double MIN_SALARY = 20000;
const double MAX_SALARY = 100000;
const int MAX_DEPENDENTS = 15;
const int MIN_DEPENDENTS = 0;
const char DEFAULT_GENDER = 'N';
const int NUMBER_WEEKS = 52;
class Employee
{
string firstName;
string lastName;
char gender;
int dependents;
double annualSalary;
static int numEmployees;
public:
Employee()
{
firstName = "";
lastName = "";
gender = 'N';
annualSalary = 20000;
}
Employee(string firstName, string lastName, char gender, int dependents, double salary)
{
this->firstName = firstName;
this->lastName = lastName;
this->gender = gender;
this->dependents = dependents;
this->annualSalary = annualSalary;
}
string getFirstName()
{
return firstName;
}
void setFirstName(string name)
{
firstName = name;
}
string getLastName()
{
return lastName;
}
void setLastName(string name)
{
lastName = name;
}
char getGender()
{
return gender;
}
void setGender(char gen)
{
switch (gen)
{
case'f': case'F': case'M': case'm':
gender = gen;
break;
default:
gender = DEFAULT_GENDER;
}
}
int getDependents()
{
return dependents;
}
void setDependents(int dep)
{
if (dep >= MIN_DEPENDENTS && dep <= MAX_DEPENDENTS)
{
dependents = dep;
}
else if (dep < MIN_DEPENDENTS)
{
dep = MIN_DEPENDENTS;
}
else
{
dependents = MAX_DEPENDENTS;
}
}
double getAnnualSalary()
{
return annualSalary;
}
void setAnnualSalary(double salary)
{
if(salary >= MIN_SALARY && salary <= MAX_SALARY)
{
annualSalary = salary;
}
else if (salary < MIN_SALARY)
{
annualSalary = MIN_SALARY;
}
else
{
annualSalary = MAX_SALARY;
}
}
double calculatePay()
{
return annualSalary;
}
void displayEmployee()
{
cout<<"First Name: "<<firstName<<endl;
cout<<"Last Name: "<<lastName<<endl;
cout<<"Gender: "<<gender<< " ";
cout<<"Dependents: "<<dependents<< " ";
cout<<"Annual Salary: "<</* setprecision(2)<<showpoint<<fixed<<*/annualSalary << " ";
cout<<"Weekly Salary: "<</* setprecision(2)<<showpoint<<fixed<<*/calculatePay();


};
void DisplayApplicationInformation()
{
cout<<"Welcome to my Employee Class Design"<<endl;
cout<<"Wright, Christopher"<<endl;
cout<<"CIS247C Week Two Lab"<<endl;
}
void DisplayDivider(string message)
{
cout<<" ************ " + message + " ************ ";
}
string GetUserInput(string message)
{
string mystring;
cout<<"Please enter your "<<message;
getline(cin, mystring);
return mystring;

}
void TerminateApplication()
{
cout<<" Thanks for using my class design. ";
}
int main()
{
Employee employee1;
char gender;
string str;
DisplayApplicationInformation();
DisplayDivider("Employee1");
employee1.setFirstName(GetUserInput("First Name "));
employee1.setLastName(GetUserInput("Last Name "));
str = GetUserInput("Gender ");
gender = str.at(0);
employee1.setGender(gender);
employee1.setDependents(atoi(GetUserInput("Dependents ").c_str()));
employee1.setAnnualSalary(atoi(GetUserInput("Annual Salary ").c_str()));
employee1.displayEmployee();
DisplayDivider("Employee 2");
DisplayDivider("Employee 2");
Employee employee2("Nathalie", "Delicia","Dan",'F', 3, 170000);
employee2.displayEmployee();
employee3.displayEmployee();
TerminateApplication();
return 0;

}