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.\n";
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:\n";
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;
}
Short Summary:
Source Code:
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
//Struct for hours and payRate
struct Employee
{
int hours;
double payRate;
};
int main()
{
vector<Employee> Employees; //Empty employees
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.\n";
for (index = 0; index < numEmployees; index++)
{
struct Employee employee; //create a employee
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;
employee.hours = tempHours; //Assign the hours to struct
employee
cout << "Hourly pay rate for employee #";
cout << (index + 1) << ": ";
cin >> tempRate;
employee.payRate = tempRate; //Assign the payRate to struct
employee
Employees.push_back(employee); //Add the employee to vector
}
// Display each employee's gross pay.
cout << "Here is the gross pay for each employee:\n";
cout << fixed << showpoint <<
setprecision(2);
for (index = 0; index < numEmployees; index++)
{
//retreive Struct Employee by Index
struct Employee employee = Employees[index];
double grossPay = employee.hours * employee.payRate;
cout << "Employee #" << (index + 1);
cout << ": $" << grossPay << endl;
}
return 0;
}
Refer the following screenshots for code indentation:



Sample Output:

Feel free to rate the answer and ask questions, if you have any.
Happy Studying!!
Using the code below (C++), add a struct with only 1 vector #include #include #include //...
i am having trouble displaying results and displaying them evenly it is suppose to look like this Enter the following data for employee 1: Employee ID: 1298 Hours worked: 35.8 Pay rate (per hour): 23.45 Enter the following data for employee 2: Employee ID: 1899 Hours worked: 34.5 Pay rate (per hour): 19.5 Enter the following data for employee 3: Employee ID: 4435 Hours worked: 30.5 Pay rate (per hour): 20.75 Enter the following data for employee 4: Employee ID:...
// I am going to use if and else stamtents for this employee pay clalulations. //using if and else to cal salary //If hours worked is <= 40.0 //Employee salry will = hours*pay rate //else //employess salary will =40*pay rate +(hours worked-40)*1.5* pay rate. #include using namespace std; const double Max_Hours= 40.0; const double MuLTIPLER = 1.5; char salary; char payrate; char hours_worked; char Max_hours; char get_total_pay; int main() { double Hours=0; double Payrate = 0; cout <<"Please enter employee...
Why is my code not calculating the pay and not printing entire data at the end? // // main.cpp // Project 14 // // Created by Esmeralda Martinez on 5/13/19. // Copyright © 2019 Esmeralda Martinez. All rights reserved. // #include<iostream> #include<fstream> #include<cstdlib> #include<regex> #include <iomanip> using namespace std; float grossPay(float hrsWorked, float payrate); float grossPay(float hrsWorked, float payrate){ return hrsWorked*payrate; } int main(){ //opening an output file ifstream outFile("Employee.txt", ios::in); //Read variables string depId,emp_num,firstName,lastName,email,hrs_worked,pay_rate,ch="y"; //Regex patterns regex integerPattern("(\\+|-)?[[:digit:]]+"); regex...
I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using namespace std; int NumOfEmployees(); int TotDaysAbsent(int); double AverageAbsent(int, int); int main() { cout << endl << "Calculate the average number of days a company's employees are absent." << endl << endl; int numOfEmployees = NumOfEmployees(); TotDaysAbsent(numOfEmployees); return 0; } int NumOfEmployees() { int numOfEmployees = 0; cout << "Please enter the number of employees in the company: "; cin >> numOfEmployees; while(numOfEmployees <= 0) { ...
I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using namespace std; int NumOfEmployees(); int TotDaysAbsent(int); double AverageAbsent(int, int); int main() { cout << endl << "Calculate the average number of days a company's employees are absent." << endl << endl; int numOfEmployees = NumOfEmployees(); TotDaysAbsent(numOfEmployees); return 0; } int NumOfEmployees() { int numOfEmployees = 0; cout << "Please enter the number of employees in the company: "; cin >> numOfEmployees; while(numOfEmployees <= 0) {...
This C++ program will not let me put numbers in on address, just characters #include using namespace std; float paycalc(){ cout<<"Enter 1 if salary and 2 if hourly: "; int choice, hoursWorked, payrate; float salary; cin>>choice; if(choice == 1){ cout<<"Enter your salary per month: "; cin>>salary; }else{ cout<<"Enter hours worked: "; cin>>hoursWorked; cout<<"Enter pay rate: "; cin>>payrate; salary = hoursWorked * payrate; } return salary; } void printCheck(float sal, int id, char address[30]){ cout<<"Employee id: "<>id; cout<<"Enter address: "; char...
Given the following program, which line(s) cause(s) output to be displayed on the screen? 1 // This program displays my gross wages. 2 // I worked 40 hours and I make $20.00 per hour. 3 #include <iostream> 4 using namespace std; 5 6 int main() 7 { 8 int hours; 9 double payRate, grossPay; 10 11 hours = 40; 12 payRate = 20.0; 13 grossPay = hours * payRate; 14 cout << "My gross pay is $" << grossPay <<...
Convert to use functions where possible #include<iostream> #include<string> using namespace std; int main() { string first, last, job; double hours, wages, net, gross, tax, taxrate = .40; double oPay, oHours; int deductions; // input section cout << "Enter First Name: "; cin >> first; cout << "Enter Last Name: "; cin >> last; cin.ignore(); cout << "Enter Job Title: "; getline(cin, job); cout << "Enter Hours Worked:...
C# please...
Design a program that uses the following parallel arrays:
empId: An array of seven Integers to hold employee identification numbers. The array should be initialized with the following numbers: 56588 45201 78951 87775 84512 13028 75804 hours: An array of seven Integers to hold the number of hours worked by each employee payRate: An array of seven Reals to hold each employee's hourly pay rate wages: An array of seven Reals to hold each employee's gross wages. The...
A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following: int main() { double radius; double area; double circumference; //the radius...