Question

"Multiple Function Returns Using Memory Pointers" Contents of employee.dat... copy paste and create a file (employee.dat)...

"Multiple Function Returns Using Memory Pointers"

Contents of employee.dat... copy paste and create a file (employee.dat)

123-45-6789 Kirk James 44.7 88.99 0.0175
124-89-0007 Bond Jane 45.6 65.75 0.04
405-77-8911 Puff Blossom 40 33.88 0.03
405-10-9871 Puff Buttercup 41.2 45.66 0.047
223-03-8761 Puff Bubbles 37.8 33.44 0.015
980-11-2201 Joneski Kasey 23.1 10.77 0.033
115-88-7619 Crooke I.M.A. 25.4 88.75 0.02
777-00-1232 Smith Alias 43.5 22.3 0.034
345-89-0022 DeMann Stan 56.7 29.45 0.065
210-37-1192 Jones Jeane 48.9 20.33 0.025
103-22-4321 Smith Alias 33.5 19.67 0.063

C++

The problem with using functions is that C++, by default will return not more than one value to the calling routine (i.e. main( ) for example). Using pointers, we can “return” more than one value to that calling routine. This allows us to “farm” out intermediate calculations to functions for later use in the logic and then pass those values on to other functions as needed.

In this exercise, we will read in a data file of employees (file is furnished to you, “employee.dat”):

1. Employee SSN

2. Employee Last Name

3. Employee First Name

4. Hours Worked

5. Pay Per Hour

6. Personal Income Tax Rate

Your assignment’s logic is to:

1. Read in the records from the file,

2. Pass the Hours Worked, Pay Per Hour, Personal Income Tax Rate to a single function to determine:

3. Whether or not overtime pay is computed (anything over 40 hours is overtime at 1.5 times the regular pay). Compute any overtime pay at 1.5 times pay rate

4. Compute the regular pay at regular hours (40 hours or less)

5. Compute the gross pay (Regular Pay plus any overtime pay)

6. Compute the personal income taxes withheld

7. Compute Net Pay (gross pay minus personal income taxes withheld)

8. Pass ALL these values BACK to the main calling routine from this one function.

9. Display:the Employee SSN, Last Name, First Name, Total Hours, Regular Hours, Overtime Hours (if any), Pay Per Hour, Personal Income Tax Rate, Regular Pay, Overtime Pay (if any), Gross Pay, Withheld Income Taxes, Net Pay.

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

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
using namespace std;
void readFile(string ids[], string fnames[], string lnames[], double hoursWork[], double payRate[],double taxrate[], int cnt);
void calculateGrossNetPay(double* hoursWork, double* payRate, double* normalPay, double* overtimePay,double* grosspay, double* taxRate,double* taxWithHeld,double* netPay,int cnt);

void displayReport(string* ids, string* fnames,string* lnames, double* hoursWork, double* payRate, double* grossPay,double* normalPay,double* overtimePay,double* taxRate,double* taxWithHeld,double* netpay, int cnt);
int main()
{
int choice;
int cnt = 0;
string* ids;
string* fnames;
string* lnames;
  
double* hoursWork;
double* payRate;
double* taxRate;
double* normalPay;
double* overtimePay;
double* taxWithHeld;
double* grossPay;
  
double* netpay;
//defines an input stream for the data file
ifstream dataIn;

string id;
           double hw;
string fname,lname;
double pay,taxR;
dataIn.open("employee.dat");
//checking whether the file name is valid or not
if (dataIn.fail()) {
cout << "** File Not Found **";
exit(0);
}
else {
while (dataIn >> id >> fname >>lname>> hw >> pay>>taxR) {
cnt++;
}
dataIn.close();

// Creating array dynamically
ids = new string[cnt];
fnames = new string[cnt];
lnames = new string[cnt];
hoursWork = new double[cnt];
normalPay = new double[cnt];
overtimePay = new double[cnt];
grossPay=new double[cnt];
payRate = new double[cnt];
taxRate = new double[cnt];
taxWithHeld=new double[cnt];
readFile(ids,fnames,lnames,hoursWork,payRate,taxRate,cnt);

calculateGrossNetPay(hoursWork, payRate,normalPay,overtimePay,grossPay, taxRate,taxWithHeld,netpay, cnt);

displayReport(ids, fnames,lnames, hoursWork, payRate, grossPay,normalPay,overtimePay,taxRate,taxWithHeld, netpay, cnt);
  
}
return 0;
}
void readFile(string ids[], string fnames[], string lnames[],double hoursWork[], double payRate[],double taxrate[], int cnt)
{
//defines an input stream for the data file
ifstream dataIn;
string id;
   double hw;
string fname,lname;
double pay,tax;
dataIn.open("employee.dat");
  
for (int i = 0; i < cnt; i++) {
dataIn >> id >> fname >>lname>> hw >> pay>>tax;
ids[i] = id;

fnames[i] = fname;
  
lnames[i] = lname;
  
hoursWork[i] = hw;

payRate[i] = pay;
  
taxrate[i]=tax;
  
}
dataIn.close();
  
}
void calculateGrossNetPay(double* hoursWork, double* payRate, double* normalPay, double* overtimePay,double* grosspay, double* taxRate,double* taxWithHeld,double* netPay,int cnt)
{
for (int i = 0; i < cnt; i++) {
if(hoursWork[i]<=40)
{
    normalPay[i]=hoursWork[i]*payRate[i];
   }
   else if(hoursWork[i]>40)
   {
      normalPay[i]=40*payRate[i];
      overtimePay[i]=(hoursWork[i]-40)*1.5*payRate[i];
   }
   grosspay[i]=normalPay[i]+overtimePay[i];
   taxWithHeld[i]=taxRate[i]*grosspay[i];
   netPay[i]=grosspay[i]-taxWithHeld[i];
}

}
void displayReport(string* ids, string* fnames,string* lnames,double* hoursWork, double* payRate, double* grossPay,double* normalPay,double* overtimePay,double* taxRate,double* taxWithHeld,double* netpay, int cnt)
{

  
for (int i = 0; i < cnt; i++) {
cout << ids[i] << "\t" << fnames[i]<<"\t"<<lnames[i] << "\t";
if(hoursWork[i]<=40)
{
   cout<<hoursWork[i]<<"\t";
       }
       else
       {
           cout<<"40\t"<<hoursWork[i]-40<<"\t";
       }
      
       cout<< payRate[i] <<"\t"<<normalPay[i]<<"\t"<<overtimePay[i]<< "\t" << grossPay[i] <<"\t"<<payRate[i]<<"\t"<<taxWithHeld[i]<< "\t" << netpay[i] << endl;
}
  
}

___________________________

Output:

CProgram Files (x86)\Dev-Cpp MinGW641bin\ReadFilelDFirstNameLastNameHoursWorkedPayRateTaxRate.exe 23-45-6789 124-89-000? 05-7

__________________Thank You

Add a comment
Know the answer?
Add Answer to:
"Multiple Function Returns Using Memory Pointers" Contents of employee.dat... copy paste and create a file (employee.dat)...
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
  • 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...

  • J Inc. has a file with employee details. You are asked to write a C++ program...

    J Inc. has a file with employee details. You are asked to write a C++ program to read the file and display the results with appropriate formatting. Read from the file a person's name, SSN, and hourly wage, the number of hours worked in a week, and his or her status and store it in appropriate vector of obiects. For the output, you must display the person's name, SSN, wage, hours worked, straight time pay, overtime pay, employee status and...

  • Python 3 Question Please keep the code introductory friendly and include comments. Many thanks. Prompt: The...

    Python 3 Question Please keep the code introductory friendly and include comments. Many thanks. Prompt: The owners of the Annan Supermarket would like to have a program that computes the weekly gross pay of their employees. The user will enter an employee’s first name, last name, the hourly rate of pay, and the number of hours worked for the week. In addition, Annan Supermarkets would like the program to compute the employee’s net pay and overtime pay. Overtime hours, any...

  • Lenny Florita, an unmarried employee, works 47 hours in the week ended January 12. His pay rate is $12 pe...

    Lenny Florita, an unmarried employee, works 47 hours in the week ended January 12. His pay rate is $12 per hour, and his wages have deductions for FICA Social Security, FICA Medicare, and federal income taxes. He claims four withholding allowances. Compute his regular pay, overtime pay (Lenny earns $18 per hour for each hour over 40 per week), and gross pay. Then compute his FICA tax deduction (6.2% for the Social Security portion and 1.45% for the Medicare portion),...

  • The Excel file Payroll Data provides hourly salaries for a group of employees. Create an Excel...

    The Excel file Payroll Data provides hourly salaries for a group of employees. Create an Excel template that allows the user to select an employee by employee ID, enter the number of regular hours and overtime hours worked, and display a payroll summary with the employee name, gross pay, federal tax, state tax, Social Security, Medicare withholding deductions, and net pay. Assume that the federal tax rate is 11%, the state tax rate is 2.385%, Social Security withholding is 6.2%,...

  • Lenny Florita, an unmarried employee, works 50 hours in the week ended January 12. His pay...

    Lenny Florita, an unmarried employee, works 50 hours in the week ended January 12. His pay rate is $12 per hour, and his wages have deductions for FICA Social Security, FICA Medicare, and federal income taxes. He claims four withholding allowances. Compute his regular pay, overtime pay (Lenny earns $18 per hour for each hour over 40 per week), and gross pay. Then compute his FICA tax deduction (6.2% for the Social Security portion and 1,45% for the Medicare portion),...

  • employees.txt Instructions You will be using Eclipse for all assignments in this course. You can download...

    employees.txt Instructions You will be using Eclipse for all assignments in this course. You can download Eclipse from the Virtual Desktop. Please write a Java program that follows the instructions below. There are two files to download. AvaCam Inc. is interested in the electronic computation of their payroll. They have reached out, and you have agreed to write a program to help them. They have sent you the file employees.txt (right-click to download the file). Store this file in the...

  • Lenny Florita, an unmarried employee, works 47 hours in the week ended January 12. His pay rate is $12 per hour, a...

    Lenny Florita, an unmarried employee, works 47 hours in the week ended January 12. His pay rate is $12 per hour, and his wages have deductions for FICA Social Security, FICA Medicare, and federal income taxes. He claims four withholding allowances. Compute his regular pay, overtime pay (Lenny earns $18 per hour for each hour over 40 per week), and gross pay. Then compute his FICA tax deduction (6.2% for the Social Security portion and 1.45% for the Medicare portion)....

  • If the wages are- But less | At least than SINGLE Persons-WEEKLY Payroll Period And the...

    If the wages are- But less | At least than SINGLE Persons-WEEKLY Payroll Period And the number of withholding allowances claimed Is- 1 | 2 | 3 4. 7. | The amount of Income tax to be withheld is- 0 | 5 6 8 9 10 $600 610 620 630 640 650 660 670 680 690 $610 620 630 640 650 660 670 680 690 នៗond no No o pond ឧ០០០ co-on d © No Exercise 11-18A Computing gross and...

  • Lenny Florita, an unmarried employee, works 46 hours in the week ended January 12. His pay...

    Lenny Florita, an unmarried employee, works 46 hours in the week ended January 12. His pay rate is $13 per hour, and his wages have deductions for FICA Social Security, FICA Medicare, and withholding allowances. Compute his regular pay, overtime pay (Lenny earns $20 per hour for each hour over 40 per week), and gross pay. Then compute his FICA tax deduction (6.2% for the Social Security portion and 1.45% for the Medicare portion), income tax deduction (use the wage...

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