Answer to Question #251124 in C++ for Fisiwe

Question #251124

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. 



1
Expert's answer
2021-10-14T03:44:59-0400
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);
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS