Task: Write a function called DisplayEmployeeRec() that takes EmployeeRec as a parameter and displays the value using the following format:
NAME:
ID:
PAYRATE:
HOURS WORKED:
GROSS PAY:
This is what I have so far:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct EmployeeRec
{
string name;
string empId;
double payRate;
double hours;
double grossPay;
};
EmployeeRec GetEmployeeRec(); // function prototype
void DisplayEmployeeRec(EmployeeRec a, EmployeeRec b); //function prototype
int main()
{
EmployeeRec A;
EmployeeRec B;
GetEmployeeRec();
DisplayEmployeeRec(A,B);
cin.get(); cin.get();
return 0;
}
EmployeeRec GetEmployeeRec()
{
EmployeeRec A;
EmployeeRec B;
cout << fixed << showpoint << setprecision(2);
cout << "Name please enter employee1 name: "<< endl;
cin >> A.name;
cout << "Enter Employee ID: " <<endl;
cin >> A.empId;
cout << "Enter the employee payrate: ";
cin >> A.payRate;
cout << "Enter the hours worked by this employee: ";
cin >> A.hours;
A.grossPay = A.hours * A.payRate;
cout << "Gross Pay: " << A.grossPay << endl << endl;
cout << "Name please enter employee2 name: " << endl;
cin >> B.name;
cout << "Enter employee2 ID: " << endl;
cin >> B.empId;
cout << "Enter the employee2 payrate: ";
cin >> B.payRate;
cout << "Enter the hours worked by this employee: ";
cin >> B.hours;
B.grossPay = B.hours * B.payRate;
cout << "Gross Pay: " << B.grossPay << endl;
return(A,B);
}
void DisplayEmployeeRec(EmployeeRec a, EmployeeRec b)
{
EmployeeRec A;
EmployeeRec B;
cout<<"Name: "<<A.name<<endl;
cout<<"ID: "<<A.empId<<endl;
cout<<"Pay Rate: "<<A.payRate<<endl;
cout<<"Hours Worked: "<<A.hours<<endl;
cout<<"Gross Pay: "<<A.grossPay<<endl;
cout<<"Name: "<<B.name<<endl;
cout<<"ID: "<<B.empId<<endl;
cout<<"Pay Rate: "<<B.payRate<<endl;
cout<<"Hours Worked: "<<B.hours<<endl;
cout<<"Gross Pay: "<<B.grossPay<<endl;
}
I'm unsure if this is the correct way in writing this program. Please leave a comment.