+1 (315) 557-6473 

C++ Program Utilizing At Least Three Functions (Getdata, Calculate, Senddata) Assignment Solution.


Instructions

Objective
Write a program program utilizing at least three functions (GetData, Calculate, SendData) in C++.

Requirements and Specifications

Here are the instructions
Objectives
~ code, compile and run a program containing two or more functions
~ error check and handle invalid input
~ output readable, formatted output
Assignment
Plan and code a program utilizing at least three functions (GetData, Calculate, SendData) to solve the following problem to calculate payroll information for Natural Oak and Pine Furniture Company.
NOTE: You MUST use GetData to get user input and return values to main. You MUST use Calculate to calculate gross pay, deductions and net pay, and return values back to main. You MUST use SendData to output itemized formatted output,
Now that we have the ability to handle errors, can process data that falls into different categories, and the ability to process more than one set of data during one program run, let's incorporate this into a new program for Natural Oak and Pine Furniture Company.
Develop a top-down design and write a C++ assignment program to determine payroll information for all employees at Natural Oak and Pine Furniture Company. (This will expand the program created for Lab 2A).
All data will be input from a file Payln.txt (See below).Develop a function (listed above) for each task involved in this problem. Use value and reference parameters for passing all data between modules, Determine the total hours worked by each employee during the week. Calculate each employees total pay based on the following scale of hours worked:
0 through 40 hours                                              regular pay
hours 41 through 60 hours                             1 1/2 pay (only for hours 41-60)
hours 61 through 80 hours                             double pay (only for hours 61-80)
Determine deductions (state withholding, federal withholding, union dues, and hospitalization) for each employee (as calculated in Lab 2A). Determine the gross pay (before deductions) and net pay (after deductions).
Output to a new file--PayOut.txt: 3 employee initials, total hours worked, pay rate, the amount of each deduction (federal withholding, state withholding, union dues, and hospitalization), gross pay, and net pay.
Input
3 employee initials, 7 numbers (representing the hours worked during 7 days), and the employee's hourly rate of pay. Error check data input from the file (by the input module). Send all error data to errorfile with the data clearly labeled. NO ARRAYS. Create the data file below. Name the file PayIn.txt.
Data File
ABC      8.0      8.0      8.0      8.0      8.0     0.0      0.0      8.75
DEF      10.0      10.0      10.0      10.0      10.0      0.0      0.0      9.75
GHI      8.0      10.0      6.0      10.0      9.0     10.0      12.0     10.00
JKL      0.0     0.0     5.0      6.0      7.0      8.0      6.0     8.75
MNO      8.0      8.0      8.0      8.0     8.0     8.0     80.0      8.00
PQR      10.0      10.0      8.0      10.0     6.0      3.0     2.0      9.75
STU 9.0      11.5     5.5     7.5      9.5      2.5     0.0      11.50
VWX 25.0      0.0      0.0      8.5      7.5      5.5      0.0      12.50
XYZ 10.0      10.0      10.0      10.0     10.0     0.0      0.0     5.00
AAA 0.0      0.0     0.0      25.0      1.0     0.0     0.0      15.75
BBB 15.0      15.0      15.0      15.0     15.0      15.0      15.0      12.75
Output
To an output file: 3 initials , total hours worked, hourly rate of pay, amount of each of 4 deductions (federal withholding, state withholding, union dues, hospitalization), gross pay, net pay. Output valid data to PayOut.txt. Output errors to an error file.
NOTE: You may not use return, break, continue or exit to prematurely exit the program. You may not use arrays, or any string handling functions.
Source Code
#include
#include
#include
#include
using namespace std;
/*
    For this problem, let's create a struct to help us with the data
*/
struct Worker
{
    string initials;
    int hours[7];
    float rate;
    int total_hours;
    float gross_payment;
    float net_payment;
    float federal_rate;
    float state_rate;
    float hospitalization;
    float union_rate;
};
struct WorkersList
{
    struct Worker workers[100];
    int n;
};
/*
    GET DATA MODULE
*/
WorkersList GetData()
{
    // Create the array of workers
    struct WorkersList list;
    // Read file
    ifstream file("PayIn.txt");
    string initials;
    int n = 0;
    float h1, h2, h3, h4, h5, h6, h7, rate;
    Worker w;
    while(file >> initials >> h1 >> h2 >> h3 >> h4 >> h5 >> h6 >> h7 >> rate)
    {
        w.initials = initials;
        w.hours[0] = h1;
        w.hours[1] = h2;
        w.hours[2] = h3;
        w.hours[3] = h4;
        w.hours[4] = h5;
        w.hours[5] = h6;
        w.hours[6] = h7;
        w.rate = rate;
        // If the rate is negative, set to positive
        if(rate < 0)
            w.rate = -rate;
        list.workers[n] = w;
        n++;
    }
    list.n = n;
    file.close();
    return list;
}
/*
    MODULE CALCULATE
*/
void Calculate(WorkersList &list)
{
    // For each worker, calculate the total hours
    int total_hours;
    for(int i = 0; i < list.n; i++)
    {
        total_hours = 0.0;
        for(int j = 0; j < 7; j++)
        {
            total_hours += list.workers[i].hours[j];
        }
        list.workers[i].total_hours = total_hours;
        // Now. calculate the total payment
        list.workers[i].gross_payment = 0; // initialize to zero
        if(total_hours >= 40)
        {
            list.workers[i].gross_payment = 40*list.workers[i].rate; // regular pay
            total_hours -= 40;
            if(total_hours >= 20)
            {
                total_hours -= 20;
                list.workers[i].gross_payment += 20*list.workers[i].rate*1.5; // 50% more
                // If there are still hours, pay them with double pay
                if(total_hours > 0)
                {
                    list.workers[i].gross_payment += total_hours*list.workers[i].rate*2.0; // double
                }
            }
            else
            {
                list.workers[i].gross_payment += total_hours*list.workers[i].rate*1.5; // 50% more
            }
        }
        else
            list.workers[i].gross_payment += total_hours*list.workers[i].rate;
        // Calculate deductions
        list.workers[i].federal_rate = list.workers[i].gross_payment*0.18f;
        list.workers[i].state_rate = list.workers[i].gross_payment*0.045f;
        list.workers[i].hospitalization = 25.65f;
        list.workers[i].union_rate = list.workers[i].gross_payment*0.02f;
        // Calculate net payment
        list.workers[i].net_payment = list.workers[i].gross_payment - (list.workers[i].federal_rate+list.workers[i].state_rate+list.workers[i].hospitalization+list.workers[i].union_rate);
    }
}
/*
    MODULE SEND DATA
*/
void SendData(WorkersList &list)
{
    // Write the data to a file
    // Open file
    ofstream file("PayOut.txt");
    // Write header
    file << left << setw(20) << "Initials" << right << setw(25) << "Total Hours" << setw(25) << "Gross Payment" << setw(35) << "Federal Withholding Deduction" << setw(35) << "State Withholding Deduction" << setw(25) << "Hospitalization" << setw(20) << "Union dues" << setw(20) << "Net Payment" << endl;
    for(int i = 0; i < list.n; i++)
    {
        file << left << setw(20) << list.workers[i].initials << right << setw(25) << list.workers[i].total_hours << setw(25) << list.workers[i].gross_payment << setw(35) << list.workers[i].federal_rate << setw(35) << list.workers[i].state_rate << setw(25) << list.workers[i].hospitalization << setw(20) << list.workers[i].union_rate << setw(20) << list.workers[i].net_payment << endl;
    }
    file.close();
}
int main()
{
    WorkersList list = GetData();
    Calculate(list);
    SendData(list);