Question: C++ My code is below the question as well as my output. Below my code is how it should look. When I compile the code
C++
My code is below the question as well as my output. Below my code is how it should look. When I compile the code and run it I am only able to put in the name and then the program terminates.
- 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.
My code:
#include
using namespace std; class Employee { private: string employeeName; int employeeNumber; int hireDate; public: void setemployeeName(string employeeName); void setemployeeNumber(int); void sethireDate(int); string getemployeeName() const; int getemployeeNumber() const; int gethireDate() const; Employee(); }; void Employee::setemployeeName(string employeeName) { employeeName = employeeName; } void Employee::setemployeeNumber(int b) { employeeNumber = b; } void Employee::sethireDate(int d) { hireDate = d; } string Employee::getemployeeName() const { return employeeName; } int Employee::getemployeeNumber() const { return employeeNumber; } int Employee::gethireDate() const { return hireDate; } Employee::Employee() {
} class ProductionWorker :public Employee { private: int Shift; double hourlyPay; public: void setShift(int); void sethourlyPay(double); int getShift() const; double gethourlyPay() const; ProductionWorker(); }; void ProductionWorker::setShift(int s) { Shift = s; } void ProductionWorker::sethourlyPay(double p) { hourlyPay = p; } int ProductionWorker::getShift() const { return Shift; } double ProductionWorker::gethourlyPay() const { return hourlyPay; } ProductionWorker::ProductionWorker() {
} int main() { ProductionWorker info; string name; int num; int date; int shift; double pay; cout > name; cout > num; cout > date; cout > shift; cout > shift; cout > pay; info.setemployeeName(name); info.setemployeeNumber(num); info.sethireDate(date); info.setShift(shift); info.sethourlyPay(pay); cout
My output:

It should look like this and let me enter the information:

- 0 G C:\Users\chris\source repos\hw1Debug\hw7.exe Name: John Jones Employee number: Hire date: Shift: Shift number: Pay rate: The data you entered for this employee is as follows: Name: Employee Number: 0 Hire Date: -858993460 Shift: -858993460 Shift number: -858993460 Pay Rate: -92559631349317830736831783200707727132248687965119994463780864.00 Press any key to continue ... I CAUsers\davyn\Documents\courses_troy\l_2013\C++\Homework\student_work\Debug week8_sa... Name : John Jones Employee number: 123 Hire date: 1/1/2006 Shift: Night Shift number: 2 Pay rate: 18.00 Press any key to continue
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
