/* Course Number : ISYS 116 Student Name : Jason Gradziel Student Number : 826-135-535 Professors Name : Gene Rychlewski Class Name : Thursday Lab Title : Assignment # 10 Pgm: PAYENTRY */ #include #include #include #include void getyesno(); FILE *Safe_fopen(char *, char *); void Safe_fclose(FILE *); typedef struct { char employee_id[5]; float hours_worked[5]; double rate_per_hour; } EMPLOYEE_REC; typedef char *STRING; typedef enum { mon,tue,wed,thu,fri,sat,sun } DAY; /* Global Variables */ int flag =1; main() { clrscr(); FILE *input_file, *output_file; EMPLOYEE_REC employee; int record_count = 0; int days; STRING day_names[7] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; DAY day; output_file = Safe_fopen("payentry.dat", "w+b"); while(flag == 1) { gotoxy(32,1); printf("**************"); gotoxy(32,2); printf("* Data Entry *"); gotoxy(32,3); printf("**************"); gotoxy(9,6); printf("Please enter the following :"); gotoxy(17,8); printf("Employee id number : _____"); gotoxy(20,9); printf("Hours worked on : "); gotoxy(29,10); printf("%s : ___", day_names[0]); gotoxy(28,11); printf("%s : ___", day_names[1]); gotoxy(26,12); printf("%s : ___", day_names[2]); gotoxy(27,13); printf("%s : ___", day_names[3]); gotoxy(29,14); printf("%s : ___", day_names[4]); gotoxy(12,15); printf("Employees rate per hour : _____"); gotoxy(38,8); gets(employee.employee_id); days=0; for (day = mon; day <= fri; ++day) { gotoxy(38,days+10); scanf("%f", &employee.hours_worked[day]); days++; } gotoxy(38,15); scanf("%lf", &employee.rate_per_hour); while ( fscanf(output_file, "%s %f %lf", employee.employee_id, &employee.hours_worked, &employee.rate_per_hour) == 3) { fwrite(&employee, sizeof(EMPLOYEE_REC), 1, output_file); ++record_count; } getyesno(); gotoxy(20,20); printf(" "); fflush(stdin); }// end of while quit loop gotoxy(20,18); printf("%d record(s) were written.", record_count); Safe_fclose(output_file); gotoxy(20,23); printf("Press any key to comtinue..."); 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); } 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); } return; } void getyesno() { int flag2=1; while (flag2==1) { char quit,y,Y,n,N; gotoxy(20,20); printf("Do you want to quit?(Y/N) "); quit=getche(); getch(); if (quit == 'Y' || quit == 'y') { //printf("\n\tBye Bye!"); flag = 0; flag2=0; delay(500); //getch(); } else if (quit == 'N' || quit == 'n') { //printf("\n\tO.K."); delay(500); flag2=0; //getch(); } else { printf("\n\tThat is incorrect."); delay(500); //getch(); } } }