Skip to content

Instantly share code, notes, and snippets.

@shade34321
Created February 18, 2013 02:26
Show Gist options
  • Save shade34321/4974779 to your computer and use it in GitHub Desktop.
Save shade34321/4974779 to your computer and use it in GitHub Desktop.
//
// Employee.cpp
// Week_06_Exception_Project
//
// Created by Shade Alabsa on 2/17/13.
// Copyright (c) 2013 Shade Alabsa. All rights reserved.
//
#include "Employee.h"
using namespace std;
void Employee::setName(string n){
name = n;
}
void Employee::setHireDate(string hd){
hireDate = hd;
}
void Employee::setNumber(int n){
if(n>=0 && n <=9999){
number = n;
}
else
throw InvalidEmployeeNumber();
}
// Specification file for the Employee class
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
using namespace std;
class Employee
{
private:
string name; // Employee name
int number; // Employee number
string hireDate; // Hire date
public:
// Default constructor
Employee()
{ name = ""; number = 0; hireDate = ""; }
// Constructor
Employee(string aName, int aNumber, string aDate)
{ name = aName; number = aNumber; hireDate = aDate; }
// Mutators
void setName(string);
void setNumber(int);
void setHireDate(string);
// Accessors
string getName() const
{ return name; }
int getNumber() const
{ return number; }
string getHireDate() const
{ return hireDate; }
class InvalidEmployeeNumber{}; //empty class declaration so we can do the exceptions
};
#endif
Undefined symbols for architecture x86_64:
"ProductionWorker::setPayRate(double)", referenced from:
_main in ccJJTQuc.o
"ProductionWorker::setShift(int)", referenced from:
_main in ccJJTQuc.o
"Employee::setHireDate(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)", referenced from:
_main in ccJJTQuc.o
"Employee::setName(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)", referenced from:
_main in ccJJTQuc.o
"Employee::setNumber(int)", referenced from:
_main in ccJJTQuc.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
//
// main.cpp
// Week_06_Exception_Project
//
// Created by Shade Alabsa on 2/17/13.
// Copyright (c) 2013 Shade Alabsa. All rights reserved.
//
#include <iostream>
#include <iomanip>
#include <string>
#include "Employee.h"
#include "ProductionWorker.h"
#include "Employee.h"
using namespace std;
void displayInfo(ProductionWorker);
int main()
{
string name, shift, hireDate;
int shiftNumber,employeeNumber;
double payRate;
ProductionWorker worker, worker2;
name = "John Jones";
employeeNumber = 123;
hireDate = "1/1/2006";
shiftNumber = 2;
payRate = 18.00;
try{
worker.setName(name);
worker.setNumber(employeeNumber);
worker.setHireDate(hireDate);
worker.setShift(shiftNumber);
worker.setPayRate(payRate);
displayInfo(worker);
}
catch(Employee::InvalidEmployeeNumber){
cout << "Error: An invalid employee number was entered." << endl;
}
catch(ProductionWorker::InvalidShift){
cout << "Error: An invalid shift was entered." << endl;
}
catch(ProductionWorker::InvalidPayRate){
cout << "Error: An invalid pay rate was entered." << endl;
}
name = "John Jones";
employeeNumber = 1;
hireDate = "1/1/2006";
shiftNumber = 2;
payRate = -18.00;
try{
worker2.setName(name);
worker2.setNumber(employeeNumber);
worker2.setHireDate(hireDate);
worker2.setShift(shiftNumber);
worker2.setPayRate(payRate);
displayInfo(worker2);
}
catch(Employee::InvalidEmployeeNumber){
cout << "Error: An invalid employee number was entered." << endl;
}
catch(ProductionWorker::InvalidShift){
cout << "Error: An invalid shift was entered." << endl;
}
catch(ProductionWorker::InvalidPayRate){
cout << "Error: An invalid pay rate was entered." << endl;
}
return 0;
}
//******************************************************
// The displayInfo function displays a production *
// worker's employment information. *
//******************************************************
void displayInfo(ProductionWorker e)
{
cout << setprecision(2) << fixed << showpoint;
cout << "Name: "
<< e.getName() << endl;
cout << "Employee number: "
<< e.getNumber() << endl;
cout << "Hire date: "
<< e.getHireDate() << endl;
cout << "Shift: "
<< e.getShiftName() << endl;
cout << "Shift number: "
<< e.getShiftNumber() << endl;
cout << "Pay rate: "
<< e.getPayRate() << endl;
}
//
// ProductionWorker.cpp
// Week_06_Exception_Project
//
// Created by Shade Alabsa on 2/17/13.
// Copyright (c) 2013 Shade Alabsa. All rights reserved.
//
#include "ProductionWorker.h"
using namespace std;
void ProductionWorker::setShift(int s){
if(s == 1 || s == 2){
shift = s;
}
else
throw InvalidShift();
}
void ProductionWorker::setPayRate(double pay){
if(pay > 0){
payRate = pay;
}
else
throw InvalidPayRate();
}
// Specification file for the ProductionWorker Class
#ifndef PRODUCTION_WORKER_H
#define PRODUCTION_WORKER_H
#include "Employee.h"
#include <string>
using namespace std;
class ProductionWorker : public Employee
{
private:
int shift; // The worker's shift
double payRate; // The worker's hourly pay rate
public:
// Default constructor
ProductionWorker() : Employee()
{ shift = 0; payRate = 0.0; }
// Constructor
ProductionWorker(string aName, int aNumber, string aDate,
int aShift, double aPayRate) : Employee(aName, aNumber, aDate)
{ shift = aShift; payRate = aPayRate; }
// Mutators
void setShift(int);
void setPayRate(double);
// Accessors
int getShiftNumber() const
{ return shift; }
string getShiftName() const
{ if (shift == 1)
return "Day";
else if (shift == 2)
return "Night";
else
return "Invalid";
}
double getPayRate() const
{ return payRate; }
class InvalidShift{};
class InvalidPayRate{};
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment