Question: Sorry I would split this into multiple questions but each part depends on the previous. Part 1: Exercise 1. Modify the below program so that
Sorry I would split this into multiple questions but each part depends on the previous.
Part 1:
Exercise 1.Modify the below program so that instead of initializing employee information in the code (with the initializations), it prompts the user to input the data (name, id, and pay rate) from the standard input device (keyboard) and stores it in variables employee1 and employee2.
// This program demonstrates the use of structure variables.
#include
#include
#include
using namespace std;
struct EmployeeRec
{
string name; // Employee name
String empId; // Employee number
double payRate; // Hourly pay rate
double hours; // Hours worked
};
int main()
{
EmployeeRec employee1 = {"Betty Ross", 14001, 18.75};
EmployeeRec employee2 = {"Rashid Wallace", 14002, 17.50};
double grossPay;
cout << fixed << showpoint << setprecision(2);
// Calculate pay for employee1
cout << "Name: " << employee1.name << endl;
cout << "Employee Number: " << employee1.empId << endl;
cout << "Enter the hours worked by this employee: ";
cin >> employee1.hours;
grossPay = employee1.hours * employee1.payRate;
cout << "Gross Pay: " << grossPay << endl << endl;
// Calculate pay for employee2
cout << "Name: " << employee2.name << endl;
cout << "Employee Number: " << employee2.empId << endl;
cout << "Enter the hours worked by this employee: ";
cin >> employee2.hours;
grossPay = employee2.hours * employee2.payRate;
cout << "Gross Pay: " << grossPay << endl;
return 0;
}
Part 2: Defining functions to manipulate structures
Exercise 1.Write a function called getEmpployeeInfo() that prompts the user to enter an employee information (name, id, and pay rate) from standard input and returns it as a EmployeeRec struct. Call the function to get information for employee1 and employee2.
Exercise 2.Write a function called displayEmpployeeInfo() that takes and EmployeeRec as a parameter and displays the value of its data members on the console using the following format:
Name: -----------------------------------
ID: ----------------------------------
Pay Rate: ----------------------------------
Hours Worked: ----------------------------------
Gross pay: ----------------------------------
Exercise 3.Modify the above program to use function displayEmployeeInfo() to output the employees information.
Part 3: Arrays of Structures
Exercise 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
Exercise 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.
Exercise 3.Use function displayEmplyeeInfo() to display the employee information in empList. Use the same output format at in the previous task.
Part 4: Hierarchical Structures
Exercise 1.Add another member to the EmployeeInfo struct to store the employees address. The address member should be a struct data type with the following members:
Street
City
State
Zip code
Exercise 2.Modify your program of Task 3, including the get and display functions, to incorporate this change.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
