C++ HELP PLEASE
Write a C++ program named bonuses.cpp in accordance with the following requirements. It’s your responsibility to fulfill all that is required.
Write a program that can report the bonuses all employees in the department will receive in the current quarter. You must use parallel arrays to load employee names and bonus information, process the information, and produce the required report. You must not prompt the user for the information. You can make up the employee names. You must use the random number generator to generate the bonus amounts. The source file must be called bonuses.cpp and should include the functions specified below.
The main function. In the main function, define an array of 12 employee names (you must initialize the array with a list of employee names that you make up) and an array of 12 doubles for storing the employee bonuses. You must use a named constant for the size declarator, 12, of the arrays. These are so called parallel arrays. That is, the employee name at certain subscript in the first array is related to the bonus at the same subscript in the second array. Set up the random number generator by seeding it with current time. Then call the function getBonuses and pass the array of bonuses and its size (the named constant) to load the bonus amounts into the array of bonuses. At last, call the function reportBonuses and pass the arrays and their size information (the named constant) to report the bonuses.
– A function named getBonuses that will receive two parameters: an array of bonuses, and the number of bonuses. The function should use the random number generator to set the bonus for each employee in the array of bonuses. The bonuses should be in hundreds and in the range from 100 to 2500. For examples, 1200 or 1300, but not something like 1281.
– A function named getTotalBonus that will receive two parameters: an array of bonuses, and the number of bonuses. The function should find the total amount of bonuses from the given array of bonuses and return the total amount.
– A function named getLargestBonus that will receive two parameters: an array of bonuses, and the number of bonuses. The function should find the largest bonus from the given array of bonuses and return the largest bonus amount.
– A function named reportBonuses that will receive four parameters: an array of employee names who may receive bonuses, the number of employee names, an array of bonuses, and the number of bonuses. The function should call getTotalBonus to determine the total of the bonuses given to the employees and getLargestBonus to determine the largest bonus that has been given to the employees. The function should report the bonuses using the following format:
Report of Bonuses
Employee Name Bonus
————————————-
Henry Kim 1200.00
Michelle Rice 1300.00
Total of bonuses: 2500.00
Largest bonus: 1300.00
Expert Answer
C++ Program:
#include <iostream>
#include <iomanip>
#include <string>
#include <stdlib.h>
#include <time.h>
using namespace std;
//Function prototype
void getBonuses(double[], int);
double getTotalBonus(double[], int);
double getLargestBonus(double[], int);
void reportBonuses(string[], int, double[], int);
//Constant size declaration
const int SIZE = 12;
//Main function
int main()
{
//Array of names
string empNames[] = {“Henry Kim”, “Michelle Rice”, “Tom Cruise”, “Jeffry Head”, “Cramp Jone”, “Jack Jill”, “Ken Thompson”, “Dennis Ritchie”, “Van Rossum”,
“Park Jey”, “Taylor Kane”, “Per Le”, “Sam Deborah”, “Warren Jeff”, “Luis Philip”};
double empBonus[SIZE];
//Seeding random generator
srand(time(NULL));
//Generating bonus
getBonuses(empBonus, SIZE);
//Printing a report
reportBonuses(empNames, SIZE, empBonus, SIZE);
return 0;
}
//Function that generates array of double values
void getBonuses(double bonus[], int numBonuses)
{
int i;
//Iterating over array
for(i=0; i<numBonuses; i++)
{
//Generating a random number
bonus[i] = ((rand()%25)+1) * 100;
}
}
//Function that generates total of bonus
double getTotalBonus(double bonus[], int numBonuses)
{
int i;
double total = 0;
//Iterating over array
for(i=0; i<numBonuses; i++)
{
//Accumulating sum
total += bonus[i];
}
return total;
}
//Function that generates largest of bonus
double getLargestBonus(double bonus[], int numBonuses)
{
int i;
//Initially set to first element
double largest = bonus[0];
//Iterating over array
for(i=0; i<numBonuses; i++)
{
//Comparing value
if(largest < bonus[i])
{
//Updating largest value
largest = bonus[i];
}
}
return largest;
}
//Function that generates report of bonus
void reportBonuses (string names[], int numEmps, double bonus[], int numBonuses)
{
int i;
cout << fixed << setprecision(2);
//Printing header
cout << “nn Report of Bonuses nn”;
cout << “n ” << left << setw(20) << ” Employee Name ” << left << setw(15) << ” Bonus “;
cout << “n ____________________________________ n”;
//Iterating over array
for(i=0; i<numBonuses; i++)
{
//Printing employee details
cout << “n ” << left << setw(20) << names[i] << left << setw(15) << bonus[i];
}
//Printing total and largest details
cout << “nnn ” << left << setw(20) << “Total of bonuses: ” << left << setw(15) << getTotalBonus(bonus, numBonuses);
cout << “nn ” << left << setw(20) << “Largest bonus: ” << left << setw(15) << getLargestBonus(bonus, numBonuses) << ” nn”;
}
__________________________________________________________________________________________
Sample Output: