Answer to Question #262645 in C++ for ron

Question #262645

The input file called StaffDetails.txt contains a list of records of employees working for USP. The file is generated automatically by the biometric sign-in used by all USP staff and passed to payroll department for calculation of monthly wages. Each record is on a single line and the fields are separated by spaces. The names of the fields are: • Employee ID • Employee Last name • Employee First name • Hourly rate • Hours worked in that month An example record may have the following form but the file can have a maximum of 300 records: H111007 Bond James 40.0 150

A. You must read this file and store the records of employees into appropriate arrays. B. Program should provide user with the following menu. 1) Print all employees’ data. 2) Print all data about of employees which match a given last name that is entered by a user 3) Calculate the net wages for all employees and store it in an array. 4) Display payroll results. 5) Write results to file 6) Exit program.


1
Expert's answer
2021-11-08T05:32:58-0500
#include <iostream>
#include <stdlib.h>
#include <fstream>
using namespace std;
class employee
{
private:
    float hr,hno,net;
    string EmpId, EmpLname, EmpFname,Lname;
public:
    void getdata();
    void display();
    void display1();
    void netwages();
    void displaypayroll();
};
void employee::getdata()
{
      cout<<"Enter Employee Id: "<<endl;
      cin>>EmpId;
      cout<<"Enter Employee Last Name: "<<endl;
      cin>>EmpLname;
      cout<<"Enter Employee First Name: "<<endl;
      cin>>EmpFname;
      cout<<"Enter Hourly rate: "<<endl;
      cin>>hr;
      cout<<"Enter Hours worked in that month: "<<endl;
      cin>>hno;
}
void employee::display()
{
    cout<<EmpId<<"\t"<<EmpLname<<"\t"<<EmpFname<<"\t"<<hr<<"\t"<<hno<<endl;
}
void employee::display1()
{
    cout<<"Enter employee the employee last name"<<endl;
    cin>>Lname;
    if(Lname==EmpLname)
    {
     cout<<EmpId<<"\t"<<EmpLname<<"\t"<<EmpFname<<"\t"<<hr<<"\t"<<hno<<endl;
    }
    else
    {
        cout<<"The employee does not exist"<<endl;
    }
}
void employee::netwages()
{
    net=hr*hno;
}
void employee::displaypayroll()
{
  net=hr*hno;
  cout<<EmpId<<"\t"<<EmpLname<<"\t"<<EmpFname<<"\t"<<hr<<"\t"<<hno<<"\t"<<net<<endl;
}
int main()
{
    int n=1,i,E;
    cout<<"How many Employees?\n";
    cin>>n;
    employee e[n]; //array of objects size n
    for (i=0; i<n; i++)
    {
        e[i].getdata ();
    }
    cout<<"\t\t\tRecord of employees in USP company"<<endl;
    cout<<"\t\t\t__________________________________"<<endl;
    cout<<"\t\t\t\t***Payroll Department***"<<endl;
    cout<<"\t1.Print all employees’ data:"<<endl;
    cout<<"\t2.Print all data about of employees which match a given last name that is entered by a user:"<<endl;
    cout<<"\t3.Calculate the net wages for all employees and store it in an array"<<endl;
    cout<<"\t4.Display payroll results:"<<endl;
    cout<<"\t5.Write results to file:"<<endl;
    cout<<"\t6.Exit program:"<<endl;
    cout<<"choose operation: "<<endl;
    cin>>E;
    switch(E)
    {
    case 1:
        cout<<"Print all employees’ data:"<<endl;
        for (i=0; i<n; i++)
        {
            e[i].display ();
        }
        break;
    case 2:
        cout<<"The data about of employee"<<endl;
        for (i=0; i<n; i++)
        {
            e[i].display1 ();
        }
        break;
    case 3:
        cout<<"Calculate the net wages for all employees:"<<endl;
        for (i=0; i<n; i++)
        {
            e[i].netwages ();
        }
        break;
    case 4:
        cout<<"Display payroll results:"<<endl;
         for (i=0; i<n; i++)
        {
            e[i].displaypayroll ();
        }
        break;
    case 5:


    break;
    case 6:
        exit(6);
        break;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS