Question
Program 10. C++ *Your program should handle any number of employees up to 100. The employee master data will be input from a file (1
Program 10.
C++
*Your program should handle any number of employees up to 100. The employee master data will be input from a file (1 to 100 employees).
*Employee timecard information (employee id and hours worked) will be in another input file. Some employees may not have a timecard.
*Use a C-string (character array) instead of a C++ string object to store an employee name. You should use C-strings in your employee class and the rest of the program to hold the names.
One of the main goals of this assignment is to give you experience working with partially-filled arrays. Use an array to store the employee master data.
Important Note: When you are reading input from a file using an end-of-file loop, it is critical that the last line of the file be terminated with a newline character. The description of the end-of-file loop and all the example code in the textbook assume that the last line of input is terminated with a newline. The examples may not work correctly for files that are missing a newline at the end.
By convention all files should be terminated with a newline character.
Employee class
You will use your employee class from the previous programming assignment. Change the member variable for the employee name so that you use a C-string instead of a C++ string object. Your C-string should be able to hold names up to 20 characters in length. Then modify your member functions as required to work with the C-string.
Program input
The program input consists of two files - a master file and a transaction file. Your code must work for the 2 input files provided. You may also want to test your program with other input data.
Master file
The master file has one line of input per employee containing:
*employee ID number *name of up to 20 characters *pay rate per hour *number of dependents *type of employee (0 for a union, 1 for management) *gender of employee (M or F)
Notes: This file contains one extra piece of data at the end of each line - a single character ('M' or 'F'). You can ignore this data. Validation for the data in this file is done in the set member function of the Employee class.
This file is ordered by ID number. Your code should work for any number of employees up to 100 (use an end-of-file loop to read this file). You can assume that there is exactly one space between the employee ID number and the name. You can also assume that the name occupies 20 columns in the file.
Transaction file (weekly timesheet information)
The transaction file has one line for each employee who worked containing:
*employee id number (an integer greater than 0) *number of hours worked for the week (a floating-point value of 0.0 or greater) This file may have any number of transactions and may be in any order.
Calculations
*Gross Pay - Union members are paid 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 not paid extra for hours over 40). *Tax - All employees pay a flat 15% income tax. *Insurance - The company pays for insurance for the employee. Employees are required to buy insurance for their dependents at a price of $20 per dependent. *Net Pay is Gross Pay minus Tax minus Insurance. Payroll Processing
Since the employee master information and the timecard information (hours worked) are not input in the same order, and the total number of employees likely will be different than the number of timesheets, trying to use parallel arrays for this assignment will get very tricky. A better strategy might be to:
- read the employee master information into an array (count the number of employees as you read)
- for each timecard record in the transaction file, try to look up the matching employee in the employee array and process as required.
Program output
The program output will consist of two reports:
Error and Control Report
This report can be printed on the screen or alternatively can be printed to a file.
*Prints the transaction file input lines for which there is no matching master file record or the hours worked is invalid (a negative number). These lines should be ignored (no further processing is done for the line) and processing continues with the next transaction. *Prints the total number of transactions that were processed correctly during the run. Payroll Report
This report should be printed to a file. It should not be printed on the screen. The payroll report should be printed in a tabular (row and column) format with each column clearly labeled. Print one line for each transaction that contains:
*employee ID number *name *tax *insurance *gross pay *net pay All dollar amounts should be displayed with 2 decimal places. The decimal points should line up vertically in your columns (use the setw() manipulator when printing columns).
The final line of the payroll report should print the total amount of gross pay and total amount of net pay for the week.
Requirements/Hints:
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) You can assume that the Master file does not contain errors (error checking is done by another program). Error checking for the Transaction file is described in the Error and Control Report. You can download sample files here: master10.txt trans10.txt Your program must work correctly for these files.
Maybe the best way to copy a file to your computer is to right-click on the link, then choose "Save As" or "Save Link As" from the popup menu. Optionally you may be able to open the text file in your browser and select "Save As" or "Save Page As" from your browser menu.
If you create your own test files in a text editor, be sure to press the enter key after the last line of input and before you save your text. If you choose to copy the text from my sample file and paste it into a text editor, be sure to press the enter key after the last line of input and before you same your text.
3)Use C-strings (not the C++ string class) to represent strings in your program. 4)You should use a class to represent the master file information for one employee. 5)The Payroll Report must be written to a file. 6)The master file information should be read into an array. 7)You do not need to store the transaction information in an array. You can read each transaction (timecard information), look up the matching employee id in the employee master array, and then calculate and print the paycheck information. 8)Your program might be structured similar to this example program: itemclass.htm 9)Notes on reading c-strings: The cin.getline function is first introduced in chapter 3 and then covered more thoroughly in the Files chapter. The C++ code:
char name[21]; cin.getline( name, 21, ' ' );
should read the next 20 characters in the input stream, or up to the first newline character, whichever comes first, and store the characters in name followed by the null terminator character '\0'. This code works fine if you are reading a string at the end of a line. It sounds like it should also work to input a string in the middle of a line. But with Visual C++ 6.0, if this call does not encounter the newline character, the input stream will fail. I am not sure if this is a problem in other current compilers, but I do know that it used to work with older C++ compilers.
The textbook only covers one version of the get function - the one that is used to read a single character. There is another version of get that can be used to read string into character arrays. It has exactly the same parameters as cin.getline and works similarly:
char name[21]; cin.get( name, 21, ' ' );
This version of the get function will work for reading a string in the middle of a line of input.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started