Question
Using the code below (C++), add a struct with only 1 vector #include #include #include // Needed to define vectors using namespace std; int main()
Using the code below (C++), add a struct with only 1 vector
#include #include #include // Needed to define vectors using namespace std;
int main() { vector hours; // hours is an empty vector vector payRate; // payRate is an empty vector int numEmployees; // The number of employees int index; // Loop counter
// Get the number of employees. cout << "How many employees do you have? "; cin >> numEmployees;
// Input the payroll data. cout << "Enter the hours worked by " << numEmployees; cout << " employees and their hourly rates. "; for (index = 0; index < numEmployees; index++) { int tempHours; // To hold the number of hours entered double tempRate; // To hold the payrate entered
cout << "Hours worked by employee #" << (index + 1); cout << ": "; cin >> tempHours; hours.push_back(tempHours); // Add an element to hours cout << "Hourly pay rate for employee #"; cout << (index + 1) << ": "; cin >> tempRate; payRate.push_back(tempRate); // Add an element to payRate }
// Display each employee's gross pay. cout << "Here is the gross pay for each employee: "; cout << fixed << showpoint << setprecision(2); for (index = 0; index < numEmployees; index++) { double grossPay = hours[index] * payRate[index]; cout << "Employee #" << (index + 1); cout << ": $" << grossPay << endl; } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started