C++ Programming A company employs N employees - value of N is input by the user
ID: 3761000 • Letter: C
Question
C++ Programming
A company employs N employees - value of N is input by the user such that N >= 10 [Validate Input].
Every employee is assigned an employee ID that ranges from 1 to N.
E.g. Employee1 is assigned ID 1, Employee_N is assigned ID N
An employee with odd employee_ID is paid hourly
The program should compute expense to the company from daily waged and hourly waged employees individually.
Hence, create two variable in main function DailyWageExp and HourlyWageExp. The expenses are computed inside an overloaded function ComputeExpenses
Inside ComputeExpenses, ask for either the Number of days or Number of hours that the employee has worked for.
Function ComputeExpenses receives 2 arguments. First argument is either DailyWageExp or HourlyWageExp passed by reference.
Second argument is either $18.78 or $50 passed by value.
An employee with even employee ID is paid daily
Hourly Pay 1 hour = $18.78 Daily Pay 1 Day = $50
Output: The program should output expenses from the daily waged and hourly waged employees individually. In addition print the total expense to the company The program must use Function Overloading and Pass by reference as specified in the problem.
Explanation / Answer
#include<iostream>
#include <cstdlib>
using namespace std;
int *arr;
int n;
void ComputeExpenses(double *,int);
//void ComputeExpenses(double *,double);
void ComputeExpenses (double *y,int p)
{
int days,i,total=0;
for(i=0;i<n;i++)
{ if(arr[i]%2==0){
cout<<"Enter no of days employee works"<<endl;
cin>>days;
total=total+days*p;
}
}
*y=total;
}
void ComputeExpenses (double *x,double p)
{
int hours,i;
double total=0;
cout<<"The number of hours employee work"<<endl;
cin>>hours;
for(i=0;i<n;i++)
{if(arr[i]%2!=0){
cout<<"Enter no of hours employee works"<<endl;
cin>>hours;
total=total+hours*p;
}}
*x=total;
}
int main()
{
int i;
double DailyWageExp=0, HourlyWageExp=0;
cout<<"Enter Number of employees"<<endl;
cin>>n;
while(n<10)
{
cout<<"Invalid input. Enter greater than or equal to 10"<<endl;
cin>>n;
}
arr=(int *)(malloc(sizeof(int)*n));
for(i=0;i<n;i++)
{
arr[i]=i+1;
}
ComputeExpenses(&HourlyWageExp,18.78);
//cout<<arr[0];
cout<<"Hourly Expenses "<<HourlyWageExp<<"$"<<endl;
ComputeExpenses(&DailyWageExp,50);
cout<<"Daily Expenses "<<DailyWageExp<<"$"<<endl;
cout<<"Total Expenses "<<DailyWageExp+HourlyWageExp;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.