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

Python program assignment Write an Employee class that keeps data attributes for

ID: 3872280 • Letter: P

Question

Python program assignment

Write an Employee class that keeps data attributes for the following pieces of information:

Employee Name

Employee Number

Next, write a   class named ProductionWorker that is    a   subclass of the Employee class.

The ProductionWorker class should keep data attributes for the following information:

Shift Number (an integer 1   or 2)

Hourly Pay Rate

The workday is divided into two shifts: day and night. The shift attribute 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 the appropriate accessor and mutator methods for each class.

Once you have written the classes, write a   program that creates an object of the ProductionWorker class and prompts the user to enter data for each of the object’s data attributes. Store the data in the object and then use the object’s accessor methods to retrieve it   and display it on the screen.

Add an __str__ method to the ProductionWorker class that will print the attributes from both classes in a readable format. In the main part of the program, create one more ProductionWorker object, assign values to the attributes and print both objects using the print statement.

Explanation / Answer

Employee class:

#include "stdafx.h"

#include<iostream>

#include<string>

using namespace std;

class Employee

{

int empNumber;

char empName[20];

class date

{

int day;

int month;

int year;

string hireDate;

public:

void date:: setDate()

{

cout << "Enter the date: DAY MONTH YEAR " << endl;

cin >> day >> month >> year;

}

string date:: getDate()

{

hireDate=day+'-'+month+'-'+year;

return hireDate;

}

};

date hire_date;

public:

void getEmpDetails();

void displayEmpDetails();

virtual double pay();

};

void Employee::getEmpDetails()

{

cout << " Enter Employee Number:" << endl;

cin >> empNumber;

cout << " Enter Employee Name: " << endl;

cin >> empName;

cout << " Enter Employee hiring date: " << endl;

}

void Employee :: displayEmpDetails()

{

cout<<" Employee Name : "<<empName;

cout<<" Employee number : "<<empNumber;

cout<<" Employee hiring date: "<< hire_date.getDate();

}

class ProductionWorker: public Employee

{

private:

double hourlyPay;

enum shift{day=1,night=2};

shift shft;

public:

void setShift()

{

shift shft=day;

switch(shft)

{

case day: cout << "Shift is 1"; break;

case night: cout << "Shift is 2"; break;

}

}

void setPay()

{

double temp = 0;

do

{

cout << "Please enter your hourly pay: ";

cin >> temp;

if (hourlyPay < 0)

cout << "Invalid Pay";

} while (temp < 0);

hourlyPay = temp;

}

double pay()

{

return hourlyPay;

}

void EmpWorkDetails()

{

cout << "Employee shift is " << shft << "and hourly pay is: " << hourlyPay;

}

};

int main()

{

ProductionWorker pwkr;

pwkr.getEmpDetails();

pwkr.setShift();

pwkr.setPay();

pwkr.getEmpDetails();

pwkr.displayEmpDetails();

system("pause");

return 0;

}