Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A company wants you to write a C++ program that allows the user to input 10 empl

ID: 651670 • Letter: A

Question

A company wants you to write a C++ program that allows the user to input 10 employee names, hourly rate and hours worked into 3 arrays. Program should compute each employees gross pay, using tax withholding percentage as shown below; tax withholding amount, and net pay (gross pay minus tax withholding).

Display all the results for each employee. The end program should display the total of all hours worked, the total gross pay, the total tax withholding for all employees and total net pay.

Weekly Gross Pay                            Withholding Percentage

0.00 to 300.00                                   10

300.01 to 550.00                               13

550.01 to 800.00                               16

800.01 and up                                   20

Explanation / Answer

#include "EmployeeClass.h"
#include "Salaried.h"
#include "Hourly.h"
#include "MyVector.h"

#include
#include
#include

using namespace std;

const int> const int TWO = 2;
const int THREE = 3;
const int SIZE = 4;
//variables
int answer = 0;
string fileName;
string response;
bool exitLoop = true;

// printCheckSalaried function prologue
// Purpose: Display necessary employee data for a paycheck/pay stub
// Parameters: EmployeeClass object passed as const reference
// Returns: None
void printCheckSalary(const Salaried&);

// printCheckHourly function prologue
// Purpose: Display necessary employee data for a paycheck/pay stub
// Parameters: Hourly object passed as const reference
// Returns: None
void printCheckHourly(const Hourly&);
int main()
{
   // Fix Numerical Output data to two places after the decimal
   cout.setf(ios::fixed);
cout.precision(2);
  
   // Create an array of Employee Pointers
   MyVector myEmployees;

   // Opening User Interface
   cout <<"This program has two functions." << endl;
   cout <<"Press 1 to create a data file." << endl;
   cout <<"Press 2 to read from the file and print paychecks." << endl;
   cout <<"Input: ";
   cin >> answer;
  
   // User enters one, then execute following code
   if(answer == ONE)
   {
       ofstream employeeInput(fileName.c_str());
       do
       {
       // Open file for output  
       //Create fstream object
       startover:
       cout << "Please enter a file name:";
       cin.ignore();
       cin >> fileName;
       employeeInput.open(fileName.c_str());
           if(employeeInput)
           {
               exitLoop = false;
               break;
           }
           if(employeeInput.fail())//Check to see if the file opened
           {  
               cout << "nInvalid file name:" << endl;
               cout << "nWould you like to try again? ";
               cin.ignore();
               cin >> response;
           }
           while (response.compare("Y") != 0 && response.compare("y") != 0 && response.compare("n") != 0 && response.compare("N") != 0);
           {
               if (response == "y" || response == "Y")
               {
                   goto startover;
               }
               else
               {
                   cout << "nThank you and Goodbye." << endl;
                   system("PAUSE");
                   exit(1);
               }
           }
       }while(exitLoop);
       // write the data
       //The only place you have to worry about throwing an exception in this assignment is when you find that you cannot read data from the file.
       myEmployees.push_back(new Hourly(1, "H. Potter", "Privet Drive", "201-9090", 40, 12.00));
       myEmployees.push_back(new Salaried(2, "A. Dumbledore", "Hogewarts", "803-1230", 1200));
       myEmployees.push_back(new Hourly(3, "R. Weasley", "The Burrow", "892-2000", 40, 10.00));
       myEmployees.push_back(new Salaried(4, "R. Hagrid", "Hogwarts", "910-8765", 1000));

       try
       {
           for(int i = 0; i < myEmployees.size(); i++)
           {
               // Utilizing pointer array, write the data to the file
               myEmployees.at(vectorData)->writeData(employeeInput);
           }
       }
       catch(EmployeeExceptions e)
       {
           cout <<"   nnThere was a file error while writing employee data";
           cout << "nto the file. The data may not be saved correctly.";
           cout << "nCheck your output file";
       }
  
       cout << "nWrite Successful!!n" << endl;
       employeeInput.close( );
       for(int i = 0; i < SIZE; i++)
       {
           delete myEmployees.size();
           myEmployees.at(vectorData) = NULL;
       }
       system("PAUSE");
   }
   if (answer == TWO)
   {
       //Create an object of the required kind, Hourly or Salaried.
   //Save the pointer to this object in the new array of Employee pointers.
       //Have the object read its data from the file.
       //Repeat this for each set of data in the file.
       ifstream employeeData(fileName.c_str());
       do
           {
               startAgain:
               cout << "nPlease enter in a filename: ";
               cin.ignore();
               cin >> fileName;   
               employeeData.open(fileName.c_str());
               if (employeeData)
               {
                   exitLoop = false;
                   goto readData;
                   break;
               }
               if (employeeData.fail())
               {
                   do
                   {
                       cout << "nInvalid file name:" << endl;
                       cout << "nWould you like to try again? ";
                       cin.ignore();
                       cin >> response;
                   }while (response.compare("Y") != 0 && response.compare("y") != 0 && response.compare("n") != 0 && response.compare("N") != 0);
                   if (response == "y" || response == "Y")
                   {
                       goto startAgain;
                   }
                   else
                   {
                       cout << "nThank you and Goodbye."<< endl;
                       system("PAUSE");
                       exit(1);
                   }
               }
       } while (exitLoop);
                      
           readData:
          
           string type;
           int index = 0;
               try
               {
                   while(employeeData >> type)
                   {
                       if(type == "Hourly")
                       {
                           myEmployees.at(vectorData) = new Hourly();
                       }
                       else
                       {
                           myEmployees.at(vectorData) = new Salaried();
                       }
                       myEmployees.at(vectorData)->readData(employeeData);
                       index++;  
                   }
               }
           // Catch if Read Failed
               catch(EmployeeExceptions e)
               {
                   if (e.getCode( ) == 1 || e.getCode( ) == 2)
                   {
                       cout << "nError reading data, terminating program.";
                       system("PAUSE");
                       exit(1);
                   }
                   if (e.getCode( ) == 3)
                   {
                       cout << "nUnexpected end of file, terminating program.";
                       system("PAUSE");
                       exit(1);
                   }
               }
               int count = index;

               // if read was successful
               // call respective printCheck()
               for(int i = 0; i < count; i++)
               {
                   system("CLS");
                   EmployeeClass* employeePtr = myEmployees.at(vectorData);
                   if(typeid( *myEmployees.at(vectorData)) == typeid(Hourly))
                   {
                       Hourly* hrlyPtr = dynamic_cast(employeePtr);
                      
                           cout<<"n------------------FluffShuffle Electronics------------------------n";
                           cout<<"nPay to the order of "<getEmployeeName()<<"..............................$"<getCalcPay();
                           cout<<"nnGlobal Bank of Computer Science Theory";
                           cout<<"n------------------------------------------------------------------n";
                           cout<<"Hours worked: "<< hrlyPtr->getWeeklyHours() <<"n";
                           cout<<"Hourly Wage: "<< hrlyPtr->getHourlyWage() << "n" << endl;                  
                   }
                   else if(typeid( *myEmployees.at(vectorData)) == typeid(Salaried))
                   {
                       Salaried* slryPtr = dynamic_cast(employeePtr);

                           cout<<"n------------------FluffShuffle Electronics------------------------n";
                           cout<<"nPay to the order of "<getEmployeeName()<<"..............................$"<getCalcPay();
                           cout<<"nnGlobal Bank of Computer Science Theory";
                           cout<<"n------------------------------------------------------------------n";
                           cout<<"Weekly Salary: " <getSalary() << endl;
                   }
                   system("PAUSE");
               }
           employeeData.close();//close the read file
   }
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote