The goal is to turn the employee class into an abstract class. ok i've posted the assingment and the pseudocode for it.
Define class – Employee (Abstract Class)
private access specifier
// declare data members
numEmployees as a static integer value of 0
protected access specifier
firstName as a string
lastName as a string
gender as a character
dependents as an integer
annualSalary as a double
benefit as a Benefit class composite object
public access specifier
default constructor Employee()
constructor with parameters Employee(string, string, char, int, double, string,
double, int)
constructor with parameters Employee(string, string, char, int, double, Benefits)
declaration calculatePay() as a pure virtual function
declaration displayEmployee() as a pure virtual function
declaration getFirstName()
declaration setFirstName(string)
declaration getLastName()
declaration setLastName(string)
declaration getGender()
declaration setGender(char)
declaration getDependents()
declaration setDependents(int)
declaration getAnnualSalary()
declaration setAnnualSalary(double)
declaration static getNumEmployees()
declaration setDependents(string)
declaration setAnnualSalary(string)
declaration setBenefits(Benefits)
declaration getBenefits() returns a Benefits object
end define class
below is the program i wrote, however i need to turn it to abstract class thank you for your help. here is my code.
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 163 164 165 166 167 168 169 170 171 172
|
//Employee class creation
class Employee
{
static int numEmployees;
protected:
string firstName;
string lastName;
char gender;
int dependents;
double annualSalary;
//declaring a benefits object
Benefit benefits;
public:
Employee():benefits() // Default constructor created
{
firstName = "";
lastName = "";
gender = 'N';
dependents = 0;
annualSalary = 50000;
//static int numEmployees = 0;
//each time the aconstructor is called, it increment the class level numEmployees variable
this->numEmployees += 1;
}// end of default constructor
Employee(string firstName, string lastName, char gender, int dependents, double salary, Benefit mybenefits):benefits(mybenefits)
{
//This is use to distinguish between the class attributes and the parameter
this->firstName = firstName;
this->lastName = lastName;
this->gender = gender;
this->dependents = dependents;
this->annualSalary = salary;
//each time the aconstructor is called, it increment the class level numEmployees variable
this->numEmployees += 1;
}
Employee(string firstName, string lastName, char gender, int dependents, Benefit mybenefits):benefits(mybenefits)
{
//This is use to distinguish between the class attributes and the parameter
this->firstName = firstName;
this->lastName = lastName;
this->gender = gender;
this->dependents = dependents;
//each time the aconstructor is called, it increment the class level numEmployees variable
this->numEmployees += 1;
}
//creating the set and get method for the benefit object
Benefit getBenefits()
{
return benefits;
}
void setBenefits(Benefit benefits)
{
this->benefits = benefits;
}
//Display the number of employees been created
static int getNumberEmployees()
{
return numEmployees;
}
//Setters and Getters for each class attributes
string getFirstName()
{
return firstName;
}
void setFirstName(string name)
{
firstName = name;
}
string getLastName()
{
return lastName;
}
void setLastName(string name)
{
lastName = name;
}
char getGender()
{
return gender;
}
void setGender(char gen)
{
switch (gen)
{
case'f': case'F': case'M': case'm':
gender = gen;
break;
default:
gender = DEFAULT_GENDER;
}
}
int getDependents()
{
return dependents;
}
void setDependents(int dep)
{
if (dep >= MIN_DEPENDENTS && dep <= MAX_DEPENDENTS)
{
dependents = dep;
}
else if (dep < MIN_DEPENDENTS)
{
dep = MIN_DEPENDENTS;
}
else
{
dependents = MAX_DEPENDENTS;
}
}
double getAnnualSalary()
{
return annualSalary;
}
void setAnnualSalary(double salary)
{
if (salary >= MIN_SALARY && salary <= MAX_SALARY)
{
annualSalary = salary;
}
else if (salary < MIN_SALARY)
{
annualSalary = MIN_SALARY;
}
else
{
annualSalary = MAX_SALARY;
}
}
//calculate employee salary
double calculatePay()
{
return annualSalary/NUMBER_WEEKS;
}
// function to display employee info
void displayEmployee()
{
cout<<"Employee Information\n ";
cout<<"_______________________________________________________________________\n ";
cout<<"First Name:\t\t "<<firstName<<endl; // show the first name of employee
cout<<"Last Name:\t\t "<<lastName<<endl; //show the last name of employee
cout<<"Gender:\t\t "<<gender<< "\n"; //show the gender of employee
cout<<"Dependents:\t "<<dependents<< "\n"; // show the number of dependents employee have
cout<<"Annual Salary:\t "<< setprecision(2)<<showpoint<<fixed<<annualSalary << "\n"; //show annual salary for employee
cout<<"Weekly Salary:\t "<< setprecision(2)<<showpoint<<fixed<<calculatePay() <<"\n"; //show weekly salary for employee
//showing the benefits
this->benefits.displayBenefits();
}
};//end of employee class
|
i didn't post the benefit class.