1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
// File Prologue
// Author: Clint Pedersen
// Course: CS 1400-002
// Project: Project 03
// Date: 1/29/2009
// --------------------------------------------
// I declare that the following source code was written solely by me.
// I understand that copying any source code, in whole or in part,
// constitutes cheating, and that I will receive zero grade on this
// project if I am found in violation of this policy.
#include <iostream>
#include "employee.h"
#include <fstream>
using namespace std;
// The doPayroll function
// Purpose: Print out the data stored in the derived
// classes of the Employee class
// Parameters: vector of pointers
// Returns: none
// Pre-conditions: none
// Post-conditions: none
void doPayroll(Employee[]);
// The printCheck function
// Purpose: Print out the data stored in the derived
// classes of the Employee class
// Parameters: Employee pointer
// Returns: none
// Pre-conditions: none
// Post-conditions: none
void printCheck(Employee*);
const int SIZE = 4;
int main()
{
Employee* payroll[SIZE];
payroll[0] = new Salaried (10000.0, 1, "Laura Bush", "1600 Pennsylvanie Ave.", "(202) 123-4567", "511-89-1000");
payroll[1] = new Sales (65000.0, .4, 5000.0, 2, "Muffin Man", "34 Drury Lane", "(801) 345-9876", "623-90-4567");
payroll[2] = new Hourly (34.5, 50, 3, "Tony Blair", "27 Downing Street", "1-44-345-8765", "512-90-5454");
payroll[3] = new PartTime (25.0, 22.0, 30.0, 4, "Mephistopheles", "7734 Upside Down Street", "(914) 212-2287", "512-63-5151");
ofstream output("c:\\payroll.txt");
if(output.fail())
{
cout << "\nUnable to open a new file for writing.";
return 1;
}
cout << "\nOpened: payroll.txt";
for(int i = 0; i < SIZE; i++)
{
payroll[i]->writeData(output);
}
output.close();
Employee* newPayroll[SIZE];
ifstream input;
input.open("c:\\payroll.txt");
int temp;
input >> temp;
while ( !input.eof( ) )
{
input >> temp;
if ( !input )
{
if (input.eof( ) )
break;
else
{
cout << "File error...\n";
break;
}
}
switch(temp)
{
case 1:
{
newPayroll[temp-1] = new Salaried();
newPayroll[temp-1]->readData(input);
break;
}
case 2:
{
newPayroll[temp-1] = new Sales();
newPayroll[temp-1]->readData(input);
break;
}
case 3:
{
newPayroll[temp-1] = new Hourly();
newPayroll[temp-1]->readData(input);
break;
}
case 4:
{
newPayroll[temp-1] = new PartTime();
newPayroll[temp-1]->readData(input);
break;
default:
{
cout << "\nBad type code ... can't complete execution";
break;
}
}
input.close();
doPayroll(payroll[SIZE]);
system("PAUSE");
return 0;
}
void doPayroll(Employee pointers[])
{
int size = 4;
for(int i = 0; i < size; i++)
{
printCheck(pointers[i]);
}
}
void printCheck(Employee* pointers)
{
cout << "Employee Number: "<< pointers->getEmpNumber() << endl
<< "Employee Name: " << pointers->getName() << endl
<< "Employee Address: " << pointers->getAddress() << endl
<< "Employee Phone Number: " << pointers->getPhoneNumber() << endl
<< "Employee SSN: " << pointers->getSocial() << endl
<< "Net Pay: $";
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << pointers->calcSalary() << endl << endl;
}
|