Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to create a list of employees by storing their information in th

ID: 3553126 • Letter: W

Question

Write a program to create a list of employees by storing their information in the following arrays:

The program should relate the data in each array through the subscripts. For example, the number in element 0 of the hours array should be the hours worked of the employee whose number is stored in element 0 of the empId array. Similarly with the other arrays. Create a constant for the array size to be used by all the arrays.

When the program is run, it first calls a function to display a menu as follows:

There are 6 functions:

Input Validation: Accept only value between 1 and 5 for the menu choice. The hours worked must be positive. The pay rate must be at least 6.

Explanation / Answer

#include <iostream>
using namespace std;
int MAXN =100;
int showMenu()
{
    cout<<"=================================================="<<endl;

cout<<"                  Employee Payroll"<<endl;

cout<<"1. Add employee"<<endl;
cout<<"2. Update employee"<<endl;
cout<<"3. Retrieve employee"<<endl;
cout<<"4. List all"<<endl;
cout<<"5. Quit the Program"<<endl<<endl;

cout<<"Enter your choice:"<<endl;
int in;
cin>>in;
while(in<1&&in>5)
{
    cout<<"The choice you entered is not correct. Please enter a value between 1 and 5"<<endl;
    cin>>in;
}
return in;
}
bool addEmployee(long long int *empId,int *hours,double *payRate,double *wages,int &n)
{
    int empNum,empHours;
    double empRate;
    if(n==(MAXN-1)){
        cout<<"No further employee records can be added"<<endl;
        return false;
    }
    cout<<"Enter the employee Number,hours worked and pay rate seperated by a space"<<endl;
    cin>>empNum>>empHours>>empRate;
    n++;
    empId[n-1]=empNum;
    hours[n-1]=empHours;
    payRate[n-1]=empRate;
    wages[n-1]=empRate*empHours;
    cout<<"Record successfully added"<<endl;
    return true;
}
int searchList(long long int *empId,int empNum,int n)
{
    for(int i=0;i<n;i++)
    {
        if(empId[i]==empNum)
            return i;
    }
    return n;
}
void updateEmployee(long long int *empId,int *hours,double *payRate,double *wages,int &n)
{
    cout<<"Enter the Employee number"<<endl;
    int empNum,empHours;
    double empRate;
    cin>>empNum;
    int index=searchList(empId,empNum,n);
        if(index!=n)
        {
            cout<<"Record Found "<<empNum<<endl;
            cout<<"Enter the hours worked and the payRate"<<endl;
            cin>>empHours>>empRate;
            empId[index]=empNum;
            hours[index]=empHours;
            payRate[index]=empRate;
            wages[index]=empRate*empHours;
            cout<<"Record successfully updated"<<endl;
        }
        else
            cout<<"Record not found"<<endl;
}
void retrieveEmployee(long long int *empId,int *hours,double *payRate,double *wages,int &n)
{
    cout<<"Enter the Employee number"<<endl;
    int empNum;
    cin>>empNum;
    int index=searchList(empId,empNum,n);
        if(index!=n)
        {
            cout<<"Record Found "<<empNum<<endl;
            cout<<"Emp Number : "<<empId[index]<<endl;
            cout<<"Wage : "<<wages[index]<<endl;
            cout<<"Pay Rate : "<<payRate[index]<<endl;
            cout<<"Hours worked : "<<hours[index]<<endl;
        }
        else
            cout<<"Record not found"<<endl;
}
void listEmployee(long long int *empId,int *hours,double *payRate,double *wages,int &n)
{
    for(int i=0;i<n;i++)
    {
        cout<<"Record "<<i+1<<endl;
        cout<<"Emp Number : "<<empId[i]<<endl;
            cout<<"Wage : "<<wages[i]<<endl;
            cout<<"Pay Rate : "<<payRate[i]<<endl;
            cout<<"Hours worked : "<<hours[i]<<endl<<endl;
    }
}
int main()
{
    long long int empId[MAXN];
    int hours[MAXN];
    int n=0;
    double payRate[MAXN],wages[MAXN];
    while(1){
        int choice=showMenu();
        if(choice==5)
            break;
        if(choice==1)
        {
            while(1){
            if(addEmployee(empId,hours,payRate,wages,n))
            {
                cout<<"Do you want to enter the records of more employees"<<endl;
                cout<<"Enter y for Yes or n for NO"<<endl;
                char c;
                cin>>c;
                if(c=='n')
                    break;
            }
            else
                break;
            }
        }
        else if(choice==2)
        {
            updateEmployee(empId,hours,payRate,wages,n);
        }
        else if(choice==3)
        {
            retrieveEmployee(empId,hours,payRate,wages,n);
        }
        else if(choice==4)
        {
            listEmployee(empId,hours,payRate,wages,n);
        }
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote