Question
//Employee.h #ifndef EMPLOYEE_H #define EMPLOYEE_H #include #include using namespace std; class Employee { private: static int lastEmployeeNumberIssued; // Sequential employee number int employeeNumber; // Employee
//Employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include
#include
using namespace std;
class Employee
{
private:
static int lastEmployeeNumberIssued; // Sequential employee number
int employeeNumber; // Employee number for current employee
string employeeName; // Employee name
string hireDate; // Hire date
public:
// Constructors
Employee();
Employee(string aName, string aDate);
// Mutators
void setEmployeeName(string n);
void setHireDate(string date);
// Accessors
string getEmployeeName() const;
int getEmployeeNumber() const;
string getHireDate() const;
static int getLastEmployeeNumberIssued();
bool isValidDate(string);
};
class inValidHireDate : public exception {
public:
virtual const char*what() const throw() {
return " Invalid date";
}
};
#endif
//Employee.cpp
#include "Employee.h"
#include
#include
using namespace std;
int Employee::lastEmployeeNumberIssued=0; // Sequential employee number
// Default constructor
Employee::Employee()
{
lastEmployeeNumberIssued++;
employeeNumber = lastEmployeeNumberIssued;
employeeName = "";
hireDate = "";
}
// Constructor
Employee::Employee(string aName, string aDate)
{
if (!isValidDate(aDate)) {
throw InvalidHireDate();
}
lastEmployeeNumberIssued++;
employeeNumber = lastEmployeeNumberIssued;
employeeName = aName;
hireDate = aDate;
}
// Mutators
void Employee::setEmployeeName(string n)
{
employeeName = n;
}
void Employee::setHireDate(string date)
{
if (!isValidDate(aDate)) {
throw InvalidHireDate();
}
hireDate = date;
}
// Accessors
string Employee::getEmployeeName() const
{
return employeeName;
}
int Employee::getEmployeeNumber() const
{
return employeeNumber;
}
string Employee::getHireDate() const
{
return hireDate;
}
int Employee::getLastEmployeeNumberIssued()
{
return lastEmployeeNumberIssued;
}
bool Employee::isValidDate(string date) {
if (date.length() == 10) {
if (date[2] == '/' && date[5] == '/') {
for (int i = 0; i
if (i != 2 && i != 5) {//checking if all digits in other indices are digits
if (!isdigit(date[i])) {/ot a digit
return false;
}
}
}
return true;
}
}
return false;
}
//ProductionWorker.h
#ifndef PRODUCTION_WORKER_H
#define PRODUCTION_WORKER_H
#include
#include
#include
#include "Employee.h"
using namespace std;
class ProductionWorker : public Employee
{
private:
int shift;
double payRate;
public:
//Default constructor
ProductionWorker() : Employee() {
shift = 0;
payRate = 0.0;
}
//Constructor
ProductionWorker(string name, string aDate, int aShift, double aPayRate) : Employee(aName, aDate) {
shift = aShift;
payRate = aPayRate;
}
//Mutators
void setShift(int s);
void setPayRate(double r);
static ProductionWorker*createNewProductionWorker();
//Accessors
int getShiftNumber() const;
string getShiftName() const;
double getPayRate() const;
void printWorkerData() const;
void displayInfo(ProductionWorker e);
};
#endif // !PRODUCTION_WORKER_H
//ProductionWorker.cpp
#include "ProductionWorker.h"
void ProductionWorker::setShift(int shift)
{
this->shift = shift;
}
void ProductionWorker::setHourlyPayRate(double rate)
{
hourlyPayRate = rate;
}
ProductionWorker::ProductionWorker() {
shift = 1;
hourlyPayRate = 0.0;
}
ProductionWorker::ProductionWorker(int shift, double rate) {
this->shift = shift;
hourlyPayRate = rate;
}
//Main function
#include "Employee.h"
#include"ProductionWorker.h"
#include
#include
using namespace std;
int main()
{
bool quit = false;
char command;
string name, date;
int shift, numEmployees = 0;
double rate;
ProductionWorker newEmployees[100];
while (!quit)
{
cout
cin >> command;
cin.ignore(80, ' ');
switch (command)
{
case 'c':
cout
getline(cin, name);
cout
getline(cin, date);
cout
cin >> shift;
cout
cin >> rate;
newEmployees[numEmployees].setEmployeeName(name);
newEmployees[numEmployees].setHireDate(date);
newEmployees[numEmployees].setHourlyPayRate(rate);
newEmployees[numEmployees].setShift(shift);
break;
case 'h':
cout
break;
case'p':
cout
numEmployees++;
break;
case 'q':
quit = true;
break;
default:
cout
}
}
return 0;
}
Employee Class Modify the Employee class: .Add an exception class: InvalidHireDate Add code to the Employee class to check if hire date string object fits the MM/DD/YYYY numeric format. One easy way to accomplish this is to use the "square brackets" operator [ ])to access individual characters in the hire date string: 1. The hire date string should have a length of 10 2. The characters at index 2 and index 5 should be a forward-slash character/). 3. The characters at index 0,1,3,4, 6,7, 8, and 9 should be in the range of 0. .9. (Refer to the isdigit () function in the cctype function library. You may need to add a #include
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