/* Course Number : ISYS 116 Student Name : Jason Gradziel & Peter Newton Student Number : 826-135-535 826135725 Professors Name : Gene Rychlewski Class Name : Thursday Lab Title : Assignment # 10 Pgm: PAYCALC */ #include #include #include #include FILE *Safe_fopen(char *, char *); void Safe_fclose(FILE *); typedef struct { char emp_id[5]; float pay_rate; float week_day[5]; } EMP_REC; /*typedef struct { char employee_id[5]; int hours_worked[5]; double rate_per_hour; } EMPLOYEE_REC;*/ typedef char *STRING; //typedef enum { // mon,tue,wed,thu,fri,sat,sun // } DAY; main() { clrscr(); FILE *input_file, *output_file; EMP_REC employee; //EMPLOYEE_REC employee; int record_count = 0; int days; double total_hours, payroll=0, gross; STRING day_names[7] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; //DAY day; gotoxy(32,1); printf("**************"); gotoxy(32,2); printf("* Data Calcs *"); gotoxy(32,3); printf("**************"); input_file = Safe_fopen("a:input.dat", "rb"); output_file = Safe_fopen("a:output.dat", "w"); gotoxy(6,5); printf("Employee Id Days Worked Houry Rate\n\n"); for(int day =0; day<5; ++day) { gotoxy(30,day+7); printf("%s",day_names[day]); } gotoxy(11,14); printf("Total Hours"); gotoxy(32,14); printf("Gross Pay"); fread(&employee, sizeof(EMP_REC), 1, input_file); while ( !feof (input_file)) { total_hours=0; ++record_count; fprintf(output_file, "\n\n\t %s \t%.2f %.2f %.2f %.2f %.2f\t%.2f",employee.emp_id,employee.week_day[0], employee.week_day[1],employee.week_day[2],employee.week_day[3],employee.week_day[4],employee.pay_rate); //%7s%5.2f%5.2f%5.2f%5.2f%5.2f%6.2f", employee.employee_id, employee.week_day[0], employee.hours_worked[1],employee.hours_worked[2],employee.hours_worked[3],employee.hours_worked[4],employee.rate_per_hour); //fprintf(input_file, "\n\n%15s%15f%15.2f", employee.employee_id, employee.hours_worked, employee.rate_per_hour); //printf("\n\n%7d%5.2f%5.2f%5.2f%5.2f%5.2f%6.2f", employee.employee_id, employee.hours_worked[0], employee.hours_worked[1],employee.hours_worked[2],employee.hours_worked[3],employee.hours_worked[4],employee.rate_per_hour); //printf("\n\n\t %s \t%.2f %.2f %.2f %.2f %.2f\t%.2f",employee.employee_id,employee.hours_worked[0], employee.hours_worked[1],employee.hours_worked[2],employee.hours_worked[3],employee.hours_worked[4],employee.rate_per_hour); gotoxy(9,7); for(int a=0; a<5; ++a) { printf("%c",employee.emp_id[a]); } for(day =0; day<5; day++) { gotoxy(40,day+7); printf("%.1f",employee.week_day[day]); total_hours+=employee.week_day[day]; } gotoxy(59,7); printf("$ %.2f",employee.pay_rate); gross = total_hours * employee.pay_rate; payroll += gross; gotoxy(13,16); printf("%.1f",total_hours); // Print the totals gotoxy(32,16); printf("$ %.2f",gross); fread(&employee, sizeof(EMP_REC), 1, input_file); gotoxy(20,22); printf("End of the %d record.",record_count); gotoxy(20,23); printf("Press any key to continue...."); getch(); gotoxy(20,22); printf(" "); gotoxy(20,23); printf(" "); gotoxy(11,16); printf(" "); // Clear the totals off the screen gotoxy(31,16); printf(" "); } gotoxy(20,20); printf("%d record(s) were written.", record_count); gotoxy(49,14); printf("Total Payroll"); gotoxy(52,16); printf("$ %.2f",payroll); Safe_fclose(input_file); Safe_fclose(output_file); gotoxy(20,23); printf("Program Complete. Press any key to exit... "); getch(); return 0; } FILE * Safe_fopen(char *f_name, char *mode) { FILE *file_ptr; if ( (file_ptr = fopen(f_name, mode)) == NULL) { fprintf(stderr, "\nError: File %s cannot be opened.", f_name); getch(); exit(1); } else { gotoxy(20,22); printf("File %s was succfully opened.", f_name); delay(1000); gotoxy(20,22); printf(" "); } return file_ptr; } void Safe_fclose(FILE *file_ptr) { if ( fclose(file_ptr) == EOF) { fprintf(stderr, "\nError: The file cannot be closed."); getch(); exit(1); } else { gotoxy(20,22); printf("File was succfully closed."); delay(500); gotoxy(20,22); printf(" "); } return; }