Write a program named question6c.cpp that demonstrates the use of the following functions. A C++ function named
getName()prompts the user for two string values; first name and last name and return a combination of the two as
one value. The second function getHours()calculate employee’s weekly pay, it must receive one argument,
fullName, a stringvariable and a floatvalue for the rate. It must then prompt the user for hours worked for each
day of the week, i.e. Monday – Friday and calculates the weekly pay. Employees who have worked more than 40 hours
that week will receive a bonus of 10% and those who have worked less than 40 hour will receive 10% less pay for that
week.
using namespace std;
/*
Write a program named question6c.cpp that demonstrates the use of the following functions.
A C++ function named getName() prompts the user for two string values; first name and last name and return a combination of the two as
one value.
The second function getHours() calculate employee’s weekly pay, it must receive one argument,
fullName, a stringvariable and a float value for the rate.
It must then prompt the user for hours worked for each day of the week, i.e. Monday – Friday and calculates the weekly pay.
Employees who have worked more than 40 hours that week will receive a bonus of 10% and those who have worked less than 40 hour will receive 10% less pay for that
week.
*/
string getName(void)
{
string FirstName,LastName,Name;
cout<<"\n\tEnter First Name: "; cin>>FirstName;
cout<<"\n\tEnter Last Name: "; cin>>LastName;
Name = FirstName + " " + LastName;
return(Name);
}
void getHours(string Name, float Rate)
{
string Days[] = {"Monday","Tuesday","Wednesday","THursday","Friday"};
float Hours[7], TotalHours=0,TotalPay;
int n;
cout<<"\n\tPay Calculation for employee: "<<Name;
for(n=0;n<5;n++)
{
Hours[n]=-1;
while(Hours[n]<0 || Hours[n]>24)
{
cout<<"\n\tEnter hours worked on "<<Days[n]<<" (0 to 24 hours) : "; cin>>Hours[n];
}
TotalHours = TotalHours+Hours[n];
}
TotalPay = TotalHours*Rate;
if(TotalHours<40) TotalPay = 0.9*TotalPay;
if(TotalHours>=40) TotalPay = 1.1*TotalPay;
cout<<"\n\tTotal hours worked = "<<TotalHours;
cout<<"\n\tTotal Pay = "<<TotalPay;
}
int main()
{
string Name;
Name = getName();
cout<<"\n\tName: "<<Name;
getHours(Name,20);
return(0);
}
Comments
Leave a comment