Extend the employee
class of Exercise 4 to include a date
class (see Exercise 5) and an etype enum (see Exercise 6 in Chapter 4). An
object of the date class should be used to hold the date of first employment;
that is, the date when the employee was hired. The etype variable should hold
the employee’s type:{ laborer, secretary, manager, accountant, executive, researcher
}. These two items will be private member data in the employee definition, just
like the employee number and salary. You’ll need to extend the getemploy() and
putemploy() functions to obtain this new information from the user and display
it. These functions will probably need switch statements to handle the etype
variable. Write a main() program that allows the user to enter data for three
employee variables and then displays this data.
SOLUTION:
#include "stdafx.h"
#include "iostream"
using namespace std;
/////////////////////////////////////////////////////////////////////////////////////////
class date
{
private:
int
month,day,year;
char
dummychar;
public:
void
getdate( )
{
cin
>> day >> dummychar >> month >> dummychar >>
year;
}
void
showdate( ) const
{
cout
<< day << "/" << month << "/"
<< year << endl;
}
};
class employee
{
private:
enum
etype { laborer, secretary, manager, accountant, executive, researcher };
date
d_hired;
char
c;
public:
void
getemploy( )
{
cout
<< "Enter employee type (first letter only)\n";
cout
<< "( i.e. laborer, secretary, manager, accountant, executive,
researcher): ";
cin
>> c;
cout
<< "Enter Date when the Employee was Hired ( DAY/MONTH/YEAR Format
): ";
d_hired.getdate(
);
}
void
putemploy( )
{
switch(c)
{
case
'l': case 'L':
cout
<< "\nEmployee Type is 'Laborer' and,\n";
cout
<< "Date of Employement is: ";
d_hired.showdate( ); break;
case
's': case 'S':
cout
<< "\nEmployee Type is 'Secretary' and,\n"
cout
<<"Date of Employement is: ";
d_hired.showdate( ); break;
case
'm': case 'M':
cout
<< "\nEmployee Type is 'Manager' and,\n";
cout
<< "Date of Employement is: ";
d_hired.showdate( ); break;
case
'a': case 'A':
cout
<< "\nEmployee Type is 'Accountant' and,\n";
cout
<< "Date of Employement is: ";
d_hired.showdate( ); break;
case
'e': case 'E':
cout
<< "\nEmployee Type is 'Executive' and,\n";
cout
<< "Date of Employement is: ";
d_hired.showdate( ); break;
case
'r': case 'R':
cout
<< "\nEmployee Type is 'Researcher' and,\n";
cout
<< "Date of Employement is: ";
d_hired.showdate( ); break;
}
}
};
/////////////////////////////////////////////////////////////////////////////////////////
void main( )
{
employee
emp1,emp2,emp3;
emp1.getemploy(
);
emp2.getemploy(
);
emp3.getemploy(
);
emp1.putemploy(
);
emp2.putemploy(
);
emp3.putemploy(
);
system("pause");
}
OUTPUT:
0 comments: