Question

Create a Text file containing the following data (without the headings): Name            Wage      Hours Callaway, G 16.00       40 Hanson, P     15.00      48 Lasard, D      16.50      35 Stillman,...

Create a Text file containing the following data (without the headings):

Name            Wage      Hours
Callaway, G 16.00       40

Hanson, P     15.00      48

Lasard, D      16.50      35

Stillman, W   18.00      50

Write a C++ program that uses the information in the file to produce the following pay report for each employee:

Name, Pay Rate, Hours, Regular Pay, Overtime Pay, Gross Pay      

Compute regular pay as  any hours worked up to and including 40 hours multiplied by the pay rate. Compute overtime pay as any hours worked above 40 hours times a pay rate of 1.5 multiplied by the regular rate. The gross pay is the sum of regular and overtime pay. At the end of the report, the program should display the totals of the regular, overtime and gross pay columns.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;

int main()
{
   ifstream inFile;
   inFile.open("employeeInfo.txt");
   string firstName,lastnamae,fullName;
   double wage,hour;
   double regularPay,overtimePay,grossPay;
   if(!inFile)
   {
       cout<<"Error! File not found..Exiting..."<<endl<<endl;
       return 1;
   }
   cout<<fixed;
   cout<<setprecision(2);
   cout.width(15);cout << std::left << "Name";
   cout.width(15);cout << std::right << "Pay Rate";
   cout.width(15);cout << std::right << "Hours";
   cout.width(15);cout << std::right << "Regular Pay";
   cout.width(15);cout << std::right << "Overtime Pay";
   cout.width(15);cout << std::right << "Gross Pay"<<endl;
   while(inFile>>firstName>>lastnamae>>wage>>hour)
   {
       fullName=firstName+" "+lastnamae;
       if(hour>40)
       {
           regularPay=40*wage;
           overtimePay=(hour-40)*(1.5*wage);
       }
       else
       {
           regularPay=hour*wage;
           overtimePay=0;
       }
       cout.width(15);cout << std::left << fullName;
       cout.width(15);cout << std::right << wage;
       cout.width(15);cout << std::right << hour;
       cout.width(15);cout << std::right << regularPay;
       cout.width(15);cout << std::right << overtimePay;
       cout.width(15);cout << std::right << (regularPay+overtimePay)<<endl;
   }
   return 1;
}

output

Hours Regular Pay Overtime Pay Pay Rate Gross Pay Name Callaway,G Hanson, P Lasard, D Stillman, W Press any key to continue .

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Answer #2




 Hours Callaway, G 16.00       40 Hanson, P     15.00      48 Lasard, D      16.50      35 Stillman,...

answered by: roberto
Add a comment
Know the answer?
Add Answer to:
Create a Text file containing the following data (without the headings): Name            Wage      Hours Callaway, G 16.00       40 Hanson, P     15.00      48 Lasard, D      16.50      35 Stillman,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT