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
|
#include "employee.h"
using namespace std;
// printCheck function
// Purpose: Create a paystub for an employee
// Parameters: Employee information
// Returns: void
void printCheck(const Employee&);
//Setting variables
int userSelection;
string fileName;
//main method
//Purpose: To call to my employee functions and display information about employees
//Parameters: None
//Returns: None
int main()
{
//Getting information from the user
cout << "This program has two options:" << endl;
cout << "1 - Create a data file, or " << endl;
cout << "2 - Read data from a file and print paychecks." << endl;
try
{
cout << "Please enter <1> to create a file or <2> to print checks: ";
cin >> userSelection;
if (userSelection != 1 || userSelection != 2)
{
throw "Invalid Input! Program will now close.";
}
}
catch (const char* Message)
{
cout << "\nError: " << Message << endl;
system ("Pause");
return 0;
}
cout << endl;
try
{
cout << "Please enter file name: ";
cin >> fileName;
if (fileName != fileName)
throw "No such file exists.";
}
catch (const char* Message)
{
cout << "\nError: " << Message << endl;
system("Pause");
return 0;
}
cout << endl;
Employee b1(1234, "Bruce Banner", "436 E 900 S", "801-465-2291", 10.00, 45);
Employee b2(1569, "Tony Stark", "7000 E 9680 S", "801-941-0745", 12.50, 30);
Employee b3(1967, "Charles Xavier", "500 W 780 N", "801-754-3687", 15.00, 40);
//If statement that handles the writeEmployee information
if (userSelection == 1)
{
ofstream odataFile(fileName);
if (odataFile.good())
{
//Write the data
b1.writeEmployee(odataFile);
b2.writeEmployee(odataFile);
b3.writeEmployee(odataFile);
odataFile.close();
cout << "Data file created ... you can now run option 2." << endl;
system("PAUSE");
}
}
//If statment that handles the readEmployee information
if (userSelection == 2)
{
ifstream idataFile(fileName);
if (idataFile.good())
{
// Read the file
if (b1.readEmployee(idataFile))
{
// If read was successful, print b1
printCheck(b1);
}
if (b2.readEmployee(idataFile))
{
//If read was successful, print b2
printCheck(b2);
}
if (b3.readEmployee(idataFile))
{
//If read was successful, print b3
printCheck(b3);
}
else // the read operation failed ... display a message
cout << "\nRead failed";
}
}
}
void printCheck(const Employee& b)
{
cout << "\n--------------------Marvel Comics--------------------" << endl;
cout << "\n\nPay to the order of " << b.getEmployeeName() << ".............$" << setprecision(2) << fixed << b.getCalcPay() << endl;
cout << "\n\nS.H.I.E.L.D Bank" << endl;
cout << "-----------------------------------------------------" << endl;
cout << "Hours worked: " << b.getWeeklyHours() << endl;
cout << "Hourly Wage: " << b.getHourlyWage() << endl;
cout << "\n" << endl;
system("PAUSE");
system("CLS");
}
|