Question

In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an...

In C++

Please please help..

Assignment 5 - Payroll Version 1.0

In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an array of structs to hold the employee information for all employees. If you choose to declare a separate struct for each employee, I will not deduct any points. However, I strongly recommend that you use an array of structs.

Be sure to read through Chapter 7 before you start this assignment. If you are using an array of structs, read through Chapter 8 sections 8.1 - 8.8 and 8.12.

Your job is to write a payroll program for Armadillo Automotive Group.

Warning:Input using the extractor operator (">>") is simple. However, when you mix the extractor operator with the getline function, things get tricky. Be sure that you understand how input works and review the examples of using the getline function in your textbook.

Program input

For a payroll program you would normally input the data from files, but in this first version you will input the data from the keyboard. The program input should be in 2 parts: employee master information and timesheet information.

Employee Master information

The employee master information consists of the following data:

  • employee ID number (integer value)
  • employee name (your program should handle names of up to 20 characters - may contain spaces)
  • pay rate per hour (floating-point value)
  • type of employee (0 for union, 1 for management)

Note: Use the C++ string class for the employee name. Use a C++ struct to hold the employee master information for one employee. Do not put Timesheet information in the employee master information struct.

Timesheet information

  • number of hours worked for the week (floating-point value)

Assume that there are exactly 4 employees. Your program should first input the employee master information into an array of structs. Then use a separate loop to do the payroll processing for each employee (input the employee's hours worked and calculate their pay (see the example program dialog below).

Calculations

  • Gross Pay - Union members are paid their normal pay rate for the first 40 hours worked, and 1.5 times their normal pay rate for any hours worked over 40. Management employees are paid their normal pay rate for all hours worked (they are paid for overtime hours, but they are paid at their normal hourly rate).
  • Tax - All employees pay a flat 15% income tax.
  • Net Pay is Gross Pay - Tax.

Input validation

The input should be checked for reasonable values. If a value is not reasonable, your program should print an informative error message and ask the user to re-enter the value.

  • The following data should be positive numbers (greater than 0): employee id and pay rate.
  • The following data should be non-negative (0 or larger): hours worked.
  • Employee type should be 0 or 1.

Program output - Payroll Report

Your program should gather all the required input before the payroll report is printed. The input prompts must not be mixed in with the report. If necessary, you can print the payroll report to an output file.

The payroll report should be formatted in a tabular (row and column) format with each column clearly labeled with a column heading. All dollar amounts should be formatted with 2 decimal places. Note: do not use tabs between the columns - use the setw manipulator to set the column width so that you can line up columns of numbers on the decimal point. Print one line for each transaction that contains:

  • employee ID number
  • name
  • gross pay
  • tax
  • net pay

The final lines of the payroll report should print the total amount of gross pay and total amount of net pay for the week (the total for all employees).

Your program dialog should look something like this example (user input is shown in bold).

Enter information for employee 1
Employee id: 22
Employee name: Cindy Burke
Pay rate: 15.00
Type: 0

Enter information for employee 2
Employee id: 42
Employee name: J. P. Morgan
Pay rate: 12.50
Type: 0
...
(input employee master information for last 2 employees)
...
Enter timecard information for each employee:
Hours worked for Cindy Burke: 40.0
Hours worked for J. P. Morgan: 39.5
...
(input timecard information for last 2 employees)

...
Payroll Report

ID  Name                       Gross Pay      Tax  Net Pay
22  Cindy Burke                   600.00    90.00   510.00
42  J. P. Morgan                  493.75    74.06   419.69
41  Sue Kim                       665.00    99.75   565.25
45  Ernest Chavez                 760.00   114.00   646.00

Total Gross Pay $ 2512.50
Total Net Pay   $ 2135.63

Press any key to continue . . .

Other Requirements

  1. Global variables are variables that are declared outside any function. Do not use global variables in your programs. Declare all your variables inside functions.
  2. Use the C++ string class to represent strings in your program.
  3. You should use a struct to represent the employee master information for one employee. Note: you should NOT include Timecard information in this struct. Timecard information may change from one pay period to the next while employee master information usually does not. In other words, an employee's master information and information about a specific paycheck are 2 different things and logically should not be combined in the same struct (or object).
  4. The timecard information (hours worked) does not need to be stored in an array.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

#include<iostream>
#include<string>

using namespace std;
struct employeeMaster
{
   int emplueeId;
   string employeeName;
   float payRate;
   int type;
};
void dataInput(struct employeeMaster emp[])
{
   int id,t;
   float rate;
   for(int i=0;i<4;i++)
   {
       cout<<"Enter information for employee "<<(i+1)<<endl;
       while(true)
       {
           cout<<"Employee id: ";
           cin>>id;
           if(id>0)
               break;
           else
               cout<<"Error: Id should be postive. Please reenter"<<endl;
       }
       fflush(stdin);
       cout<<"Employee Name: ";
       getline(cin,emp[i].employeeName);
       while(true)
       {
           cout<<"Pay Rate: ";
           cin>>rate;
           if(rate>0)
               break;
           else
               cout<<"Error: Rate should be postive. Please reenter"<<endl;
       }
       while(true)
       {
           cout<<"Type: ";
           cin>>t;
           if(t==0 || t==1)
               break;
           else
               cout<<"Error: Type should be 0 or 1. Please reenter"<<endl;
       }
       emp[i].emplueeId=id;
       emp[i].payRate=rate;
       emp[i].type=t;
       cout<<endl<<endl;
   }
}
float calculatePay(float h,float rate,int type)
{
   if(type==1)
   {
       return rate*h;
   }
   else
   {
       if(h<=40)
           return h*rate;
       else
       {
           return ((10*rate)+((h-10)*(1.5*rate)));
       }
   }
}
void timeCardInfoAndCalculatePay(struct employeeMaster emp[],float pay[])
{
   float hour;
   cout<<"Enter timecard information for each employee:"<<endl;
   for(int i=0;i<4;i++)
   {
       while(true)
       {
           cout<<"Hours worked for "<<emp[i].employeeName<<" : ";
           cin>>hour;
           if(hour>0)
               break;
           else
               cout<<"Error: Hour should be positve. Please reenter"<<endl;
       }
       pay[i]=calculatePay(hour,emp[i].payRate,emp[i].type);
   }
}

void display(struct employeeMaster emp[],float pay[])
{
   cout<<"Payroll Report"<<endl<<endl;
   cout.width(10); cout << std::left << "ID";
   cout.width(15); cout << std::left << "Name";
   cout.width(15); cout << std::left << "Gross Pay";
   cout.width(15); cout << std::left << "Tax";
   cout.width(15); cout << std::left << "Net Pay"<<endl;
   float tax,netPay,totalPay=0,totalNetPay=0;
   for(int i=0;i<4;i++)
   {
       tax=pay[i]*0.15;
       netPay=pay[i]-tax;
       cout.width(10); cout << std::left <<emp[i].emplueeId;
       cout.width(15); cout << std::left << emp[i].employeeName;
       cout.width(8); cout << std::right << pay[i];
       cout.width(12); cout << std::right << tax;
       cout.width(17); cout << std::right << netPay;
       cout<<endl;
       totalPay+=pay[i];
       totalNetPay+=netPay;
   }
   cout<<"\n\nTotal Gross Pay :$ "<<totalPay<<endl;
   cout<<"Total Net Pay :$ "<<totalNetPay<<endl;
}
int main()
{
   struct employeeMaster employees[4];
   float hourWorked[4];
   float totalPay[4];
   dataInput(employees);
   timeCardInfoAndCalculatePay(employees,totalPay);
   display(employees,totalPay);
}

output

Enter information for employee 1 Employee id: 22 Employee Name: Cindy Burke Pay Rate: 15.0e Type: Enter information for emploIf 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
Know the answer?
Add Answer to:
In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an...
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
  • I am really struggling with this assignment, can anyone help? It is supposed to work with...

    I am really struggling with this assignment, can anyone help? It is supposed to work with two files, one that contains this data: 5 Christine Kim # 30.00 3 1 15 Ray Allrich # 10.25 0 0 16 Adrian Bailey # 12.50 0 0 17 Juan Gonzales # 30.00 1 1 18 J. P. Morgan # 8.95 0 0 22 Cindy Burke # 15.00 1 0 and another that contains this data: 5 40.0 15 42.0 16 40.0 17 41.5...

  • The Payroll Department keeps a list of employee information for each pay period in a text...

    The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: <last name> <hourly wage> <hours worked> Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period. The report should be in tabular format with the appropriate header. Each line should contain: An employee’s name...

  • Programming Exercise 4.12 The Payroll Department keeps a list of employee information for each pay period...

    Programming Exercise 4.12 The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: <last name> <hours worked> <hourly wage> Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period. The report should be in tabular format with the appropriate header. Each line should contain:...

  • using c++ output format should look this but use employee id,hours worked and pay rate and...

    using c++ output format should look this but use employee id,hours worked and pay rate and the total should be calculated. for example employee id:1234 hours work:29.3 pay rate:16.25 administrative, office and field should be outputted as well too. Using a structure, and creating three structure variables, write a program that will calculate the total pay for thirty (30) employees. (Ten for each structured variable.) Sort the list of employees by the employee ID in ascending order and display their...

  • The Payroll Department keeps a list of employee information for each pay period in a text...

    The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period. The report should be in tabular format with the appropriate header. Each line should contain: An employee’s name The hours worked The wages paid...

  • Requesting help with the following C Program: DESIGN and IMPLEMENT a menu driven program that uses...

    Requesting help with the following C Program: DESIGN and IMPLEMENT a menu driven program that uses the following menu and can perform all menu items: Enter a payroll record for one person Display all paycheck stubs Display total gross payroll from all pay records. Quit program The program will reuse the DATE struct from the previous assignment.  You should also copy in the functions relating to a DATE. The program will create a PAYRECORD struct with the following fields: typedef struct...

  • You are to write a program that will process employees and their pay. For each employee...

    You are to write a program that will process employees and their pay. For each employee the program will read in an employee’s name and hourly pay rate. It should also read in the number of hours worked each day for 5 days and calculate his or her total number of hours worked. You must read the hours using a loop. The program should output the employee’s name, gross pay, total withholding amount and net pay. Withholding is made up...

  • C++ Linked Lists You have been hired by Employees. Inc to write an employee management system....

    C++ Linked Lists You have been hired by Employees. Inc to write an employee management system. The following are your specifications: Write a program that uses the following linked lists: bullet empId: a linked list of seven long integers to hold employee identification numbers. The array should be initialized with the following numbers: 5658845 4520125 7895122 8777541 8451277 1302850 7580489 bullet hours: a linked list of seven integers to hold the number of hours worked by each employee bullet payRate:...

  • C++ Program The Ward Bus Manufacturing Company has recently hired you to help them convert their...

    C++ Program The Ward Bus Manufacturing Company has recently hired you to help them convert their manual payroll system to a computer-based system. Write a program to produce a 1-week payroll report for only one employee to serve as a prototype (model) for the administration to review. Input for the system will be the employee’s 4-digit ID number, the employee’s name, hours worked that week, and the employee’s hourly pay rate. Output should consist of the employee’s ID number, the...

  • java Payroll class Exceptions Programming Challenge 5 of Chapter 6 required you to write a Payroll...

    java Payroll class Exceptions Programming Challenge 5 of Chapter 6 required you to write a Payroll class that calculates an employee’s payroll. Write exception classes for the following error conditions: • An empty string is given for the employee’s name. • An invalid value is given for the employee’s ID number. If you implemented this field as a string, then an empty string would be invalid. If you implemented this field as a numeric variable, then a negative number or...

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