Nov 17, 2013 at 8:28pm UTC
the code works fine for the most part, it just asks for health, life, and vacation before the rest of employee info, but it does display it in the proper spot afterwards.
so if someone could help me with getting it to ask the employee info first the the benefits, that would be amazing.
P.S. i am very novice beginner.
[code]
#include <iostream>
#include <stdlib.h>
#include <string>
#include <iomanip>
using namespace std;
// ========== Non-class Methods ==========
void displayDivider(string outputTitle)
{
cout << "**************** " + outputTitle + " ****************" << endl;
}
// ========== Class ==========
class benefit
{
private:
string healthInsurance;
double lifeInsurance;
int vacationDays;
public:
benefit();
benefit(string health, double life, int vacation);
void displayBenefit();
string getHealthInsurance();
void setHealthInsurance(string healthIns);
double getLifeInsurance();
void setLifeInsurance(double lifeIns);
int getVacationDays();
void setVacationDays(int vacation);
void BenefitInput(); // earl
}; // class benefit
benefit::benefit(string health, double life, int vacation)
{
healthInsurance = health;
lifeInsurance = life;
vacationDays = vacation;
}
string benefit::getHealthInsurance()
{
return healthInsurance;
}
void benefit::setHealthInsurance(string healthIns)
{
healthInsurance = healthIns;
}
double benefit::getLifeInsurance()
{
return lifeInsurance;
}
void benefit::setLifeInsurance(double lifeIns)
{
lifeInsurance = lifeIns;
}
int benefit::getVacationDays()
{
return vacationDays;
}
void benefit::setVacationDays(int vacation)
{
vacationDays = vacation;
}
void benefit::displayBenefit()
{
cout << "Health Insurance Company: " << healthInsurance << endl;
cout << "Life Insurance Amount: " << lifeInsurance << endl;
cout << "Vacation Days: " << vacationDays << " days" << endl;
}
benefit::benefit()
{
cout << "Please Enter Health Insurance Company: ";
cin >> healthInsurance;
cout << "Please Enter the Life Insurance Amount: ";
cin >> lifeInsurance;
cout << "Please Enter the Amount of Vacation Days: ";
cin >> vacationDays;
} // benefit::benefit()
// ========== Class ==========
class iEmployee abstract
{
public:
virtual double calculatePay() = 0;
}; // class iEmployee
// ========== Class ==========
class Employee : public iEmployee
{
private:
string firstName;
string lastName;
char gender;
int dependents;
double annualSalary;
benefit Benefit;
public:
Employee();
Employee(string first, string last, char gen, int dep, double salary);
double calculatePay();
void displayEmployee();
string getFirstName();
void setFirstName(string first);
string getLastName();
void setLastName(string last);
char getGender();
void setgender(char gen);
int getDependents();
void setDependents(int dep);
void setDependents(string dep);
double getAnnualSalary();
void setAnnualSalary(double salary);
void setAnnualSalary(string salary);
static int getNumEmployees();
static int numEmployees;
}; // class Employee
Employee::Employee()
{
firstName = "Not Given";
lastName = "Not Given";
gender = 'U';
dependents = 0;
annualSalary = 20000;
cout << "Please Enter The Employee's First Name: ";
cin >> firstName;
cout << "Please Enter The Employee's Last Name: ";
cin >> lastName;
cout << "Please Enter The Employee's Gender: ";
cin >> gender;
if (gender == 'M' || gender == 'm')
gender = 'M';
else if (gender == 'F' || gender == 'f')
gender = 'F';
else
gender = 'U';
cout << "Please Enter The Employee's Dependent Count: ";
cin >> dependents;
cout << "Please Enter The Employee's Yearly Salary: ";
cin >> annualSalary;
} // Employee::Employee()
Employee::Employee(string first, string last, char gen, int dep, double salary)
{
firstName = first;
lastName = last;
gender = gen;
dependents = dep;
annualSalary = salary;
}
string Employee::getFirstName()
{
return firstName;
}
void Employee::setFirstName(string first)
{
firstName = first;
}
string Employee::getLastName()
{
return lastName;
}
void Employee::setLastName(string last)
{
lastName = last;
}
char Employee::getGender()
{
return gender;
}
void Employee::setgender(char gen)
{
gender = gen;
}
int Employee::getDependents()
{
return dependents;
}
void Employee::setDependents(int dep)
{
dependents = dep;
}
void Employee::setDependents(string dep)
{
dependents = atoi(dep.c_str());
}
double Employee::getAnnualSalary()
{
return annualSalary;
}
void Employee::setAnnualSalary(double salary)
{
annualSalary = salary;
}
void Employee::setAnnualSalary(string salary)
{
annualSalary = atof(salary.c_str());
}
double Employee::calculatePay()
{
return annualSalary / 52;
}
int Employee::getNumEmployees()
{
return numEmployees;
}
void Employee::displayEmployee()
{
cout << endl;
cout << "________________________________________________________________________________" << endl;
cout << "Employee Information" << endl;
cout << "________________________________________________________________________________" << endl;
cout << endl;
cout << "First Name: " << firstName << endl;
cout << "Last Name: " << lastName << endl;
cout << "Gender: " << gender << endl;
cout << "Dependent(s): " << dependents << endl;
cout << "Annual Salary: " << setprecision(2) << showpoint << fixed << annualSalary << endl;
cout << "Weekly Pay: " << calculatePay() << endl;
cout << endl;
cout << "________________________________________________________________________________" << endl;
cout << "Benefit Information" << endl;
cout << "________________________________________________________________________________" << endl;
Benefit.displayBenefit();
cout << endl;
}
int Employee::numEmployees = 0;
// ========== Main ==========
int main()
{
int numEmpl;
cout << "Welcome to your first Object Oriented Programming -- Employee ClassCIS247C, Week 4 Lab" << endl;
cout << "NAME: Kris Bazant" << endl;
cout << endl;
displayDivider("Employee One");
cout << endl;
Employee one;
Employee::numEmployees++;
one.displayEmployee();
numEmpl = Employee::getNumEmployees();
cout << "--- Number Of Employee Object Created ---" << endl;
cout << "Number Of Employees: " << numEmpl << endl;
cout << endl;
displayDivider("Employee Two");
Employee two("Mary", "Noia", 'F', 5, 24000.00);
Employee::numEmployees++;
two.displayEmployee();
numEmpl = Employee::getNumEmployees();
cout << "--- Number Of Employee Object Created ---" << endl;
cout << "Number Of Employees: " << numEmpl << endl;
cout << "The end of the CIS 247C Week 4 iLab." << endl;
system("pause");
return 0;
} // main()
Last edited on Nov 18, 2013 at 5:41pm UTC