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....
In c++ create a class to maintain a GradeBook. The class should allow information on up...
In c++ create a class to maintain a GradeBook. The class should allow information on up to 3 students to be stored. The information for each student should be encapsulated in a Student class and should include the student's last name and up to 5 grades for the student. Note that less than 5 grades may sometimes be stored. Your GradeBook class should at least support operations to add a student record to the end of the book (i.e., the...
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...
Write a C program Design a program that uses an array to store 10 randomly generated...
Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...
Create a simple Java class for a Month object with the following requirements:  This program...
Create a simple Java class for a Month object with the following requirements:  This program will have a header block comment with your name, the course and section, as well as a brief description of what the class does.  All methods will have comments concerning their purpose, their inputs, and their outputs  One integer property: monthNumber (protected to only allow values 1-12). This is a numeric representation of the month (e.g. 1 represents January, 2 represents February,...
Using C# Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and...
Using C# Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and initSalary. It includes constructor(s) and properties to initialize values for all fields. Create an interface, SalaryCalculate, class that includes two functions: first,CalcYearWorked() function, it takes one parameter (currentyear) and calculates the number of year the worker has been working. The second function, CalcCurSalary() function that calculates the current year salary. Create a Worker classes that is derived from Employee and SalaryCalculate class. In Worker...
Java... Write a class named TestScores. The class constructor should accept an array of test scores...
Java... Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate the class in a program (create a Driver class in the same file). The program should ask the user to input the number of test scores 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”...
write C++ programs Array of Payroll Objects Design a PayRoll class that has data members for...
write C++ programs Array of Payroll Objects Design a PayRoll class that has data members for an employee’s hourly pay rate and number of hours worked. Write a program with an array of seven PayRoll objects. The program should read the number of hours each employee worked and their hourly pay rate from a file and call class functions to store this information in the appropriate objects. It should then call a class function, once for each object, to return...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT