Question

In C++ Employee Class Write a class named Employee (see definition below), create an array of...

In C++

Employee Class

Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions.

In main create an array of 100 Employee objects using the default constructor.

The program will repeatedly execute four menu items selected by the user, in main:

1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored, up to 100).

2) in a second function, display the employee data from the array.

3) in main have the user enter an employee ID number and name, and while processing each object in the array call the "Match" member function described below; if the ID and name are found in the current object then display in main all of the associated object's employee data; if not found display in main an error message with the entered ID and name.

4) end the program

The Employee class should be defined as follows:

Private member data:

-name (a string)

-idNumber (an int)

-department (a string)

-position (a string)

The Employee class should have the following Public member functions:

-a default constructor

-a constructor which accepts the employee name and ID number as arguments and assigns them to the appropriate member variables

-a constructor which accepts the employee name, ID number, department, and position as arguments and assigns them to the appropriate member variables

Also write the appropriate accessor (getter) and mutator (setter) functions for each of the member variables.

The employee ID number will be entered by the user in a member function named Enter_ID and returned via its return type. Enter_ID will call "private" member function Validate to validate the ID, which will be returned to Enter_ID via reference variable (the ID must be greater than zero).

Add a "Match" member function to the Employee class. The “Match” function will accept into its parameter list an ID number and name. The function will match the two parameter values to those in the current object and return "true" if the values match, i.e., the employee is found, or "false" if not.

Provide four screen prints:

-execute menu option #1 (have the user enter the data for the four employees shown below)

-execute menu option #3 (have the user enter ID Number 39119 and Mark Jones)

-execute menu option #2

-execute menu option #3 (have the user enter ID Number 53179 and Susan Meyers)

Employee data for user to enter (name; id; department; position):

Susan Meyers; 47899; Accounting; Vice President

Mark Jones; 39119; IT; Programmer

Joy Rogers; 81774; Manufacturing; Engineer

Humpty Dumpty; 00001; Executive; CEO

Homework Answers

Answer #1

#include<iostream>
#include<string>
using namespace std;

class Employee
{
   private:
       string name,dept,position;
       int id;
       bool validate(int i)
       {
           if(i<=0)
           return false;
           else return true;
       }
   public:
       Employee()
       {
           this->name="ABC";
           this->dept="XYZ";
           this->position="NONE";
           this->id=0;
       }
      
       Employee(string name,int id)
       {
           this->name=name;
           this->dept="XYZ";
           this->position="NONE";
           this->id=id;
       }
      
       Employee(string name,string department,string pos,int id)
       {
           this->name=name;
           this->dept=department;
           this->position=pos;
           this->id=id;
       }
      
       void setName(string name)
       {
           this->name=name;
       }
      
       string getName()
       {
           return this->name;
       }
      
       void setDept(string dept)
       {
           this->dept=dept;
       }
      
       string getDept()
       {
           return this->dept;
       }
      
       void setPosition(string pos)
       {
           this->position=pos;
       }
      
       string getPosition()
       {
           return this->position;
       }
      
       void setId(int id)
       {
           this->id=id;
       }
      
       int getId()
       {
           return this->id;
       }
      
       bool Enter_ID()
       {
           int i;
           cout<<"Enter the id of employee: ";
           cin>>i;
           if(validate(i))
           {
               setId(i);
               return true;
           }
           else return false;
       }
      
       bool Match(int i,string n)
       {
           if(this->id!=i || this->name.compare(n)!=0)
           {
               return false;
           }
           else
           {
               cout<<"\nEmployee found with details:-\n";
               this->display();
               return true;
           }
       }
      
       void display()
       {
           cout<<"\nID: "<<this->getId();
           cout<<"\nName: "<<this->getName();
           cout<<"\nDepartment: "<<this->getDept();
           cout<<"\nPosition: "<<this->getPosition();
           cout<<"\n";
       }
};

int main()
{
   Employee e[100];
   int n=0,ch;
   string na,d,p="";
   do
   {
       cout<<"1) Enter employee details";
       cout<<"\n2) Display all emplyees";
       cout<<"\n3) Search for an employee";
       cout<<"\n4) exit the program";
       cout<<"\nEnter your choice: ";
       cin>>ch;
      
       switch(ch)
       {
           case 1:
               cout<<"\nEnter the name of the employee: ";
               cin.ignore();
               getline(cin, na);
               e[n].setName(na);
               reenter:
               if(e[n].Enter_ID())
               {
                   cout<<"Enter the department: ";
                   cin.ignore();
                   getline(cin,d);
                   e[n].setDept(d);
                   cout<<"Enter the position of the employee: ";
                   getline(cin,p);
                   e[n].setPosition(p);
                   n++;
               }
               else
               {
                   cout<<"\nThe id must be greater the 0.\n";
                   goto reenter;  
               }
               break;
           case 2:
               for(int i=0;i<n;i++)
               e[i].display();
               break;
           case 3:
               int id,f;
               f=0;
               bool a;
               cout<<"\nEnter the id of the employee to be searched: ";
               cin>>id;
               cout<<"Enter the name of the employee to be searched: ";
               cin.ignore();
               getline(cin,na);
               for(int i=0;i<n;i++)
               {
                   if(e[i].Match(id,na))
                   {
                       f=1;
                       goto out;
                   }
                  
               }
               out:
               if(f==0)
               cout<<"\nThe employee does not exist";
               break;
           case 4:
               cout<<"Exiting...";
               break;
       }
       cout<<"\n";
   }while(ch!=4);
   return 0;
}

Output:-

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a C# application You are to create a class object called “Employee” which included eight...
Create a C# application You are to create a class object called “Employee” which included eight private variables: firstN lastN dNum wage: holds how much the person makes per hour weekHrsWkd: holds how many total hours the person worked each week. regHrsAmt: initialize to a fixed amount of 40 using constructor. regPay otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods:  constructor  properties  CalcPay(): Calculate the regular...
write a c++ program A class called car (as shown in the class diagram) contains: o...
write a c++ program A class called car (as shown in the class diagram) contains: o Four private variables: carId (int), carType (String), carSpeed (int) and numOfCars (int). numOfCars is a static counter that should be  Incremented whenever a new Car object is created.  Decremented whenever a Car object is destructed. o Two constructors (parametrized and copy constructor) and one destructor. o Getters and setters for the Car type, ID, and speed. And static getter function for numOfCars....
This program is in C++: Write a program to allow the user to: 1. Create two...
This program is in C++: Write a program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to...
c++ C++ CLASSES and objects DO ADD COMMENTS DISPLAY OUTPUT First make three files: episode.cpp, episode.h...
c++ C++ CLASSES and objects DO ADD COMMENTS DISPLAY OUTPUT First make three files: episode.cpp, episode.h andRun.cpp to separate class header and implementation. In this program, we are going to create a small scale Telivision Management System. A) Create a class Episode with following variables: char* episode_name, char* episode_venue, char episode_date[22] and char episode_time[18]. Input format for episode_date: dd-mm-yyyy Input format for episode_time: hh:mm am/pm B) Implement default constructor and overloaded constructor. Print “Default Constructor Called” and “Overloaded Constructor Called”...
Create a class called Employee that contains three instance variables (First Name (String), Last Name (String),...
Create a class called Employee that contains three instance variables (First Name (String), Last Name (String), Monthly Salary (double)). Create a constructor that initializes these variables. Define set and get methods for each variable. If the monthly salary is not positive, do not set the salary. Create a separate test class called EmployeeTest that will use the Employee class. By running this class, create two employees (Employee object) and print the annual salary of each employee (object). Then set the...
Java Create a new Drive class. * Create a Menu class. * The menu class will...
Java Create a new Drive class. * Create a Menu class. * The menu class will use the previous 4 classes you created in GCD, LCM, FACTORIAL, DIGITS The Menu will display a menu that give you the option of selecting: 1) Greatest Common Denominator 2) Lowest Common Multiple 3) Factorial 4) Number of Digits in an Integer Enter 1,2,3 or 4: When the User enter the choice, then the correct function/method is called for the class and asks the...
1. Consider the following interface: interface Duty { public String getDuty(); } a. Write a class...
1. Consider the following interface: interface Duty { public String getDuty(); } a. Write a class called Student which implements Duty. Class Student adds 1 data field, id, and 2 methods, getId and setId, along with a 1-argument constructor. The duty of a Student is to study 40 hours a week. b. Write a class called Professor which implements Duty. Class Professor adds 1 data field, name, and 2 methods, getName and setName, along with a 1-argument constructor. The duty...
Create a Software Application for XYZ Bank that allows its members to access their bank account...
Create a Software Application for XYZ Bank that allows its members to access their bank account information through an “ATM like” interface. The Menu Options should include: checking the account balance, debiting the account and crediting the account, along with an option to exit the program. Create an Account Class to represent the customers’ bank accounts. Include a data member of type float to represent the account balance. Provide a constructor that receives an initial balance and uses it to...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this assignment must be submitted by the deadline on Blackboard. Submitting your assignment early is recommended, in case problems arise with the submission process. Late submissions will be accepted (but penalized 10pts for each day late) up to one week after the submission deadline. After that, assignments will not be accepted. Assignment The object of this assignment is to construct a mini-banking system that helps...
My assignment: Triplet Template Class Directions: Define a template class for a generic triplet. The private...
My assignment: Triplet Template Class Directions: Define a template class for a generic triplet. The private data member for the triplet is a generic array with three elements. The triplet ADT has the following functions:  default constructor  explicit constructor: initialize the data member using parameters  three accessors (three get functions) which will return the value of each individual element of the array data member  one mutator (set function) which will assign values to the data member...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT