#include #include #include #define TYPE_PROGRAMMER 1 #define TYPE_EMPLOYEE 2 using namespace std; int currentID; class Employee { public: Employee(); Employee(string name, string phoneNumber, int age, int gender, string jobTitle, int salary, int yearsWithCompany); int type; // Accessors int getID() { return id; } string getName() { return name; } string getPhoneNumber() { return phoneNumber; } int getPhoneNumberAsInt(); int getAge() { return age; } char getGender() { return gender; } string getJobTitle() { return jobTitle; } int getSalary() { return salary; } int getYearsWithCompany() { return yearsWithCompany; } // Programmer funcs virtual int getDepartment() { return -1; } virtual string getSupervisor() { return "NA"; } virtual float getLastSalaryIncrease() { return -1.0f; } virtual int getYearsOfExperience() { return -1; } virtual bool getJavaExperience() { return -1; } virtual bool getCppExperience() { return -1; } void setID( int id ) { this->id = id; } void setName( string name ) { this->name = name; } void setPhoneNumber( string phoneNumber ) { this->phoneNumber = phoneNumber; } void setAge( int age ) { this->age = age; } void setGender( char gender ) { this->gender = gender; } void setJobTitle( string jobTitle ) { this->jobTitle = jobTitle; } void setSalary( int salary ) { this->salary = salary; } void setYearsWithCompany( int yearsWithCompany) { this->yearsWithCompany = yearsWithCompany; } protected: int id; string name; string phoneNumber; int age; char gender; string jobTitle; int salary; int yearsWithCompany; }; Employee::Employee() { currentID++; id = currentID; name = "N/A"; phoneNumber = "000-000-0000"; age = -1; gender = 'M'; jobTitle = "N/A"; salary = -1; yearsWithCompany = -1; type = TYPE_EMPLOYEE; } Employee::Employee(string name, string phoneNumber, int age, int gender, string jobTitle, int salary, int yearsWithCompany) { currentID++; this->id = currentID; this->name = name; this->phoneNumber = phoneNumber; this->age = age; this->gender = gender; this->jobTitle = jobTitle; this->salary = salary; this->yearsWithCompany = yearsWithCompany; type = TYPE_EMPLOYEE; } int Employee::getPhoneNumberAsInt() { // Search the string for '-'s and delete them int charLoc = phoneNumber.find("-"); while( charLoc > 0) { phoneNumber = phoneNumber.replace(charLoc, 1, ""); charLoc = phoneNumber.find("-"); } return atoi(phoneNumber.c_str()); } class Programmer: public Employee { int dept; string supervisor; float lastSalaryIncrease; int yearsOfExp; bool JavaExp; bool CppExp; public: Programmer(); Programmer(string name, string phoneNumber, int age, int gender, string jobTitle, int salary, int yearsWithCompany, int dept, string supervisor, float lastSalaryIncrease, int yearsOfExp, bool JavaExp, bool CppExp); // Accesors int getDepartment() { return dept; } string getSupervisor() { return supervisor; } float getLastSalaryIncrease() { return lastSalaryIncrease; } int getYearsOfExperience() { return yearsOfExp; } bool getJavaExperience() { return JavaExp; } bool getCppExperience() { return CppExp; } void setDepartment( int dept ) { this->dept = dept; } void setSupervisor( string supervisor ) { this->supervisor = supervisor; } void setLastSalaryIncrease( float lastSalaryIncrease ) { this->lastSalaryIncrease = lastSalaryIncrease; } void setYearsOfExperience( int yearsOfExp ) { this->yearsOfExp = yearsOfExp; } void setJavaExperience( bool JavaExp ) { this->JavaExp = JavaExp; } void setCppExperience( bool CppExp ) { this->CppExp = CppExp; } }; Programmer::Programmer() { currentID++; this->id = currentID; dept = -1; string supervisor = "NoSupervisor"; lastSalaryIncrease = 0.0f; yearsOfExp = -1; JavaExp = false; CppExp = false; jobTitle = "Programmer"; type = TYPE_PROGRAMMER; } Programmer::Programmer(string name, string phoneNumber, int age, int gender, string jobTitle, int salary, int yearsWithCompany, int dept, string supervisor, float lastSalaryIncrease, int yearsOfExp, bool JavaExp, bool CppExp) { // Employee vars currentID++; id = currentID; this->name = name; this->phoneNumber = phoneNumber; this->age = age; this->gender = gender; this->jobTitle = jobTitle; this->salary = salary; this->yearsWithCompany = yearsWithCompany; // Unique Programmer vars this->dept = dept; this->supervisor = supervisor; this->lastSalaryIncrease = lastSalaryIncrease; this->yearsOfExp = yearsOfExp; this->JavaExp = JavaExp; this->CppExp = CppExp; type = TYPE_PROGRAMMER; } void ListEmployees(vector wrkrs) { for(int i = 0; i < wrkrs.size(); i++) { cout << "Employee: " << wrkrs[i]->getName().c_str() << endl; if(wrkrs[i]->type == TYPE_EMPLOYEE) cout << " Type: " << "Employee" << endl; else cout << " Type: " << "Programmer" << endl; cout << " - ID: " << wrkrs[i]->getID() << endl; cout << " - Phone Number: " << wrkrs[i]->getPhoneNumber().c_str() << endl; cout << " - Age: " << wrkrs[i]->getAge() << endl; cout << " - Gender: " << wrkrs[i]->getGender() << endl; cout << " - Job Title: " << wrkrs[i]->getJobTitle().c_str() << endl; cout << " - Salary: " << wrkrs[i]->getSalary() << endl; cout << " - Years With The Company: " << wrkrs[i]->getYearsWithCompany() << endl; cout << "\n\n-------------------------------------------------\n\n"; } } int main() { // Employee array vector workers; cout << "Employee DB\n By: Renato Ciuffo\n\n"; cout << " - Creating Employees..."; // Adding employee using default constructor, then manualy setting values. Employee newEmp; newEmp.setAge(21); newEmp.setGender('M'); newEmp.setJobTitle("QnA"); newEmp.setName("Joe Bob"); newEmp.setPhoneNumber("949-123-4567"); newEmp.setSalary(100000); newEmp.setYearsWithCompany(4); workers.push_back(&newEmp); // Adding employee using non-default constructor workers.push_back(new Employee("Johnathan Foo", "000-000-0000", 45, 'M', "Custodian", 20000, 2)); // Adding programmer using Employees default constructor and some unique Programmer funcs Programmer newProg; newProg.setAge(30); newProg.setGender('F'); newProg.setJobTitle("Customer Service"); newProg.setName("Joana Bob"); newProg.setPhoneNumber("949-000-0000"); newProg.setSalary(1000); newProg.setYearsWithCompany(1); newProg.setDepartment(43245); newProg.setSupervisor("Joe The Supervisor"); newProg.setYearsOfExperience(54); newProg.setLastSalaryIncrease( 0.001f ); newProg.setCppExperience(true); newProg.setJavaExperience(false); workers.push_back(&newProg); // Adding programmer using non-default constructor workers.push_back(new Programmer("Renato Ciuffo", "000-000-0001", 41, 'M', "Programmer", 9000000, 10, 1234, "Jack SuprVisor", 0.2f, 50, false, true )); cout << "done.\n\n\n"; cout << "Listing current employees...\n\n\n"; ListEmployees(workers); cout << "Done listing employees...\n"; cout << "Changing Last Name of one Employee...\n"; newEmp.setName("Jack NewNAme"); cout << "Changing Last Name of one Programmer...\n"; newProg.setName("Jack NewName"); cout << "Changing Department Number of one Programmer...\n\n\n\n"; newProg.setDepartment(999999); cout << "====================================================\n"; cout << "Finished making changes to user DB, Listing new Employee DB\n"; cout << "====================================================\n\n\n\n" << endl; ListEmployees(workers); cout << "\n\n\n Press 'Any' Key To Exit\n"; getchar(); return 1; }