Question: Using the following code, I need to: 1. Instead of using separate variables to store employee information (employee1, employee2, etc.), modify you program from the

Using the following code, I need to:

  1. 1. Instead of using separate variables to store employee information (employee1, employee2, etc.), modify you program from the previous task to declare an array of structs to hold the information of up to 100 employees. Name the array empList

  1. 2. Use function getEmployeeInfo() to read data for at least 3 employees into array empList. You can prompt the user to tell you how many employees they want to enter. Be sure to save the number of employee entered into a variable.

  1. 3. Use function displayEmplyeeInfo() to display the employee information in empList. Use the same output format at in the previous task.

#include

#include

using namespace std;

struct address

{

string street, city, state;

int zipCode;

};

struct EmployeeRec

{

string name;

string empId;

double payRate;

double hours;

address add;

};

EmployeeRec empList[100];

address readAddress()

{

address d;

cout << "enter the street";

cin >> d.street;

cin.ignore(100, ' ');

cout << "enter the city";

cin >> d.city;

cout << "enter the state";

cin >> d.state;

cout << "enter the zip code";

cin >> d.zipCode;

return d;

}

EmployeeRec getEmployeeInfo()

{

int numEmployee;

cout << "How many employees do you want to enter";

cin >> numEmployee;

for (int i = 0; i < numEmployee-1; ++i)

{

EmployeeRec Info;

cout << "enter employee name";

cin >> Info.name;

cin.ignore(100, ' ');

cout << "enter employee ID";

getline(cin, Info.empId);

cout << "enter pay rate";

cin >> Info.payRate;

cout << "enter hours worked";

cin >> Info.hours;

Info.add = readAddress();

return Info;

}

}

void displayAddress(address d)

{

cout << d.street << " " << d.city << " ," << d.state << ", " << d.zipCode;

}

void displayEmployeeInfo(EmployeeRec x)

{

cout << x.name << ", " << x.empId << ", ";

cout << x.payRate << ", " << x.hours << ". " << x.payRate*x.hours << ", ";

displayAddress(x.add);

}

using namespace std;

int main()

{

EmployeeRec x;

x = getEmployeeInfo();

cout << endl;

displayEmployeeInfo(x);

cout << endl;

system("pause");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!