I have been working on this project for a while and need help understanding why I get the results I do.
First the display of the after compiling the code:
Enter the employee's name: Bob Green
Enter the employee's number: 112
Enter the date the employee was hired: 01091989
Enter the employee's shift where day shift = 1 and night shift = 2: 2
Enter the employee's pay rate in decimal format (0.00): 23.00
The employee's name is
The employee's number is -858993460
This employee was hired on -858993460
This worker has the Night shift and
makes $23 per hour
Press any key to continue . . .
Now the code I am using to get this result
Production h.
#ifndef PRODUCTIONWORKER_H
#define PRODUCTIONWORKER_H
#include "Employee.h"
#include <string>
class ProductionWorker : public Employee
{
private:
int shift;
double payRate;
public:
//Default constructor
ProductionWorker()
{ shift = 0;
payRate = 0.0; }
//Constructor
ProductionWorker(double p)
{ payRate = p; }
//Mutator functions
void setShift(int s)
{ shift = s; }
void setPayRate(double p)
{ payRate = p; }
//Accessor functions
string getNameShift();
};
#endif
Employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
using std::string;
//Employee class declaration
class Employee
{
private:
string employeeName;
int employeeNumber;
int hireDate;
public:
//Default constructor
Employee()
{ employeeName = ' ';
employeeNumber = 0;
hireDate = 0; }
//Constructor
Employee(std::string name, int number, int date)
{ set(name, number, date); }
//Mutator functions
void set(string, int, int);
//Accessor functions
string getEmployeeName() const
{ return employeeName; }
int getEmployeeNumber() const
{ return employeeNumber; }
int getHireDate() const
{ return hireDate; }
};
#endif
Main.cpp
#include <iostream>
#include <iomanip>
#include <string>
#include "Employee.h"
#include "ProductionWorker.h"
using namespace std;
using std::string;
int main()
{
string name;
int number;
int date;
int empShift = 0;
double empPayRate = 0.0;
//Create a ProductionWorker object
ProductionWorker stats;
//Get the employee's name
cout << "Enter the employee's name: ";
getline(cin,name);
//Get the employee's number
cout << "Enter the employee's number: ";
cin >> number;
//Get the date the employee was hired
cout << "Enter the date the employee was hired: ";
cin >> date;
//Get the employee's shift
cout << "Enter the employee's shift where day shift = 1 and night shift = 2: ";
cin >> empShift;
//Get the employee's pay rate
cout << "Enter the employee's pay rate in decimal format (0.00): ";
cin >> empPayRate;
//Store the employee's shift and pay rate into the stats object
stats.setShift(empShift);
stats.setPayRate(empPayRate);
//Define info object and initalize it with values entered
Employee info(name, number, date);
//Display the results
cout << "\nThe employee's name is " << info.getEmployeeName() << endl;
cout << "The employee's number is " << info.getEmployeeNumber() << endl;
cout << "This employee was hired on " << info.getHireDate() << endl;
cout << setprecision(3);
cout << "This worker has the " << stats.getNameShift() << " shift and" << endl;
cout << "makes $" << empPayRate << " per hour" << endl;
return 0;
}
Production.cpp
#include "ProductionWorker.h"
#include <string>
string ProductionWorker::getNameShift()
{
string nameShift;
if (shift == 1)
nameShift = "Day";
if (shift == 2)
nameShift = "Night";
return nameShift;
}
Empployee.cpp
#include "Employee.h"
#include <string>
void Employee::set(string name, int number, int date)
{
}
I am new to the C++ community so please help me understand why this is giving me the results I am getting.