/********************************************************************************** * Course Number : CIS-112 * * Assignment : Project # 4 * * Due Date : May 8/9, 2002 * * Author : Jim Chaires * * Instructor : Jim Chaires * * Input : Disk File - "personel.bin" * * Output : Screen/Printer * * Program Objective: Program # 4 takes program # 3 and uses objects and * * classes instead of structures. As in program #3, an array * * is built, the array is sorted on name and employees who * * make more than $41,000 are printed. * **********************************************************************************/ #include // PREPROCESSOR DIRECTIVES #include #include #include #include #include ifstream employee_file ("a:personel.bin", ios::in|ios::binary); class employee { private: char last_name [13]; long int ssn; double salary; int years; int dept; public: void open_input_file_fcn (); void print_headers_fcn (); int build_print_array_fcn(employee employee_rec[]) ; void sort_print_array_fcn (employee employee_rec[], int) ; }; // must have both type and identifier name //****************************************************************************** void employee::open_input_file_fcn () { if (employee_file.fail ()) { clrscr(); cout << ("There is a problem locating the input file\n"); exit(1); } } // end fcn //****************************************************************************** void employee::print_headers_fcn() { cout << (" PGCC PERSONNEL REPORT -- Spring 2002\n\n"); cout << (" DIVISION OF BUSINESS AND TECHNOLOGY\n\n"); cout << (" REPORT PREPARED BY: Jim Chaires\n\n"); cout << ("\n Name SSN Salary Years D_Code\n"); } // end fcn //****************************************************************************** int employee::build_print_array_fcn (employee employee_rec[] ) { int i = 0; employee_file.read ( (char*) &employee_rec[i], sizeof (employee_rec[0])); while (!employee_file.eof() ) { cout << "\n" << setw(12) << employee_rec[i].last_name << setw(12) << employee_rec[i].ssn << setw(13) << employee_rec[i].salary << setw(10) << employee_rec[i].years << setw(9) << employee_rec[i].dept; i++; employee_file.read ( (char*) &employee_rec[i], sizeof(employee_rec[0])); } return i; } // end of fcn //****************************************************************************** void employee::sort_print_array_fcn (employee employee_rec [], int num_items) { int i ; int j ; employee temp; // hold area used in sort char dept_string [20] = {" "}; cout << ("\n\n\n\n\n EMPLOYEES MAKING MORE THAN $40,000.00"); cout << ("\n\n ******** SORTED BY LAST NAME ********\n"); cout << ("\n Employee Salary Department\n"); for (i = 0; i < num_items; i++) for (j = (i + 1); j < num_items; j++) if (strcmp(employee_rec[i].last_name,employee_rec[j].last_name)>0) { temp = employee_rec[i] ; employee_rec[i] = employee_rec[j] ; employee_rec[j] = temp ; } // end of if for ( i = 0; i < num_items; i++) if (employee_rec[i].salary > 40000.00) { switch (employee_rec[i].dept) { case 1 : strcpy (dept_string, "Accounting"); break; case 2 : strcpy (dept_string, "Business"); break; case 3 : strcpy (dept_string, "Computer Info Sys"); break; case 4 : strcpy (dept_string, "Criminal Justice"); break; case 5 : strcpy (dept_string, "Engineering"); break; case 6 : strcpy (dept_string, "Engineering Tech"); break; case 7 : strcpy (dept_string, "Office Tech"); break; default: cout << "D-code other than 1 --> 7"; break; } // end of switch cout << "\n" << setw(17) << employee_rec[i].last_name << setw(15) << employee_rec[i].salary << setw(22) << dept_string; } cout << "\n\n"; } // end of fcn //****************************************************************************** void main() { cout << setprecision (2) << setiosflags(ios::fixed) << setiosflags(ios::showpoint); int numitems = 0; clrscr(); class employee employee_rec[50]; // creates an array of 50 employee objects employee_rec[0].open_input_file_fcn() ; employee_rec[0].print_headers_fcn () ; numitems = employee_rec[0].build_print_array_fcn (employee_rec) ; employee_rec[0].sort_print_array_fcn (employee_rec, numitems) ; // cout << "\n\n"; system ("PAUSE"); // Used with version 5.00/5.02 } // end of main ( )