Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program with an overloaded function to determine the salary of an ho

ID: 3665785 • Letter: W

Question

Write a C++ program with an overloaded function to determine the salary of an hourly worker, who gets time and a half for hours over 40. Have the user input the hourly rate and the hours worked. If the hours are over 40, calculate regular hours and overtime hours, and then call the function with arguments for hourly rate, regular hours, and overtime hours. If the hours are not over 40, call the overloaded version of the function with arguments for hourly rate and just all the regular hours. Both versions of the function should calculate (with different formulas) and return the salary to main to print with 2 decimal places. Use proper forms, function prototypes, etc.

Explanation / Answer

#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <iostream.h>

using namespace std;


int main(void)
{
   char *empname, *test, *final_output;
   float hours=0, pay_rate=0, gross=0, net=0;

//loop
   do {
       /*-- get first & last name --*/
       cout<<"Please Enter Your Name ";
       cin>>empname;

       /*--
           get pay rate with error checking on
           null and 0 values
       --*/
       do {
           cout << "Pay Rate: ";
           cin >> test;
           if (test == NULL)
               cout << "Invalid pay rate.";
           else if(atof(test) != 0)
               break;
           else
               cout << "Invalid pay rate.";          
       } while (1);
       pay_rate=atof(test);
          
       /*--
           get hours worked with error checking on
           null and 0 values
       --*/
       do {
           cout << "Hours Worked: ";
           cin >> test;
           if (test == NULL)
               cout << "Invalid amount of hours.";
           else if(atof(test) != 0)
               break;
           else
               cout << "Invalid amount of hours.";
       } while (1);
       hours=atof(test);

       /*-- calculate values --*/      
       gross=hours*pay_rate;

       /*-- set out precision --*/
       cout.precision(2);
       cout.setf(ios::fixed | ios::showpoint);
      
       /*-- create output --*/
       sprintf(final_output," %s %s ssn(%s) ------------------------------ ",
               empname);
       cout << final_output;
       cout << "Gross: " << gross << endl;

       /*-- do another? --*/
       cout << "Calculate Another? (y/n)?";
       cin >> test;

       /*-- check first value of string for y/Y --*/
   } while (!strncasecmp(test,"y",1));

   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote