Ok, I posted earlier and your suggestions worked fine, I had to rework the program a bit but it compiles now. The only problem is that it segfaults right away now. This is the gdb backtrace:
(gdb) backtrace full
#0 0x95082630 in std::istream::sentry::sentry ()
No symbol table info available.
#1 0x95082d4b in std::istream::operator>> ()
No symbol table info available.
#2 0x0000281f in employee::getData ()
No symbol table info available.
#3 0x00002901 in main ()
No symbol table info available.
And here is my full code:
#include <iomanip>
#include <iostream>
#include <fstream>
#include "custom_sort.cpp"
using namespace std;
const double taxrate = .3;
const double overtime_rate = 1.5;
const int NUMEMP = 50;
class employee {
// data members - all private.
public:
ifstream fin;
int n;
long int emp_id;
char employee_type_flag;
double avg_array[NUMEMP];
public: double given_gross_pay;
char fname[20],lname[20];
double hours_worked, hourly_rate, gross_pay, net_pay, tax_amt, overtime_hours;
virtual void calc_gross_pay()=0;
void calc_net_pay() { tax_amt = gross_pay * taxrate; net_pay = gross_pay - tax_amt;}
void headers();
void avg(double*);
void getData();
//fin>>emp_id>>fname>>lname>>hours_worked>>hourly_rate>>employee_type_flag>>given_gross_pay
void setProperties(long int t_empid,char t_fname[20],char t_lname[20], double t_hoursworked, double t_hourlyrate, char t_emptypeflag, double t_givengross) {
emp_id = t_empid;
*fname = *t_fname;
*lname = *t_lname;
hours_worked = t_hoursworked;
hourly_rate = t_hourlyrate;
employee_type_flag = t_emptypeflag;
given_gross_pay = t_givengross;
}
// definitions later
//constructor/destructor
public:employee();
~employee();
void outputData();
}; // end employee class
class salary_employee: public employee {
//double hourly_rate = given_gross_pay / 52;
//hourly_rate = hourly_rate/40;
public:
void calc_gross_pay() {
if (hours_worked > 40) {
overtime_hours = hours_worked - 40;
gross_pay = (hours_worked * hourly_rate) + (overtime_hours * overtime_rate); } else
{
gross_pay = (hours_worked * hourly_rate);overtime_hours = 0;
}
}// end calc_gross_pay
}; // end salary_employee
class hourly_employee: public employee {
public:
void calc_gross_pay() {
if (hours_worked > 40) { overtime_hours = hours_worked - 40;
gross_pay = (hours_worked * hourly_rate) + (overtime_hours * overtime_rate); } else
{
gross_pay = (hours_worked * hourly_rate);overtime_hours = 0;
}
}
}; // end hourly_employee
employee::employee() { fin.open("payroll.dat"); }
employee::~employee() { fin.close(); };
void employee::avg(double *p) {
double total = 0;
int count = 0;
while(*p != 0) {
total = *p + total;
count++;
p++; }
cout << endl << "Average net pay for all employees: " << (total/count) << endl;
}; //end avg
void employee::headers() {
cout.flags(ios::left);
cout << setw(150) << setfill('=') << "==Payroll Information" << endl;
cout << setfill(' ');
cout << setw(20) << "ID" << setw(20) << "First Name" << setw(20) << "Last Name" << setw(20) << "Hours Worked" << setw(20) << "Overtime Hours" << setw(12) << "GrossPay" << setw(12) << "Tax Rate" << setw(12) << "Tax Amount" << setw(12) << "Net Pay"<< endl;
cout << setw(150) << setfill('-')<< "" << endl;
cout << setfill(' ');
}
void employee::getData() {
int i=0;
employee *emp1[10];
while(fin>>emp_id>>fname>>lname>>hours_worked>>hourly_rate>>employee_type_flag>>given_gross_pay) {
if (employee_type_flag == 's') {
emp1[i] = new salary_employee();
} else if (employee_type_flag == 'h') {
emp1[i] = new hourly_employee();
} // end employee_type check
emp1[i]->setProperties(emp_id,fname,lname,hours_worked,hourly_rate,employee_type_flag,given_gross_pay);
i++;
employee::headers();
emp1[i]->calc_gross_pay();
emp1[i]->calc_net_pay();
cout << setw(20) << emp1[i]->emp_id;
cout << setw(20) << emp1[i]->fname;
cout << setw(20) << emp1[1]->lname;
cout << setw(20) << setprecision(5) << hours_worked;
cout << setw(20) << setprecision(5) << overtime_hours;
cout << setw(12) << setprecision(6) << gross_pay;
cout << setw(12) << setprecision(4) << taxrate;
cout << setw(12) << setprecision(4) << tax_amt;
cout << setw(12) << setprecision(5) << net_pay;
cout << endl;
avg_array[i] = net_pay;
i++;} //end while loop
avg(avg_array);
//
};
int main() {
employee *emp;
emp->getData();
// end employee_type check
//
return 0;
}
I really appreciate any help you could give me.