Write a C++ program that asks the user to store the basic salaries of 50 employees in a 1-D array called Salaries and their overtime hours in a 1-D array called OvertimeHours (5 points). Each employee will be paid $30 for each overtime hour. The program should call a functions to do each of the following:
· Store in an array called finalSalaries the final salaries of the 50 employees. An employee’s final salary is computed as the sum of the basic salary and the earned overtime payments. Also note that a 4% income tax is deducted from the computed final salary. (5 points).
· Output an ascending sorted list of the employees’ final salaries. (5 points).
· Increase by 2% the basic salaries of the employees who worked for more than 10 overtime hours. (5 points).
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
//An employee’s final salary is computed as the sum of the basic salary and the earned overtime payments.
//Also note that a 4% income tax is deducted from the computed final salary. (5 points).
void calculateFinalSalary(float Salaries[],int OvertimeHours[],float finalSalaries[]){
//Each employee will be paid $30 for each overtime hour.
for(int i=0 ; i<50;i++){
finalSalaries[i]=Salaries[i]+OvertimeHours[i]*30;
finalSalaries[i]-=finalSalaries[i]*0.04;
}
}
//Output an ascending sorted list of the employees’ final salaries.
void ascendingSortedListEmployees(float finalSalaries[]){
int i,j;
const int n=50;
for (i = 0; i < n - 1; i++){
for (j = 0; j < n - i - 1; j++){
if (finalSalaries[j] > finalSalaries[j + 1])
{
// swap temp and elements[i]
float temp = finalSalaries[j];
finalSalaries[j] = finalSalaries[j + 1];
finalSalaries[j + 1] = temp;
}
}
}
for(int i=0;i<n;i++){
cout<<finalSalaries[i]<<"\n";
}
cout<<"\n";
}
//Increase by 2% the basic salaries of the employees who worked for more than 10 overtime hours.
void increaseByBasicSalaries(float Salaries[],int OvertimeHours[]){
for(int i=0 ; i<50;i++){
if(OvertimeHours[i]>10){
Salaries[i]*=Salaries[i]*0.02;
}
}
}
int main(){
//store the basic salaries of 50 employees in a 1-D array called Salaries
float Salaries[50];
//overtime hours in a 1-D array called OvertimeHours
int OvertimeHours[50];
//Store in an array called finalSalaries the final salaries of the 50 employees.
float finalSalaries[50];
srand((unsigned int)time(NULL));
cout<<"\nThe basic salaries of 50 employees:\n";
for(int i=0 ; i<50;i++){
//cout<<"Enter the basic salarie for employee"<<(i+1)<<": ";
Salaries[i]=(float(rand()/10.0));
int hoursWorked=(rand() % 25 + 50);
if(hoursWorked>40){
OvertimeHours[i]=hoursWorked-40;
}else{
OvertimeHours[i]=0;
}
cout <<"Employee ID: "<<(i+1) << "\n";
cout <<"Salary: "<<Salaries[i] << "\n";
cout <<"Overtime hours: "<<OvertimeHours[i] << "\n";
}
increaseByBasicSalaries(Salaries,OvertimeHours);
calculateFinalSalary(Salaries,OvertimeHours,finalSalaries);
cout<<"\nAn ascending sorted list of the employees' final salaries.\n";
ascendingSortedListEmployees(Salaries);
int k;
cin>>k;
return 0;
}
Comments
Leave a comment