**Note - Any updates to the description will be found on the ZyBook description of this project.
Pete’s Pets has four types of employees.
Managers, who receive a fixed weekly salary
Clerks, who receives a fixed hourly wage for up to the first 40 hours they work and "time-and-a-half," i.e., 1.5 times their hourly wage, for overtime hours worked
Vets, who receive 800plus3.75 for each vaccine they administer
Stylists, who receive a fixed amount of money per appointment.
Create a program that calculates the weekly pay for employees of "Pete's Pets", the total payroll and print's out a Weekly Pay Report.
You do not know the number of employees in the file in advance.
Each type of employee has its own pay code:
Managers have paycode 1
Clerks have code 2
Vets have code 3
Stylists have code 4
Input will come from a sequential file that has a line for each employee.
The first item in the line will always be the paycode.
The second and third item will be the first and last name.
The fourth item will be the employee ID.
For a paycode of 1, the salary will be the next item. If the pay code is 2, hourly salary is the next item followed by hours worked. If the pay code is 3, the next item will be the number of vaccines administered. If the pay code is 4, the next item will be the payrate per appointment followed by the number of appointments. All items in a line of the file are separated by a space.
You have been provided with the following classes:
Employee.h (simple class, no need for .cpp file). Implement the < and > operators. Use the employee number to determine > or <.
main.cpp (driver class)
test.cpp (this is used for the autograding)
testing.cpp (this is the one to run on the gl server and get a valgrind report on)
Requirements:
Implement 4 derived classes that inherit from Employee (these are your Data Element classes). An empty .h and .cpp file have been created for each of these.
(a) Manager -
(b) Clerk
(c) Stylist
(d) Vet
They will contain variables appropriate for the type of employee. They inherit from Employee and define the virtual method(s). There should also be getters for private members unique to each class, and any other methods that are needed for your design. The parameterized constructor should call the constructor of the Employee class with member initialization syntax. Provide a copy constructor. The toString method will override the Employee toString method and use the Employee::toString method within the implementation. Provide a destructor. Use const to represent any constants.
Assistant
Create a Data Manager class called Employees. You have been provided with the .h file and an empty .cpp file. It will contain a vector that holds pointers to Employee objects that will accommodate pointers to Manager, Clerk, Stylist and Vet objects. Add any other variables needed for your design including numManagers, numClerks, numStylist and numVets, which will be incremented when you add an Employee of this type. Employees will contain the following functions:
(a) void addEmployee(string). The string passed in will be one line from the input file. Use the paycode to determine what is to be extracted from the string. Create the correct type of object and add it to the vector.
(b) double calculateWeeklyPay(). Returns the sum of weekly pay for all objects in the vector.
(c) string printReport(). Returns a string with the Weekly Pay Report. The employees are sorted by employee number in the report. (The necessary methods and overloaded operators needed for the sort are provided for you.)The Employee Number and First and Last Names are printed in a column of width 25. The Weekly Pay is printed in a column of width 10. Total Payroll will be printed as well as the number of each type of employee. Look at the example output to see the details of the Weekly Pay Report. All pay must be printed with 2 decimal places.
(d) Rule of 3 - Copy constructor, Destructor, operator= . You will need the clone() for the copy constructor and =.
(e) Default constructor
Any additional functions you may need for your design must be private utility functions. **** Make sure any .h files you need for the derived classes are put in the Employees.h, not the Employees.cpp
main.cpp will read from the file and print out the report.
Given the following input file:
4 Paul Johnson 44444 8.75 75
1 Eric Hall 11111 1200.00
3 Katie Bell 33333 55
2 Patrick Brown 22222 12.50 50
The following report will be printed:
Weekly Pay Report for Pete's Pets
Employee Weekly Pay
11111 Eric Hall 1200.00
22222 Patrick Brown 687.50
33333 Katie Bell 1006.25
44444 Paul Johnson 656.25
Total payroll: 3550.00
Managers: 1
Clerks: 1
Vets: 1
Stylist: 1
Given the following file:
4 Paul Johnson 44444 8.75 75
2 Erica Smith 12345 8.75 35
1 Eric Hall 11111 1200.00
4 Paula Potter 34567 12.25 43
3 Katie Bell 33333 55
2 Patrick Brown 22222 12.50 50
3 Kelly Myers 23456 22
3 Karen Miller 45678 34
The following report will be printed:
Weekly Pay Report for Pete's Pets
Employee Weekly Pay
11111 Eric Hall 1200.00
12345 Erica Smith 306.25
22222 Patrick Brown 687.50
23456 Kelly Myers 882.50
33333 Katie Bell 1006.25
34567 Paula Potter 526.75
44444 Paul Johnson 656.25
45678 Karen Miller 927.50
Total payroll: 6193.00
Managers: 1
Clerks: 2
Vets: 3
Stylist: 2
You have been provided with two data files - employees.txt and employeesA.txt You have been provided with two testing files - tests.cpp is for the autograding and testing.cpp is the one to test your program on the gl server and run a valgrind report. A makefile is provided. "make driver" will run main.cpp. "make testing" will run all the tests and give you a score. "make testMemory" is for the gl server to find memory leaks. "make test" will run the tests that are used for the autograding.
this is a project i am working on i current have this
#pragma once
#include "Employee.h"
#include
#include
#include
using namespace std;
class Stylist : public Employee {
private:
double weeklySalary;
int aptNumber;
implemented does this seem correct t oyou? it currently passes all of myu test which are
#include "Employees.h"
#include "Employee.h"
#include "Manager.h"
#include "Clerk.h"
#include "Vet.h"
#include "Stylist.h"
#include
#include
#include
using namespace std;
void printResultsStr(int result, string expected="", string student=""){
if(result==0)
cout << "Passed this test\n\n";
else {
cout << "FAILED this test\n";
cout << "\nExpected result: \n"<<expected<<"\nYour result: \n"<<student<<endl;
}
}
void printResultsInt(int result, int expected, int student){
if(result==0)
cout << "Passed this test\n";
else {
cout << "FAILED this test\n";
cout << "\nExpected result: \n"<<expected<<"\nYour result: \n"<<student<<endl;
}
}
cout << "adding the following employees to Employees object employees;" << endl;
cout << "addEmployee(\"4 Paul Johnson 44444 8.75 75\")" << endl;
cout << "addEmployee(\"1 Eric Hall 11111 1200.00\")" << endl;
cout << "addEmployee(\"3 Katie Bell 33333 55\")" << endl;
cout << "addEmployee(\"2 Patrick Brown 22222 12.50 50\")" << endl;
employees.addEmployee("4 Paul Johnson 44444 8.75 75");
employees.addEmployee("1 Eric Hall 11111 1200.00");
employees.addEmployee("3 Katie Bell 33333 55");
employees.addEmployee("2 Patrick Brown 22222 12.50 50");
pay = employees.calculateWeeklyPay();
if (pay-3550.00 < .01) {
cout << "Total Weekly Pay of 3500.00 for employees was calculated correctly" << endl << endl;;
cout << "Using assignment operator: employees3 = employees" << endl;
employees3 = employees;
cout << "employees3.addEmployee(\"2 Georgia Jones 10111 13.50 40\")" << endl;
employees3.addEmployee("2 Georgia Jones 10111 13.50 40");
cout << "employees3.calculateWeeklyPay()" << endl;
pay3 = employees3.calculateWeeklyPay();
pay = employees.calculateWeeklyPay();
if (((pay3 - 4090.00) < .01) && ((pay - 3550.00) < .01)) {
cout << "Operator= working correctly, total Weekly Pay for employees3 = 4090.00\n"
"and total Weekly Pay for employees is still 3500.00" << endl;
returnResult = 0;
}
else {
expectedString = "Total Weekly Pay(employees3): 4090.00.\n";
expectedString += "Total Weekly Pay (employees): 3500.00\n";
student = "Total Weekly Pay(employees3): " + to_string(pay3);
student += "Total Weekly Pay (employees): " + to_string(pay);
return false;
}
}
else {
expectedString = "Total Weekly Pay: 3550.00.\n";
student = "Total Weekly Pay: " + to_string(pay);
}
printResultsStr(returnResult, expectedString, student);
return returnResult;
}
int testPassedPrintReportEmployee()
{
int returnResult = 1;
string expectedString = "";
string student = "";
Employees employees;
code
ifstream in;
string line;
string fileName = "employees.txt";
string result;
char result1[80];
int empNum;
double total;
in.open(fileName);
if (!in)
{
student = "Could not open file: " + fileName;
expectedString = "Opened file: " + fileName + "\n";
printResultsStr(returnResult, expectedString, student);
return 1;
}
// read a line and add to employees
while (!in.eof())
{
getline(in, line);
employees.addEmployee(line);
}
// report
istringstream inp(employees.printReport());
inp.getline(result1, 80, '\n'); //"Weekly Pay Report for Pete's Pets"
inp.getline(result1, 80, '\n'); // empty line
inp.getline(result1, 80, '\n'); //"Employee Weekly Pay"
inp >> empNum;
if (empNum != 11111)
{
expectedString = "First employee number should be 11111\n";
student = empNum;
}
else
{
inp.getline(result1, 80, '\n'); // get the rest of the line
inp >> empNum;
if (empNum != 22222)
{
expectedString = "Second employee number should be 22222\n";
student = empNum;
}
else
{
inp.getline(result1, 80, '\n'); // get the rest of the line
inp >> empNum;
if (empNum != 33333)
{
expectedString = "Third employee number should be 33333\n";
student = empNum;
}
else
{
inp.getline(result1, 80, '\n'); // get the rest of the line
inp >> empNum;
if (empNum != 44444)
{
expectedString = "Fourth employee number should be 44444\n";
student = empNum;
}
else
{
inp.getline(result1, 80, '\n'); // get the rest of the line
inp.getline(result1, 80, '\n'); // empty line
inp >> result; //"Total"
inp >> result; //"payroll"
inp >> total;
if (((total - 3550.00) > .01))
{
expectedString = "total: 3500.00\n";
student = "total: " + to_string(total);
}
else
{
inp >> result; //"Managers"
inp >> total;
if (total != 1)
{
expectedString = "Managers: 1\n";
student = "Managers: " + to_string(total);
}
else
{
inp >> result; //"Clerks"
inp >> total;
if (total != 1)
{
expectedString = "Clerks: 1\n";
student = "Clerks: " + to_string(total);
}
else
{
inp >> result; //"Vets"
inp >> total;
if (total != 1)
{
expectedString = "Vets: 1\n";
student = "Vets: " + to_string(total);
}
else
{
inp >> result; //"Sylist"
inp >> total;
if (total != 1)
{
expectedString = "Stylist: 1\n";
student = "Stylist: " + to_string(total);
}
else returnResult =0;
}
}
}
}
}
}
}
}
printResultsStr(returnResult, expectedString, student);
return returnResult;
}
int testPassedPrintReportEmployeeA()
{
int returnResult = 1;
string expectedString = "";
string student = "";
Employees employees;
code
ifstream in;
string line;
string fileName = "employeesA.txt";
string result;
char result1[80];
int empNum;
double total;
in.open(fileName);
if (!in)
{
student = "Could not open file: " + fileName;
expectedString = "Opened file: " + fileName + "\n";
printResultsStr(returnResult, expectedString, student);
return 1;
}
// read a line and add to employees
while (!in.eof())
{
getline(in, line);
employees.addEmployee(line);
}
// report
istringstream inp(employees.printReport());
inp.getline(result1, 80, '\n'); //"Weekly Pay Report for Pete's Pets"
inp.getline(result1, 80, '\n'); // empty line
inp.getline(result1, 80, '\n'); //"Employee Weekly Pay"
inp >> empNum;
if (empNum != 11111)
{
expectedString = "First employee number should be 11111\n";
student = empNum;
}
else
{
inp.getline(result1, 80, '\n'); // get the rest of the line
inp >> empNum;
if (empNum != 12345)
{
expectedString = "Second employee number should be 12345\n";
student = empNum;
}
else
{
inp.getline(result1, 80, '\n'); // get the rest of the line
inp >> empNum;
if (empNum != 22222)
{
expectedString = "Third employee number should be 22222\n";
student = empNum;
}
else
{
inp.getline(result1, 80, '\n'); // get the rest of the line
inp >> empNum;
if (empNum != 23456)
{
expectedString = "Fourth employee number should be 23456\n";
student = empNum;
}
else
{
inp.getline(result1, 80, '\n'); // get the rest of the line
inp >> empNum;
if (empNum != 33333)
{
expectedString = "Fifth employee number should be 33333\n";
student = empNum;
}
else
{
inp.getline(result1, 80, '\n'); // get the rest of the line
inp >> empNum;
if (empNum != 34567)
{
expectedString = "Sixth employee number should be 34567\n";
student = empNum;
}
else
{
inp.getline(result1, 80, '\n'); // get the rest of the line
inp >> empNum;
if (empNum != 44444)
{
expectedString = "Seventh employee number should be 44444\n";
student = empNum;
}
else
{
inp.getline(result1, 80, '\n'); // get the rest of the line
inp >> empNum;
if (empNum != 45678)
{
expectedString = "Eighth employee number should be 45678\n";
student = empNum;
}
else
{
inp.getline(result1, 80, '\n'); // get the rest of the line
inp.getline(result1, 80, '\n'); // empty line
inp >> result; //"Total"
inp >> result; //"payroll"
inp >> total;
if (((total - 6193.00) > .01))
{
expectedString = "The total should have been 6193.00\n";
student = to_string(total);
}
else
{
inp >> result; //"Managers"
inp >> total;
if (total != 1)
{
expectedString = "The number of Managers should have been 1\n";
student = to_string(total);
}
else
{
inp >> result; //"Clerks"
inp >> total;
if (total != 2)
{
expectedString = "The number of Clerks should have been 2\n";
student = to_string(total);
}
else
{
inp >> result; //"Vets"
inp >> total;
if (total != 3)
{
expectedString = "The number of Vets should have been 3\n";
student = to_string(total);
}
else
{
inp >> result; //"Sylist"
inp >> total;
if (total != 2)
{
expectedString = "The number of Stylist should have been 2\n";
student = to_string(total);
}
else
returnResult = 0;
}
}
}
}
}
}
}
}
}
}
}
}
printResultsStr(returnResult, expectedString, student);
return returnResult;
}
int main(int argc, char *argv[])
{
int passed = 1; // means fail
code
cout << "Test Name: " << argv[1] << endl;
if (strcmp(argv[1], "testPassedClerkNoOvertime") == 0)
{
passed = testPassedClerkNoOvertime();
}
else if (strcmp(argv[1], "testPassedClerkOvertime") == 0)
{
passed = testPassedClerkOvertime();
}
else if (strcmp(argv[1], "testPassedManager") == 0)
{
passed = testPassedManager();
}
else if (strcmp(argv[1], "testPassedVet") == 0)
{
passed = testPassedVet();
}
else if (strcmp(argv[1], "testPassedStylist") == 0)
{
passed = testPassedStylist();
}
else if (strcmp(argv[1], "testPassedCalcWeeklyPay") == 0)
{
passed = testPassedCalcWeeklyPay();
}
else if (strcmp(argv[1], "testPassedCopyconstructor") == 0)
{
passed = testPassedCopyconstructor();
}
else if (strcmp(argv[1], "testPassedEquals") == 0)
{
passed = testPassedEquals();
}
else if (strcmp(argv[1], "testPassedPrintReportEmployee") == 0)
{
passed = testPassedPrintReportEmployee();
}
else if (strcmp(argv[1], "testPassedPrintReportEmployeeA") == 0)
{
passed = testPassedPrintReportEmployeeA();
}
return passed; // if 0 then test passed
}
does each dervied class need a copy constructor ? cause reading the project description it seems like i do
Yes, each derived class should implement its own copy constructor. Here's why and how you can do it:
Why Implement Copy Constructors for Derived Classes?
Rule of Three Compliance:
In your Employees class, you're managing a collection of pointers to Employee objects. This involves dynamic memory management, which necessitates the Rule of Three: if you define a destructor, copy constructor, or copy assignment operator, you should define all three.
Polymorphic Behavior:
Since Employee is a base class with virtual functions, copying derived class objects properly ensures that the cloned objects retain their specific types and behaviors. The clone() method in each derived class typically relies on the copy constructor to create a copy of the object.
Deep Copy Requirements:
If your derived classes manage resources that require deep copying (e.g., dynamically allocated memory, file handles), explicit copy constructors ensure that each resource is correctly duplicated, preventing issues like double-free errors or memory leaks.
Project Specifications:
According to your project description, each derived class should provide a copy constructor, especially if they have unique member variables that need proper copying.
How to Implement Copy Constructors for Derived Classes
Below is a template for implementing copy constructors in your derived classes. I'll provide an example for the Manager class. You can follow a similar pattern for the other derived classes (Clerk, Vet, Stylist).
Each derived class’s copy constructor should call the base class (Employee) copy constructor to ensure that the base part of the object is correctly copied.
Clone Method:
Implementing the clone() method in each derived class is crucial for polymorphic copying. It typically uses the copy constructor to create a new instance.
Overriding Virtual Methods:
Ensure that all virtual methods (calcWeeklyPay, toString, clone) are correctly overridden in each derived class to reflect their unique behaviors.
Const-Correctness:
Mark methods like clone(), calcWeeklyPay(), and toString() as const to indicate that they do not modify the object’s state.
Destructor:
Although not strictly necessary in this case (since there are no dynamically allocated resources within the derived classes), providing a virtual destructor ensures that derived class destructors are called correctly when deleting objects via base class pointers.
Updating the Employees Class
Ensure that your Employees class properly utilizes the clone() method for deep copying. Here’s an example of how you might implement the copy constructor and assignment operator using clone():
Copy Constructors: Implemented in all derived classes.
Clone Method: Correctly overridden in all derived classes to use their respective copy constructors.
Rule of Three: Properly followed in the Employees class.
Memory Management: Ensured that all dynamically allocated memory is correctly managed to prevent leaks.
Testing: Continue running your tests to verify that each part works as expected. Ensure that deep copies are functioning correctly by verifying that modifying one instance does not affect another.
By following these guidelines, you'll ensure that your program behaves correctly, adheres to object-oriented principles, and meets the project requirements.