Hi everyone, my assignment for this week has me stumped once again. I have several questions and problems with my code that I could really use some help with. Not looking for the answers, an explanation using my code or code in general would be great so I can learn where I am going wrong.
The main issue I'm having is being able to use my Benefits class correctly. With it being protected I can't access it the way I have it yet. Another is how to properly inherit the employee class variables to the other classes.
This program is supposed to create at least one Employee, Hourly, and Salaried employee.
For each object created, display the number of employees created.
For each object created, write statements to exercise each of the public methods listed in the Class diagram.
For each object created, invoke the object's displayEmployee() method to display the employee's information.
As you can see, I made seperate .h and .cpp files for all the classes, thought it would make it easier, not sure if I accomplished that.
Any suggestions? Thanks in advance.
Main CPP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
// Preprocessor Directives
#include "stdafx.h"
#include "Employee.h"
#include "Hourly.h"
#include "Salaried.h"
#include <iostream>
#include <string>
using namespace std;
//----------------------------------------------------------------------------------------------
// Main Function
int main()
{
// Call DisplayApplicationInformation and DisplayDivider Proceedures
DislayApplicationInformation();
DisplayDivider("Employee 1");
// Construct Employee1 Object and Benefit Object
Employee employee1;
char gender;
string tempString;
Benefit benefit;
double lifeInsurance;
int vacation;
// Getting Employee1 Data
employee1.setFirstName(GetInput("First Name "));
employee1.setLastName(GetInput("Last Name "));
tempString = GetInput("Gender ");
gender = tempString.at(0);
employee1.setGender(gender);
employee1.setDependents(GetInput("Dependents "));
employee1.setAnnualSalary(GetInput("Annual Salary "));
// Get Employee1 Benefit Data
//employee1.benefit.setHealthInsurance(GetInput("Health Insurance "));
tempString = GetInput("Life Insurance");
lifeInsurance = atof(tempString.c_str());
//employee1.benefit.setLifeInsurance(lifeInsurance);
tempString = GetInput("Vacation ");
vacation = atoi(tempString.c_str());
//employee1.benefit.setVacation(vacation);
// Calling DisplayDivider2 and DisplayEmployee Proceedures for Employee 1
DisplayDivider2("Employee Information");
employee1.displayEmployee(); //Display Employee1 Data
cout << endl;
// Construct Hourly Employee and Benefit1 Objects
Benefit hourlyBenefit;
Hourly employee2;
double wage;
double hours;
string category;
// Get Hourly Employee Data
employee2.setFirstName(GetInput("First Name "));
employee2.setLastName(GetInput("Last Name "));
tempString = GetInput("Gender ");
gender = tempString.at(0);
employee2.setGender(gender);
employee2.setDependents(GetInput("Dependents "));
employee2.setCategory(GetInput("Category "));
tempString = GetInput("Wage ");
wage = atoi(tempString.c_str());
employee2.setWage(wage);
tempString = GetInput("Hours: ");
hours = atoi(tempString.c_str());
employee2.setHours(hours);
// Get Hourly Employee Benefit Data
//employee2.hourlyBenefit.setHealthInsurance(GetInput("Health Insurance "));
tempString = GetInput("Life Insurance");
lifeInsurance = atof(tempString.c_str());
//employee2.hourlyBenefit.setLifeInsurance(lifeInsurance);
tempString = GetInput("Vacation ");
vacation = atoi(tempString.c_str());
//employee2.hourlyBenefit.setVacation(vacation);
// Calling DisplayDivider, DisplayDivider2 and DisplayEmployee Proceedures for Employee 2
DisplayDivider("Employee 2");
DisplayDivider2("Employee Information");
employee2.displayEmployee(); //
// Construct Salaried Employee and Benefit2 Objects
Benefit SalariedBenefit;
Salaried employee3;
int managementLevel;
// Get Salaried Employee Data
employee3.setFirstName(GetInput("First Name "));
employee3.setLastName(GetInput("Last Name "));
tempString = GetInput("Gender ");
gender = tempString.at(0);
employee3.setGender(gender);
employee3.setDependents(GetInput("Dependents "));
employee3.setAnnualSalary(GetInput("Annual Salary "));
tempString = GetInput("Management Level ");
managementLevel = atoi(tempString.c_str());
employee3.setManagementLevel(managementLevel);
// Get Salaried Employee Benefit Data
//employee3.salariedBenefit.setHealthInsurance(GetInput("Health Insurance "));
tempString = GetInput("Life Insurance");
lifeInsurance = atof(tempString.c_str());
//employee3.salariedBenefit.setLifeInsurance(lifeInsurance);
tempString = GetInput("Vacation ");
vacation = atoi(tempString.c_str());
//employee3.salariedBenefit.setVacation(vacation);
// Calling DisplayDivider, DisplayDivider2 and DisplayEmployee Proceedures for Employee 3
DisplayDivider("Employee 3");
DisplayDivider2("Employee Information");
employee3.displayEmployee();
// Call TerminateApplication Proceedure
TerminateApplication();
return 0;
}
//----------------------------------------------------------------------------------------------
// DisplayApplicationInformation Procedure
void DislayApplicationInformation()
{
// Display Program Header
cout << "Welcome to your first Object Oriented Program\n";
cout << "Employee Class CIS247C, Week 4 Lab\n";
cout << "Name: Jim Stevens\n";
}
//----------------------------------------------------------------------------------------------
// DisplayDivider Prodedure
void DisplayDivider(string outputTitle)
{
// Display Divider with Output Title
cout << "************************" << outputTitle <<"************************\n";
}
//----------------------------------------------------------------------------------------------
// DisplayDivider2 Prodedure
void DisplayDivider2(string outputTitle)
{
// Display Divider with Output Title
cout << "\n" << outputTitle << endl;
cout << "----------------------------------------------------------------\n";
}
//----------------------------------------------------------------------------------------------
// GetInput Function
string GetInput (string inputType)
{
// Declare Function Varaible
string input;
// Prompt User for Input
cout<<"Please enter your "<< inputType <<": ";
getline(cin, input);
return input;
}
//----------------------------------------------------------------------------------------------
// TerminateApplication Procedure
void TerminateApplication()
{
// Display Termination Message
cout << "\nThank you for using the Employee Class program\n";
}
//----------------------------------------------------------------------------------------------
|