Employee.h
#ifndef EMPLOYEE_H_
#define EMPLOYEE_H_
#include <string>
using std::string;
class Employee
{
private:
string empName; // Employee name
int empID; // Employee ID-number
string empHireDate; // Employee hire date
public:
// Default constructor
Employee()
{
empName = " ";
empID = 0;
empHireDate = " ";
}
// Parameterized constructor
Employee(string name, int number, string hireDate)
{
empName = name;
empID = number;
empHireDate = hireDate;
}
// Mutator functions
void setEmpName(string name)
{ empName = name; }
void setEmpID(int number)
{ empID = number; }
void setEmpHireDate(string hireDate)
{ empHireDate = hireDate; }
// Accessor functions
string getEmpName() const
{ return empName; }
int getEmpID() const
{ return empID; }
string getEmpDateHired() const
{ return empHireDate; }
};
#endif
ProductionWorker.h
#ifndef PRODUCTION_WORKER_H_
#define PRODUCTION_WORKER_H_
#include "Employee.h"
// ProductionWorker class derived from the Employee class
class ProductionWorker : public Employee
{
private:
int shiftNumber; // The shift number (1 = day, 2 = night)
double hourlyPayRate; // The hourly pay rate
public:
// Default constructor
ProductionWorker() : Employee()
{
shiftNumber = 0;
hourlyPayRate = 0.0;
}
// Parameterized Constructor - passes name, number and hireDate
// to the Employee base class
ProductionWorker(string name, int number, string hireDate, int shift, double payRate) :
Employee(name, number, hireDate)
{
shiftNumber = shift;
hourlyPayRate = payRate;
}
// Mutator functions
void setShift(int shift)
{ shiftNumber = shift; }
void setHourlyPayrate(double payRate)
{ hourlyPayRate = payRate; }
// Accessor functions
int getShift() const
{ return shiftNumber; }
double getHourlyPayRate() const
{ return hourlyPayRate; }
};
#endif
EmployeeProductionWorker.cpp
#include "ProductionWorker.h"
#include <iomanip>
using std::setprecision;
using std::setw;
#include <iostream>
using std::cin;
using std::cout;
using std::left;
using std::right;
using std::fixed;
void getEmployeeData(ProductionWorker &);
void outputData(const ProductionWorker &);
int main()
{
// Create a ProductionWorker object
ProductionWorker worker("Jane Moll", 938259, "05/04/1990", 1, 35.80);
// Create another ProductionWorker object
ProductionWorker workerOne;
// Get data for this worker
cout << "TAKEUCHI MANUFACTURING CO. - EMPLOYEE DATA ENTRY SYSTEM\n\n";
getEmployeeData(workerOne);
// Output data
cout << "\n\nTAKEUCHI MANUFACTURING CO. - EMPLOYEE DATABASE\n\n";
outputData(worker);
outputData(workerOne);
cout << "You are now leaving the Database System ...\n\n";
cout << "TAKEUCHI MANUFACTURING CO.\n"
<< "Unrivaled quality, products with a difference,\n"
<< "and fast development responding to the users' needs.";
cin.get();
cin.ignore();
return 0;
}
/* **********************************************************
getEmployeeData() : obj &
This function gets data for a production worker.
********************************************************** */
void getEmployeeData(ProductionWorker &worker)
{
string name = " ";
int number = 0;
string hireDate = " ";
int shift = 0;
double payRate = 0.0;
cout << "Enter employee name: ";
getline(cin, name);
worker.setEmpName(name);
cout << "Enter employee ID: ";
cin >> number;
worker.setEmpID(number);
cout << "Enter hire date (mm/dd/yyyy): ";
cin >> hireDate;
worker.setEmpHireDate(hireDate);
cout << "\nEnter shift (1: Day, 2: Night): ";
cin >> shift;
worker.setShift(shift);
cout << "Enter hourly pay rate: $ ";
cin >> payRate;
worker.setHourlyPayrate(payRate);
}
/* **********************************************************
outputData() : const obj &
This function outputs all data about a production worker.
********************************************************** */
void outputData(const ProductionWorker &worker)
{
cout << left << setw(12) << "Name: "
<< right << worker.getEmpName() << "\n"
<< left << setw(12) << "ID-Number: "
<< right << worker.getEmpID() << "\n"
<< left << setw(11) << "Date Hired: "
<< right << worker.getEmpDateHired() << "\n\n";
worker.getShift() == 1 ? cout << "Assigned Shift: Day\n" :
cout << "Assigned Shift: Night\n";
cout << fixed << setprecision(2);
cout << left << setw(12) << "Payrate: $ "
<< right << worker.getHourlyPayRate() << "\n\n";
}
No comments:
Post a Comment