1. Employee and ProductionWorker Classes Design a class named Employee. The clas
ID: 3915432 • Letter: 1
Question
1. Employee and ProductionWorker Classes Design a class named Employee. The class should keep the following information in • Employee name • Employee number • Hire date Write one or more constructors and the appropriate accessor and mutator functions for the class. Next, write a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have member variables to hold the following information: • Shift (an integer) • Hourly pay rate (a double ) The workday is divided into two shifts: day and night. The shift variable will hold an integer value representing the shift that the employee works. The day shift is shift 1, and the night shift is shift 2. Write one or more constructors and the appropriate accessor and mutator functions for the class. Demonstrate the classes by writing a program that uses a ProductionWorker object.
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class Employee{
private:
string employeeName;
string employeeNumber;
string hireDate;
public:
//default constructor
Employee(){
employeeName = " ";
employeeNumber = " ";
hireDate = " ";
}
Employee(string name, string num, string date){
employeeName = name;
employeeNumber = num;
hireDate = date;
}
//void setEmployeeName(string);
//void setEmployeeNumber(int);
//void setHireDate(string);
//string getEmployeeName();
//int getEmployeeNumber();
//string getHireDate();
void setEmployeeName(string eName){
employeeName = eName;
}
void setEmployeeNumber(string number){
employeeNumber = number;
}
void setHireDate(int hire){
hireDate = hire;
}
string getEmployeeName(){
return employeeName;
}
string getEmployeeNumber() {
return employeeNumber;
}
string getHireDate(){
return hireDate;
}
};
class ProductionWorker: public Employee {
private:
int shift;
double wage;
public:
ProductionWorker() : Employee() {
shift = 0;
wage = 0;
}
ProductionWorker(int hours, double pay){
shift = hours;
wage = pay;
}
void setShift(int hours){
shift = hours;
}
void setWage(int pay){
wage = pay;
}
int getShift(){
return shift;
}
double GetWage(){
return wage;
}
string getShiftType() const{
if (shift == 1)
return "Day";
else if (shift ==2)
return "Night";
}
void info(){
cout << "Name: " << getEmployeeName() << endl;
cout << "Number: " << getEmployeeNumber() << endl;
cout << "Hire Date: " << getHireDate() << endl;
cout << "Shift: " << getShift() << endl;
cout << "Shift type :" << getShiftType << endl;
return;
}
};
int main(){
ProductionWorker workerProduction("Bob", "111", "5/3/3", 1,1);
workerProduction.info();
return 0;
}
Here is what i have so far, but im running warnings i can't figure out. This program takes no input.
Thank you!
Explanation / Answer
--------------------------Code--------------------------
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class Employee{
private:
string employeeName;
string employeeNumber;
string hireDate;
public:
//default constructor
Employee(){
employeeName = " ";
employeeNumber = " ";
hireDate = " ";
}
Employee(string name, string num, string date){
employeeName = name;
employeeNumber = num;
hireDate = date;
}
//void setEmployeeName(string);
//void setEmployeeNumber(int);
//void setHireDate(string);
//string getEmployeeName();
//int getEmployeeNumber();
//string getHireDate();
void setEmployeeName(string eName){
employeeName = eName;
}
void setEmployeeNumber(string number){
employeeNumber = number;
}
void setHireDate(int hire){
hireDate = hire;
}
string getEmployeeName(){
return employeeName;
}
string getEmployeeNumber() {
return employeeNumber;
}
string getHireDate(){
return hireDate;
}
};
class ProductionWorker: public Employee {
private:
int shift;
double wage;
public:
ProductionWorker() : Employee() {
shift = 0;
wage = 0;
}
ProductionWorker(string name, string num, string date,int hours, double pay):Employee(name,num,date){
shift = hours;
wage = pay;
}
ProductionWorker(int hours, double pay){
shift = hours;
wage = pay;
}
void setShift(int hours){
shift = hours;
}
void setWage(int pay){
wage = pay;
}
int getShift(){
return shift;
}
double GetWage(){
return wage;
}
string getShiftType() const{
if (shift == 1)
return "Day";
else if (shift ==2)
return "Night";
}
void info(){
cout << "Name: " << getEmployeeName() << endl;
cout << "Number: " << getEmployeeNumber() << endl;
cout << "Hire Date: " << getHireDate() << endl;
cout << "Shift: " << getShift() << endl;
cout << "Shift type :" << getShiftType() << endl;
return;
}
};
int main(){
ProductionWorker workerProduction("Bob", "111", "5/3/3", 1,1);
workerProduction.info();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.