Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <iomanip>
- using namespace std;
- const int COMPANY_SIZE = 50;
- struct employeeType
- {
- string firstName;
- string lastName;
- int personID;
- string deptID;
- double yearlySalary;
- double monthlySalary;
- double yearToDatePaid;
- double monthlyBonus;
- };
- void readEmpData(ifstream& infile, employeeType *emp, int length);
- void outputEmpData(ofstream& outfile, employeeType *emp, int length);
- int main()
- {
- employeeType employees[COMPANY_SIZE]; // stucts in arrays
- ifstream inFile;
- ofstream outFile;
- inFile.open("employRecords.dat");
- if (!inFile)
- {
- cout << "Data file (employRecords.dat) does not exist." << endl;
- return 1;
- }
- outFile.open("employRecords.out", ios::app);
- readEmpData(inFile, employees, COMPANY_SIZE);
- outputEmpData(outFile, employees, COMPANY_SIZE);
- inFile.close();
- outFile.close();
- return 0;
- }
- void readEmpData(ifstream& infile, employeeType& emp, int length)
- {
- int counter;
- for (counter = 0; counter < length; counter++)
- {
- infile >> emp[counter].firstName >> emp[counter].lastName
- >> emp[counter].personID >> emp[counter].deptID
- >> emp[counter].yearlySalary;
- emp[counter].monthlySalary = emp[counter].yearlySalary / 12;
- emp[counter].yearToDatePaid = 0.0;
- emp[counter].monthlyBonus = 0.0;
- }
- }
- void outputEmpData(ofstream& outfile, employeeType& emp, int length)
- {
- int counter;
- double payCheck;
- for (counter = 0; counter < length; counter++)
- {
- cout << emp[counter].firstName << " " << emp[counter].lastName << " "
- << endl;
- outfile << emp[counter].firstName << " " << emp[counter].lastName << " "
- << endl;
- payCheck = emp[counter].monthlySalary + emp[counter].monthlyBonus;
- emp[counter].yearToDatePaid = emp[counter].yearToDatePaid + payCheck;
- cout << setprecision(2) << payCheck << endl;
- outfile << setprecision(2) << showpoint << payCheck << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement