I am trying to set up a vector of pointers to objects using the base object class. I am then assigning specific objects of pointers to derived classes to the vector. I have attached the actual driver program. All the classes work with a different driver program. I am sure this has inly to do with my use of pointers in the program. I knwo there may be a better way to do this, but I am doing this for an asignment, and the requirements are very specific. This code compiles fine using Borland, but it will not run properly. Any suggestions would be greatly appreciated.
Here is my code:
<CODE>
void doPayroll(vector<Employee*> employeelist);
int main( )
{
clrscr( );
vector<Employee*> employeelist;
Salaried* employee1;
employee1->setName("Laura Bush");
employee1->setEmpNumber(1);
employee1->setMonthlySalary(50000.00);
employee1->setAddress("1600 Pennsylvania Ave.");
employee1->setPhoneNumber("123-4567");
employee1->setDeptNumber(100);
employeelist.push_back(employee1);
Sales* employee2;
employee2->setName("Muffin Man");
employee2->setEmpNumber(2);
employee2->setMonthlySalary(40000.00);
employee2->setMonthlySales(165000.00);
employee2->setCommission(0.4);
employee2->setAddress("34 Drury Lane");
employee2->setPhoneNumber("890-1234");
employee2->setDeptNumber(200);
employeelist.push_back(employee2);
Hourly* employee3;
employee3->setName("Tony Blair");
employee3->setEmpNumber(3);
employee3->setHourlyRate(34.50);
employee3->setHoursWorked(50);
employee3->setAddress("27 Downing Street");
employee3->setPhoneNumber("567-8901");
employee3->setDeptNumber(300);
employeelist.push_back(employee3);
PartTime* employee4;
employee4->setName("Mephistopheles");
employee4->setEmpNumber(4);
employee4->setHourlyRate(22.00);
employee4->setHoursWorked(30);
employee4->setMaxHours(25);
employee4->setAddress("7734 Upside Down Street");
employee4->setPhoneNumber("234-5678");
employee4->setDeptNumber(400);
employeelist.push_back(employee4);
}
void doPayroll(vector<Employee*> employeelist)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
int x = 0;
employeelist[x]->calcSalary( );
cout << "\n\nDepartment: " << employeelist[x]->getDeptNumber( )
<< "\tEmployee Number: " << employeelist[x]->getEmpNumber( )
<< "\n\nEmployee Name:\t" << employeelist[x]->getName( )
<< "\nAddress:\t" << employeelist[x]->getAddress( )
<< "\nPhone Number:\t" << employeelist[x]->getPhoneNumber( )
<< "\n\nGross Pay: \t\t$" << employeelist[x]->getGrossPay( )
<< "\nFederal Taxes: \t$" << employeelist[x]->getFedTax( )
<< "\nState Taxes: \t\t$" << employeelist[x]->getStateTax( )
//<< "\nBenefits: \t\t$" << employeelist[x].getBenefits( )
<< "\n\t\t\t--------------"
<< "\nNet Pay: \t\t$" << employeelist[x]->calcTaxes( ) << "\n\n"
<< "_________________________________________";
}
</CODE>