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

1234 John Smith M Y 45 0 52000 2345 Bob Murphy S N 30.89 20.24 0 3456 Patty Lane

ID: 3560538 • Letter: 1

Question

1234 John Smith M Y 45 0 52000
2345 Bob Murphy S N 30.89 20.24 0
3456 Patty Lane M N 20.13 13.15 0
4567 Mary Daniels H N 7.99 4.00 0
5678 Paul Jones M Y 27.08 0 52000
6789 Jeff Smith M Y 33 0 107000
7890 Adam Thomas M Y 50 0 247000
8901 Jeanine Michaels H N 55 15.02 18.00

When I compile and run the program inside of Dev C++, this is my output...

THERE IS NO DATA.

Please help me fix the syntax to run this program successfully with the desired output or walk me through how to get my data to work using Dev C++.

Here is code:

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
class Employee_Info{
public:
   int employeeid;
   string firstname, lastname;
   char taxstatus, typeemp;
   double hoursworked, hourlyrate, overtimehours, overtimepay, grosspay, grosssalary, taxrate, taxamount, netpay;
};//end class

class Employee :public Employee_Info{

public:
   ifstream input;
   Employee_Info empi[100];
   int counter;
   void headers();
   virtual void grosspaycalc() = 0;
   virtual void taxratecalc() = 0;
   virtual void netpaycalc() = 0;
   virtual void employee_report() = 0;
   void netpaysort();
   virtual void displayinfo() = 0;
};//end class

void Employee::netpaysort(){
   for (int pass = 1; pass <= counter; pass = pass + 1) {
       for (int i = 0; i<counter - 1; i = i + 1) {
           if (empi[i].netpay<empi[i + 1].netpay) {
               swap(empi[i].netpay, empi[i + 1].netpay);
           }//end if
       }//end for
   }//end for
}//end netpaysort

class Hourly_Employee : public Employee{

public:
   Hourly_Employee();//constructor
   ~Hourly_Employee();//destructor
  
   void grosspaycalc(){
       for (int i = 0; i<counter; i++) {
           if (empi[i].typeemp == 'Y')
           {
               double gross_pay = empi[i].grosspay / 52;
               empi[i].hourlyrate = gross_pay / 40;
               if (empi[i].hoursworked>40) {
                   empi[i].overtimehours = empi[i].hoursworked - 40;
                   empi[i].overtimepay = 1.5*empi[i].overtimehours*empi[i].hourlyrate;
               }
               else
               {
                   empi[i].overtimehours = 0;
                   empi[i].overtimepay = 0;
               }
           }
           else if (empi[i].hoursworked>40){
               empi[i].overtimehours = empi[i].hoursworked - 40;
               empi[i].overtimepay = 1.5*empi[i].overtimehours*empi[i].hourlyrate;
               empi[i].grosspay = empi[i].overtimepay + (empi[i].hoursworked*empi[i].hourlyrate);
           }//end if
           else
           {
               empi[i].overtimehours = 0;
               empi[i].overtimepay = 0;
               empi[i].grosspay = empi[i].hoursworked*empi[i].hourlyrate;
           }
       }//end for
   }//end grosspaycalc
  
   void taxratecalc(){
       for (int i = 0; i<counter; i++) {
           if (empi[i].grosspay>1000) {
               empi[i].taxrate = .30;
           }//end if
           if (empi[i].grosspay>800 && empi[i].grosspay <= 1000) {
               empi[i].taxrate = .20;
           }//end if
           if (empi[i].grosspay>500 && empi[i].grosspay <= 800) {
               empi[i].taxrate = .10;
           }//end if
           if (empi[i].grosspay >= 0 && empi[i].grosspay <= 500) {
               empi[i].taxrate = 0;
           }//end if
           if ((empi[i].taxstatus == 'H' || empi[i].taxstatus == 'h') && (empi[i].grosspay>500)){
               empi[i].taxrate = empi[i].taxrate - .05;
           }//end if
           if (empi[i].taxstatus == 'S' || empi[i].taxstatus == 's'){
               empi[i].taxrate = empi[i].taxrate + .05;
           }//end if
           if (empi[i].taxstatus == 'M' || empi[i].taxstatus == 'm'){
               empi[i].taxrate = empi[i].taxrate;
           }//end if
       }//end for
   }//end Hourly_Employee taxratecalc

   void netpaycalc(){
       for (int i = 0; i<counter; i++) {
           empi[i].taxamount = empi[i].grosspay*empi[i].taxrate;
           empi[i].netpay = empi[i].grosspay - empi[i].taxamount;
       }//end for
   }//end netpaycalc

   void displayinfo(){

       //if (empi[i].typeemp == 'N' || empi[i].typeemp == 'n') {
       cout << setiosflags(ios::fixed | ios::showpoint | ios::left) << setprecision(2);
       for (int i = 0; i<counter; i++)
           cout << setw(15) << empi[i].employeeid << setw(15) << empi[i].firstname << setw(15) << empi[i].lastname << "-" << setw(15) << empi[i].taxstatus << setw(15) << empi[i].typeemp << setw(15) << empi[i].hoursworked << "$ " << setw(15) << empi[i].hourlyrate << setw(15) << empi[i].grosspay << setw(15) << empi[i].overtimehours << "$ " << setw(17) << empi[i].overtimepay << "% " << setw(15) << empi[i].taxrate * 100 << "$ " << setw(15) << empi[i].taxamount << "$ " << setw(15) << empi[i].netpay << endl;
       //}//end if
   }//end employeeinfo

   void employee_report(){
       grosspaycalc();
       taxratecalc();
       netpaycalc();
       netpaysort();
   }//end readindata
};//end class

Hourly_Employee::Hourly_Employee() :Employee(){
   input.open("data.txt");
   counter = 0;

   while (input >> empi[counter].firstname >> empi[counter].lastname >> empi[counter].employeeid >> empi[counter].taxstatus >> empi[counter].typeemp
       >> empi[counter].hoursworked >> empi[counter].hourlyrate >> empi[counter].grosspay) {
       counter++;
   }//end while
}//end constructor

Hourly_Employee::~Hourly_Employee(){
   input.close();
}// end Destructor
//end function

void headers();

int main(){
   const int MAXSIZE = 70;
   Hourly_Employee hourly_report;
   cout << setw(100) << "++++++++++++++++++++++++++++++++++++" << endl;
   cout << setw(100) << " Adam DiStefano's Payroll Program " << endl;
   cout << setw(100) << "++++++++++++++++++++++++++++++++++++" << endl;
   headers();
   //for (int i = 0; i<MAXSIZE; i++) {
   hourly_report.employee_report();
   hourly_report.displayinfo();
   //}//end for
   return 0;
}// End Main

void headers(){
   cout << setiosflags(ios::fixed | ios::showpoint | ios::left);
   cout << setw(15) << "Employee ID" << setw(15) << "First Name" << setw(15) << "Last Name" << setw(15) << "Tax Status" << setw(15) << "Salaried" << setw(15) << "Hours Worked" << setw(15) << "Hourly Rate" << setw(15) << "Gross Pay" << setw(15) << "OT Hours" << setw(15) << "Overtime Pay" << setw(15) << "Tax Rate" << setw(15) << "Tax Amount" << setw(15) << "Net Pay" << endl;
}//end

Explanation / Answer

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
class Employee_Info{
   public:
       int employeeid;
       string firstname, lastname;
       char taxstatus, typeemp;
       double hoursworked, hourlyrate, overtimehours, overtimepay, grosspay, grosssalary, taxrate, taxamount, netpay;
};//end class

class Employee :public Employee_Info{

   public:
       ifstream input;
       Employee_Info empi[100];
       int counter;
       void headers();
       virtual void grosspaycalc() = 0;
       virtual void taxratecalc() = 0;
       virtual void netpaycalc() = 0;
       virtual void employee_report() = 0;
       void netpaysort();
       virtual void displayinfo() = 0;
};//end class

void Employee::netpaysort(){
   for (int pass = 1; pass <= counter; pass = pass + 1) {
       for (int i = 0; i<counter - 1; i = i + 1) {
           if (empi[i].netpay<empi[i + 1].netpay) {
               swap(empi[i].netpay, empi[i + 1].netpay);
           }//end if
       }//end for
   }//end for
}//end netpaysort

class Hourly_Employee : public Employee{

   public:
       Hourly_Employee();//constructor
       ~Hourly_Employee();//destructor

       void grosspaycalc(){
           for (int i = 0; i<counter; i++) {
               if (empi[i].typeemp == 'Y')
               {
                   double gross_pay = empi[i].grosspay / 52;
                   empi[i].hourlyrate = gross_pay / 40;
                   if (empi[i].hoursworked>40) {
                       empi[i].overtimehours = empi[i].hoursworked - 40;
                       empi[i].overtimepay = 1.5*empi[i].overtimehours*empi[i].hourlyrate;
                   }
                   else
                   {
                       empi[i].overtimehours = 0;
                       empi[i].overtimepay = 0;
                   }
               }
               else if (empi[i].hoursworked>40){
                   empi[i].overtimehours = empi[i].hoursworked - 40;
                   empi[i].overtimepay = 1.5*empi[i].overtimehours*empi[i].hourlyrate;
                   empi[i].grosspay = empi[i].overtimepay + (empi[i].hoursworked*empi[i].hourlyrate);
               }//end if
               else
               {
                   empi[i].overtimehours = 0;
                   empi[i].overtimepay = 0;
                   empi[i].grosspay = empi[i].hoursworked*empi[i].hourlyrate;
               }
           }//end for
       }//end grosspaycalc

       void taxratecalc(){
           for (int i = 0; i<counter; i++) {
               if (empi[i].grosspay>1000) {
                   empi[i].taxrate = .30;
               }//end if
               if (empi[i].grosspay>800 && empi[i].grosspay <= 1000) {
                   empi[i].taxrate = .20;
               }//end if
               if (empi[i].grosspay>500 && empi[i].grosspay <= 800) {
                   empi[i].taxrate = .10;
               }//end if
               if (empi[i].grosspay >= 0 && empi[i].grosspay <= 500) {
                   empi[i].taxrate = 0;
               }//end if
               if ((empi[i].taxstatus == 'H' || empi[i].taxstatus == 'h') && (empi[i].grosspay>500)){
                   empi[i].taxrate = empi[i].taxrate - .05;
               }//end if
               if (empi[i].taxstatus == 'S' || empi[i].taxstatus == 's'){
                   empi[i].taxrate = empi[i].taxrate + .05;
               }//end if
               if (empi[i].taxstatus == 'M' || empi[i].taxstatus == 'm'){
                   empi[i].taxrate = empi[i].taxrate;
               }//end if
           }//end for
       }//end Hourly_Employee taxratecalc

       void netpaycalc(){
           for (int i = 0; i<counter; i++) {
               empi[i].taxamount = empi[i].grosspay*empi[i].taxrate;
               empi[i].netpay = empi[i].grosspay - empi[i].taxamount;
           }//end for
       }//end netpaycalc

       void displayinfo(){

           //if (empi[i].typeemp == 'N' || empi[i].typeemp == 'n') {
           cout << setiosflags(ios::fixed | ios::showpoint | ios::left) << setprecision(2);
           for (int i = 0; i<counter; i++)
               cout << setw(15) << empi[i].employeeid << setw(15) << empi[i].firstname << setw(15) << empi[i].lastname << "-" << setw(15) << empi[i].taxstatus << setw(15) << empi[i].typeemp << setw(15) << empi[i].hoursworked << "$ " << setw(15) << empi[i].hourlyrate << setw(15) << empi[i].grosspay << setw(15) << empi[i].overtimehours << "$ " << setw(17) << empi[i].overtimepay << "% " << setw(15) << empi[i].taxrate * 100 << "$ " << setw(15) << empi[i].taxamount << "$ " << setw(15) << empi[i].netpay << endl;
           //}//end if
       }//end employeeinfo

       void employee_report(){
           grosspaycalc();
           taxratecalc();
           netpaycalc();
           netpaysort();
       }//end readindata
};//end class

Hourly_Employee::Hourly_Employee() :Employee(){
   input.open("data.txt");
   counter = 0;

   while (input >> empi[counter].employeeid >> empi[counter].firstname >> empi[counter].lastname >> empi[counter].taxstatus >> empi[counter].typeemp >> empi[counter].hoursworked >> empi[counter].hourlyrate >> empi[counter].grosspay) {
       cout<< empi[counter].firstname;
       counter++;
   }//end while
}//end constructor

Hourly_Employee::~Hourly_Employee(){
   input.close();
}// end Destructor
//end function

void headers();

int main(){
   const int MAXSIZE = 70;
   Hourly_Employee hourly_report;
   cout << setw(100) << "++++++++++++++++++++++++++++++++++++" << endl;
   cout << setw(100) << " Adam DiStefano's Payroll Program " << endl;
   cout << setw(100) << "++++++++++++++++++++++++++++++++++++" << endl;
   headers();
   //for (int i = 0; i<MAXSIZE; i++) {
   hourly_report.employee_report();
   hourly_report.displayinfo();
   //}//end for
   return 0;
}// End Main

void headers(){
   cout << setiosflags(ios::fixed | ios::showpoint | ios::left);
   cout << setw(15) << "Employee ID" << setw(15) << "First Name" << setw(15) << "Last Name" << setw(15) << "Tax Status" << setw(15) << "Salaried" << setw(15) << "Hours Worked" << setw(15) << "Hourly Rate" << setw(15) << "Gross Pay" << setw(15) << "OT Hours" << setw(15) << "Overtime Pay" << setw(15) << "Tax Rate" << setw(15) << "Tax Amount" << setw(15) << "Net Pay" << endl;
}//end

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