1) Develop a C++ program that will determine the gross pay for each of several employees. The company pays "straight-time" for the first 40 hours worked by each employee amd pays "time-and-a half" for all hours worked in excess of 40 hours. You are given a list of employees of the company, the number of hours each employee worked last night and the hourly rate of each employee. Your program should input this information for each employeee and should determine and display the employee's gross pay.
Enter hours worked (-1 to end): 39
Enter hourly rate of the worker ($00.00): 10.00
Salary is: $390.00
Enter hours worked (-1 to end): 40
Enter hourly rate of the worker ($00.00): 10.00
Salary is: $400.00
Enter hours worked (-1 to end): 41
Enter hourly rate of the worker ($00.00): 10.00
Salary is: $415.00
I tried to found the math expression for this one "Hours * Hourly rate = Salary", but it didn't apply for "41 hours"...
2) Write a C++ program that utilizes looping and the tab escape sequence \t to print the following table of values:
You need to come up with a way of expressing the idea that the first 40 hours get one salary rate, and all hours after that get a different rate.
If I tell you that someone worked 50 hours, how many hours of that is at the first pay rate and how many is at the second pay rate? How did you work that out?
The first 40 hours get paid at one rate. All following hours get paid at another rate.
If someone works 50 hours, how many hours of that are paid at the first rate? If you can't tell me that, you're really going to struggle as a programmer.
#include <iostream>
usingnamespace std;
namespace global
{
bool executing_code ;
}
void employee() ;
int main()
{
global::executing_code = true ;
while ( global::executing_code )
{
employee() ;
}
return 0 ;
}
void employee()
{
double salary ;
int hours ;
int overtime ;
double rate ;
int work_limit = 40 ; // adjustable in the source code if desired
cout << "Enter hours worked (-1 to end): " ;
cin >> hours ;
if (hours < 0) { global::executing_code = false ; return ; }
cout << "Enter hourly rate of the worker ($00.00): " ;
cin >> rate ;
overtime = hours - work_limit ;
if (overtime > 0)
{
salary = ( work_limit * rate ) + ( overtime * rate * 1.5 ) ;
}
else { salary = hours * rate ; }
cout << "Salary is: $" << salary << "\n\n" ;
return;
}
I am not entirely sure if this is the correct use for a namespace, but it was a quick bandage to figure out how to make the employee() function change a variable that is used outside of this function. Note that it is my first time using a namespace for anything particular.
you don't need a namespace, just doing bool executing_code outside of any scope/function/class/etc will make it global, for extra safety you can then refer to it with ::executing_code, so if you make a second variable called executing_code by accident in one of your functions, it will use the global one instead of the local one.