Question

In: Computer Science

Assignment: (Save this file as A7-1.cpp) Write a program to calculate the gross pay for an...

Assignment: (Save this file as A7-1.cpp) Write a program to calculate the gross pay for an assembly line employee that works for a company that pays all assembly line workers $7.50 hour. Any employee that works over 40 hours per week is compensated by being paid time-and-one-half for each hour over 40. a. Use main( ) as the driver function. Allow the user to compute as many employees as desired. b. Write the function getName( ) that prompts for the name of the employee and returns it to main( ). c. Write the function getTime( ) that prompts the user for the time worked for that week and returns this value back to main( ). Do not allow the user to enter a negative value for the hours. Display an error message and keep prompting until a valid value is entered. d. Write the function computePay( ) that calculates the gross pay of the employee using the time entered by the user and returns the calculated gross pay back to main( ). e. Write the function displayPay( ) that takes as input the employee’s name, the gross pay and time worked from main( ) and displays these values.

Solutions

Expert Solution

ANSWER:

  • I have provided the properly commented  and indented code so you can easily copy the code as well as check for correct indentation.
  • I have provided the output image of the code so you can easily cross-check for the correct output of the code.
  • Have a nice and healthy day!!

CODE

// import libraries
#include <bits/stdc++.h>
// using namespace
using namespace std;

// b. function getName
string getName(){
        // prompting user to enter employee name
        cout<<"Please enter name of the employee: ";
        // storing name in variable name
        string name;

        // taking input
        cin>>name;

        // returning name
        return name;
}

// c. function getTime
float getTime(){
        // loop till input time is correct
        while(1){
                // prompting user to enter employee name
                cout<<"Please enter working hours of the employee: ";

                // storing result in float hours
                float hours;
                // taking input
                cin>>hours;

                // checking if hours is correct
                if(hours>=0){
                        // return hours
                        return hours;
                }

                // otherwise prompt user to enter again
                cout<<"Negative working hours, Retry..."<<endl;
        }
}

// d. function computePay, to compute gross according to hours
float computePay(float hours){
        // defining variable grossPay
        float grossPay;

        // payment calculation
        if(hours<=40){
                grossPay = hours * 7.5;
        } // otherwise > 40
        else{
                // 7.5 till 40 hours and for remaining hours 7.5*1.5
                grossPay = (40 * 7.5) + (grossPay-40)*7.5*1.5;
        }

        // return grossPay
        return grossPay;
}

// e. function displayPay, to display all details of employee
void displayPay(string name, float hours, float grossPay){
        // displaying result
        cout<<name<<" gross pay for working "<<hours<<" hours is: $"<<grossPay;
        cout<<endl;
}

// a. function main, Driver Function
int main(){
        // while loop, till user want to enter employee details
        // defining variable for run for more employee
        int more = 1;

        while(more){
                // b. getName function call to ask employee name
                string name = getName();

                // c. getTime function call to ask +ve working hours
                float hours = getTime();

                // d. computePay function call to fetch grossPay
                float grossPay = computePay( hours);

                // e. diplay function to display result
                displayPay(name,hours,grossPay);

                // prompting user to enter more employee or not
                cout<<"Do you want to continue <1,0>: ";
                cin>>more;
        }

}

OUTPUT IMAGE


Related Solutions

Need this program Using Classes , Objects, Save to file, and Printbill Simple python assignment Write...
Need this program Using Classes , Objects, Save to file, and Printbill Simple python assignment Write a menu-driven program for Food Court. (You need to use functions!) Display the food menu to a user (Just show the 5 options' names and prices - No need to show the Combos or the details!) Ask the user what he/she wants and how many of it. (Check the user inputs) AND Use strip() function to strip your inputs. Keep asking the user until...
Write a program that reads a file (provided as attachment to this assignment) and write the...
Write a program that reads a file (provided as attachment to this assignment) and write the file to a different file with line numbers inserted at the beginning of each line. Such as Example File Input: This is a test Example File Output 1. This is a test. (Please comment and document your code and take your time no rush).
Write a C++ program based on the cpp file below ++++++++++++++++++++++++++++++++++++ #include using namespace std; //...
Write a C++ program based on the cpp file below ++++++++++++++++++++++++++++++++++++ #include using namespace std; // PLEASE PUT YOUR FUNCTIONS BELOW THIS LINE // END OF FUNCTIONS void printArray(int array[], int count) {    cout << endl << "--------------------" << endl;    for(int i=1; i<=count; i++)    {        if(i % 3 == 0)        cout << " " << array[i-1] << endl;        else        cout << " " << array[i-1];    }    cout...
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++...
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++ Rules: -Use fork(), exec(), wait(), and exit() _______________________________________________________________________________________________________________________________________________ -A line of input represents a token group. -Each token group will result in the shell forking a new process and then executing the process. e.g. cat –n myfile.txt // a token group -Every token group must begin with a word that is called the command(see example above). The words immediately following a command are calledarguments(e.g....
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++...
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++ Rules: -Use fork(), exec(), wait(), and exit() _______________________________________________________________________________________________________________________________________________ -A line of input represents a token group. -Each token group will result in the shell forking a new process and then executing the process. e.g. cat –n myfile.txt // a token group -Every token group must begin with a word that is called the command(see example above). The words immediately following a command are calledarguments(e.g....
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two output tiles. One file listing out all boys names, and the other file listing out all girls name. CODE: (teacher gave some of the code below use it to find the answer please String B is the boy names String E is girl names) import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** This program reads a file with numbers, and writes the numbers...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two output tiles. One file listing out all boys names, and the other file listing out all girls name. CODE: (teacher gave some of the code below use it to find the answer please String B is the boy names String E is girl names) import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** This program reads a file with numbers, and writes the numbers...
For this assignment, write a program that will calculate the quiz average for a student in...
For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
For this assignment, write a program that will calculate the quiz average for a student in...
For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
Write a C++ program that start the assignment by creating a file named pointerTasks.cpp with an...
Write a C++ program that start the assignment by creating a file named pointerTasks.cpp with an empty main function, then add statements in main() to accomplish each of the tasks listed below. Some of the tasks will only require a single C++ statement, others will require more than one. For each step, include a comment in your program indicating which step you are completing in the following statement(s). The easiest way to do this is copy and paste the below...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT