Advertisement
BHXSpecter

Struct Array Function Params Reference

Sep 15th, 2011
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. const int COMPANY_SIZE = 50;
  9. struct employeeType
  10. {
  11.     string firstName;
  12.     string lastName;
  13.     int personID;
  14.     string deptID;
  15.     double yearlySalary;
  16.     double monthlySalary;
  17.     double yearToDatePaid;
  18.     double monthlyBonus;
  19. };
  20.  
  21. void readEmpData(ifstream& infile, employeeType *emp, int length);
  22. void outputEmpData(ofstream& outfile, employeeType *emp, int length);
  23.  
  24. int main()
  25. {
  26.     employeeType employees[COMPANY_SIZE]; // stucts in arrays
  27.     ifstream inFile;
  28.     ofstream outFile;
  29.     inFile.open("employRecords.dat");
  30.     if (!inFile)
  31.     {
  32.         cout << "Data file (employRecords.dat) does not exist." << endl;
  33.         return 1;
  34.     }
  35.     outFile.open("employRecords.out", ios::app);
  36.     readEmpData(inFile, employees, COMPANY_SIZE);
  37.     outputEmpData(outFile, employees, COMPANY_SIZE);
  38.    
  39.     inFile.close();
  40.     outFile.close();
  41.    
  42.     return 0;
  43. }
  44.  
  45. void readEmpData(ifstream& infile, employeeType& emp, int length)
  46. {
  47.     int counter;
  48.    
  49.     for (counter = 0; counter < length; counter++)
  50.     {
  51.         infile >> emp[counter].firstName >> emp[counter].lastName
  52.                >> emp[counter].personID >> emp[counter].deptID
  53.                >> emp[counter].yearlySalary;
  54.        
  55.         emp[counter].monthlySalary = emp[counter].yearlySalary / 12;
  56.         emp[counter].yearToDatePaid = 0.0;
  57.         emp[counter].monthlyBonus = 0.0;
  58.     }
  59. }
  60.  
  61. void outputEmpData(ofstream& outfile, employeeType& emp, int length)
  62. {
  63.     int counter;
  64.     double payCheck;
  65.     for (counter = 0; counter < length; counter++)
  66.     {
  67.         cout << emp[counter].firstName << " " << emp[counter].lastName << " "
  68.              << endl;
  69.              
  70.         outfile << emp[counter].firstName << " " << emp[counter].lastName << " "
  71.              << endl;
  72.              
  73.         payCheck = emp[counter].monthlySalary + emp[counter].monthlyBonus;
  74.        
  75.         emp[counter].yearToDatePaid = emp[counter].yearToDatePaid + payCheck;
  76.        
  77.         cout << setprecision(2) << payCheck << endl;
  78.        
  79.         outfile << setprecision(2) << showpoint << payCheck << endl;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement