In: Computer Science
C++ program:
Create a Date class that contains three members: the month, the day of the month, and the year, all of type int. The user should enter a date in the format 12/31/2001, store it in an object of type Date, then retrieve the object and print it out in the same format.
Next create an employee class. The member data should comprise an employee number (type int) and the employee’s compensation (in dollars; type float). Extend the employee class to also include a Date class and an enumerator, etype, to hold the employee’s type. The enumerated values are:{laborer, secretary, manager, accountant, executive, researcher }.
The Date field should be used to hold the date when the employee was hired. The etype variable should hold the employee type. These two items will be private member data in the employee definition, just like the employee number and salary. Member functions should allow the user to enter this data and display it.The program should ask the user to fill in the employees’ data for three employees, store it in an array of three objects of type Employee, and then display the information for each employee.
The program should allow the user to specify employee type by entering its first letter (‘l’, ‘s’, ‘m’, and so on) and then storing the type chosen as a value of a variable of type etype.
You will write an object oriented program to implement this. It is assumed that you will use good programming practices you have learnt in the course to write safe, reliable, and well tested programs.
SOLUTION-
I have solve the problem in C++ code with comments and screenshot
for easy understanding :)
CODE-
//c++ code
#include<bits/stdc++.h>
using namespace std;
//class date
class Date {
public:
int month, day,
year;
//constructor
void set(int m, int d,
int y) {
month = m;
day = d;
year = y;
}
};
enum etype {
laborer, secretary,
manager, accountant,
executive,
researcher
};
class Employee {
// private:
//data members
int
Employee_number;
float
compensation;
Date D = Date();
etype E;
public:
//constructors
Employee() {}
Employee(int Emp, double com, int month, int day, int year, char c) {
if (c == 'l') {
E = laborer;
} else if (c == 's') {
E = secretary;
} else if (c == 'm') {
E = manager;
} else if (c == 'a') {
E = accountant;
} else if (c == 'e') {
E = executive;
} else {
E = researcher;
}
Employee_number = Emp;
compensation = com;
D.set(month, day, year);
}
void display()
{
cout << "Employee Number: " << Employee_number <<
endl;
cout << "Employee Compensation: " << compensation
<< endl;
cout << "Date of hiring: " << D.month << "/"
<< D.day << "/" << D.year << endl;
cout << "Employee type: ";
if (E == laborer) {
cout << "laborer";
} else if (E == secretary) {
cout << "secretary";
} else if (E == manager) {
cout << "manager";
} else if (E == accountant) {
cout << "accountant";
} else if (E == executive) {
cout << "executive";
} else if (E == researcher) {
cout << "researcher";
}
cout << endl;
}
};
int main()
{
Employee arr[3] ;
for (int i = 0; i
< 3; ++i) {
cout << "Employee " << i + 1 << " : \n";
int n;
double c;
int month, day, year;
char e;
cout << "Enter employee number: ";
cin >> n;
cout << "Enter employee compensation: ";
cin >> c;
cout << "Enter date of hiring of employee: ";
scanf("%2d/%2d/%4d", &month, &day, &year);
cout << "Enter first letter of employee type: ";
cin >> e;
arr[i] = Employee(n, c, month, day, year, e);
cout << endl;
}
cout << "Employee Details:\n";
for (int i = 0; i
< 3; ++i) {
arr[i].display();
cout << endl;
}
return 0;
}
SCREENSHOT-
IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL
SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK
YOU!!!!!!!!----------