Write a class named Employee that has the following membervariables: • name. A s
ID: 3679331 • Letter: W
Question
Write a class named Employee that has the following membervariables:
• name. A string that holds the employee’s name.
• idNumber. An int variable that holds the employee’sID number.
• department. A string that holds the name of the departmentwhere the employee works.
• position. A string that holds the employee’s jobtitle.
The class should have the following constructors:
• A constructor that accepts the following values asarguments and assigns them to the appropriate member variables:employee’s name, employee’s ID number, department, andposition.
• A constructor that accepts the following values asarguments and assigns them to the appropriate member variables:employee’s name and ID number. The department and positionfields should be assigned an empty string (“ “);
• A default constructor that assigns empty strings (““) to the name, department, and position member variables,and 0 to the idNumber member variable.
Write appropriate mutator functions that store values in thesemember variables and accessor functions that return the values inthese member variables. Once you have written the class, create athree Employee objects (3 separate instances), in your mainfunction, to hold the following data.
Name ID Number Department Position
Susan Meyers 47899 Accounting Vice President
MarkJones 39119 IT Programmer
JoyRogers 81774 Manufacturing Engineer
The program should store this data in three objects and thendisplay the data for each employee on screen.
Explanation / Answer
#include<iostream>
using namespace std;
class employee
{
int emp_num;
char emp_name[20];
char pos[10];
char dept[10];
public:
void get_details();
void show_emp_details();
};
void employee :: get_details()
{
cout<<" Enter employee number: ";
cin>>emp_num;
cout<<" Enter employee name: ";
cin>>emp_name;
cout<<" Enter employee dept: ";
cin>>dept;
cout<<" Enter employee position: ";
cin>>pos;
}
void employee :: show_emp_details()
{
cout<<" Details of : "<<emp_name;
cout<<" Employee number: "<<emp_num;
cout<<" employee position : "<<pos;
cout<<" employee department : "<<dept;
}
int main()
{
int i;
cout<<" Enter number of employee details ";
employee e;
for(i=0;i<4;i++)
{
e.get_details();
e.show_emp_details();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.