Language of implementation is C++ Write a program for calculating the weekly sal
ID: 3813254 • Letter: L
Question
Language of implementation is C++ Write a program for calculating the weekly salary for the employees of a company. The company currently has 3 employees (Carla, Steve, and Bob) but intends to expand soon to have 20 employees. Every employee has a unique ID in the range 101 – 120. Employees Carla, Steve, and Bob have been assigned 101, 102, and 103 respectively. Their hourly pay rates are $14, $12, and $15. You will demonstrate your program under changing scenarios for a two week period in the life of the company as follows. a. Your program must store the information about employee names, ids, pay rate, hours worked, and the total weekly salary using five different arrays. b. The program must ask the user for the hours worked by each employee and use this information to calculate the weekly salary. c. Display the id, name, pay rate, hours worked, and the weekly salary in a suitable format. d. At the start of the second week, new employees Rachael and Adam are hired with rates at $10.50. e. Give Carla a raise to $14.50. f. Steve quits his job. Hint: You must compact the arrays to avoid wastage of space. g. For the second week repeat steps b and c and display your results in the same format used earlier. I'm confused on how to start this but I do know I need to create an array. I think part f, compact the arrays, is one of the bigger things throwing me off.
Explanation / Answer
c++ code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n = 20;
string names[n+1];
int ID[n+1];
double payrates_hourly[n+1];
double hoursworked[n+1];
double total_weekly_salary[n+1];
//Week 1
cout << "Week 1 ";
names[0] = "Carla"; payrates_hourly[0] = 14;
names[1] = "Steve"; payrates_hourly[1] = 12;
names[2] = "Bob"; payrates_hourly[2] = 15;
for (int i = 0; i < n+1; ++i)
{
ID[i] = 101 + i;
}
for (int i = 3; i < n; ++i)
{
cout << "Enter the name of employee with ID = " << ID[i] << endl;
cin >> names[i];
}
for (int i = 3; i < n; ++i)
{
cout << "Enter the Hourly pay rate of employee with ID = " << ID[i] << endl;
cin >> payrates_hourly[i];
}
for (int i = 0; i < n; ++i)
{
cout << "Enter the Hours worked by employee with ID = " << ID[i] << endl;
cin >> hoursworked[i];
}
cout << "ID " << " " << " Name " << " " << "Payrates_hourly" << " " << "Hoursworked" << " " << "Total_weekly_salary" << endl;
for (int i = 0; i < n; ++i)
{
total_weekly_salary[i] = (payrates_hourly[i])*(hoursworked[i]);
}
for (int i = 0; i < n; ++i)
{
cout << ID[i] << " " << names[i] << " " << payrates_hourly[i] << " " << hoursworked[i] << " " << total_weekly_salary[i] << endl;
}
cout << " Week 2 ";
//Week 2 Adam-> 102 and Rachael -> 121
payrates_hourly[0] = 14.5;
names[n] = "Rachael"; names[1] = "Adam"; payrates_hourly[1] = 10.5; payrates_hourly[n] = 10.5;
for (int i = 0; i < n+1; ++i)
{
cout << "Enter the Hours worked by employee with ID = " << ID[i] << endl;
cin >> hoursworked[i];
}
cout << "ID " << " " << " Name " << " " << "Payrates_hourly" << " " << "Hoursworked" << " " << "Total_weekly_salary" << endl;
for (int i = 0; i < n+1; ++i)
{
total_weekly_salary[i] = (payrates_hourly[i])*(hoursworked[i]);
}
for (int i = 0; i < n+1; ++i)
{
cout << ID[i] << " " << names[i] << " " << payrates_hourly[i] << " " << hoursworked[i] << " " << total_weekly_salary[i] << endl;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.