/* Write an interactive program in C language to manage the study centre with menu optionslike student's details, semester enrolled for, assignments Submitted and marks obtained,attendance for the practical courses etc. using the file handling concepts. The application should be designed user-friendly. */ #include<stdio.h> #include #include<process.h> void main() {0
24 struct student_record { char name[100]; unsigned long int enrollment_no; int semester; struct marks_obtained { int sub1, sub2, sub3, sub4, sub5, sub6, sub7; }marks; };7. struct student_record student; FILE *fp, *fp1; int choice, flag, add_another, view_another, modify_another, delete_another; unsigned long int search_enrollment_no; long int size=sizeof(student); char a[100], name[100]; clrscr(); fp=fopen("STUDENT.DAT", "rb+"); if(fp==NULL) { fp=fopen("STUDENT.DAT", "wb+"); if(fp==NULL) { printf("\nError! Cannot open the File.\n"); exit(0); } } while(1) { printf("\n"); printf("\t\t****************************************\n"); printf("\t\t\t PCTI RECORD MANAGEMENT\n"); printf("\t\t****************************************\n"); printf("\n\n"); printf("\t\t\t 1. Add Records.\n"); printf("\t\t\t 2. View Records.\n"); printf("\t\t\t 3. Modify Records.\n"); printf("\t\t\t 4. Delete Records.\n"); printf("\t\t\t 0. Exit.\n"); printf("\n"); printf("\t\t\tEnter Your Choice :=>> "); choice_again: scanf("%d", &choice); switch(choice) { case 1: { clrscr(); fseek(fp, 0, SEEK_END); add_another=1; while(add_another==1) {
printf("\n"); printf("\t\t*********************************************\n"); printf("\t\t\t INPUT STUDENT DATA\n"); printf("\t\t*********************************************\n"); printf("\n\n"); printf("\t\t Enter Student's Name :=> "); gets(a); // scanf("%s", student.name); printf("\t\t Enter Enrollment No. :=> "); scanf("%lu", &student.enrollment_no); printf("\t\t Semester Enrolled For :=> "); scanf("%d", &student.semester); printf("\n\t\t\t\tINPUT MARKS"); printf("\n\t\t\t _______________________\n\n"); printf("\t\t\t 1. MCS-011 :=> "); scanf("%d", &student.marks.sub1); printf("\t\t\t 2. MCS-012 :=> "); scanf("%d", &student.marks.sub2); printf("\t\t\t 3. MCS-013 :=> "); scanf("%d", &student.marks.sub3); printf("\t\t\t 4. MCS-014 :=> "); scanf("%d", &student.marks.sub4); printf("\t\t\t 5. MCS-015 :=> "); scanf("%d", &student.marks.sub5); printf("\t\t\t 6. MCS-016 :=> "); scanf("%d", &student.marks.sub6); printf("\t\t\t 7. MCS-017 :=> "); scanf("%d", &student.marks.sub7); printf("\n"); fwrite(&student, size, 1 , fp); /* Writes Data to the File.*/ printf("\t\t Record Succussfully Added!\n\n"); printf("\t\t Want to Add One More Record?\n"); printf("\t\t Press 1 Otherwise Press 0 ..... "); add_another_again: /*Label for Goto Statement.*/ scanf("%d",&add_another); if(add_another!=1 && add_another!=0) /*Validation Checking.*/ { printf("\n\t\t Please Enter only 1 OR 0 ..... "); goto add_another_again; /*Goto Statement.*/ } else { clrscr(); } } break; } case 2: { clrscr(); view_another=1; while(view_another==1) { printf("\n");
printf("\t\t*********************************************\n"); printf("\t\t\t VIEW STUDENT RECORD\n"); printf("\t\t*********************************************\n"); printf("\n\n"); printf("\tEnter Student's Enrollment No. = "); scanf("%lu", &search_enrollment_no); rewind(fp); flag=0; while(fread(&student, size, 1, fp)==1) { if(search_enrollment_no==student.enrollment_no) { printf("\n"); printf("\t\t\tStudent's Name = %s\n", student.name); printf("\t\t\tEnrollment No. = %lu\n", student.enrollment_no); printf("\t\t\tSemester Enrolled For = %d\n", student.semester); printf("\n\t\t\t\tMARKS OBTAINED"); printf("\n\t\t\t _______________________\n\n"); printf("\t\t\t 1. MCS- 011:=> %d\n", student.marks.sub1); printf("\t\t\t 2. MCS- 012:=> %d\n", student.marks.sub2); printf("\t\t\t 3. MCS- 013:=> %d\n", student.marks.sub3); printf("\t\t\t 4. MCS- 014:=> %d\n", student.marks.sub4); printf("\t\t\t 5. MCS- 015:=> %d\n", student.marks.sub5); printf("\t\t\t 6. MCSL-016:=> %d\n", student.marks.sub6); printf("\t\t\t 7. MCSL-017:=> %d\n", student.marks.sub7); flag=1; } } if(flag!=1) { printf("\n\t\t\tRecord doesn't not Exist.\n"); } printf("\n"); printf("\t\t Want to View More Records?\n"); printf("\t\t Press 1 Otherwise Press 0 ..... "); view_another_again: /*Label for Goto Statement.*/ scanf("%d",&view_another); if(view_another!=1 && view_another!=0) /*Validation Checking.*/ { printf("\n\tPlease Enter only (1 for YES / 0 for NO) = "); goto view_another_again; /*Goto Statement.*/ } else { clrscr(); } } break; } case 3: { clrscr(); modify_another=1; while(modify_another==1)
{ printf("\n"); printf("\t\t*********************************************\n"); printf("\t\t\t MODIFY STUDENT RECORD\n"); printf("\t\t*********************************************\n"); printf("\n\n"); printf("\t\tEnter Student's Enrollment No. = "); scanf("%lu", &search_enrollment_no); rewind(fp); flag=0; while(fread(&student, size, 1, fp)==1) { if(search_enrollment_no==student.enrollment_no) { printf("\n"); if("\t\tEnter Student's New Name = "); scanf("%s", student.name); printf("\t\tNew Enrollment No. = "); scanf("%lu", &student.enrollment_no); printf("\t\tNew Semester Enrolled For = "); scanf("%d", &student.semester); printf("\n"); fseek(fp, -size, 1); fwrite(&student, size, 1 , fp); /* Writes Data to the File.*/ flag=1; break; } } if(flag!=1) { printf("\n\t\tRecord doesn't not Exist.\n"); } else { printf("\n\t\tRecord Modified Successfully.\n"); } printf("\n"); printf("\t\tWant to Modify More Records?\n"); printf("\t\tPress 1 Otherwise Press 0 ..... "); modify_another_again: /*Label for Goto Statement.*/ scanf("%d",&modify_another); if(modify_another!=1 && modify_another!=0) /*Validation Checking.*/ { printf("\n\tPlease Enter only (1 for YES / 0 for NO) = "); goto modify_another_again; /*Goto Statement.*/ } else { clrscr(); } } break; } case 4:
{ delete_another=1; while(delete_another==1) { printf("\n"); printf("Enter Student's Enrollment No. = "); scanf("%lu", &search_enrollment_no); fp1=fopen("TEMP.DAT", "wb"); rewind(fp); while(fread(&student, size, 1, fp)==1) { if(search_enrollment_no!=student.enrollment_no) { fwrite(&student, size, 1, fp1); } } fclose(fp); fclose(fp1); remove("STUDENT.DAT"); rename("TEMP.DAT", "STUDENT.DAT"); fp=fopen("STUDENT.DAT", "rb+"); printf("Do you want to Delete One More Record (1 for YES / 0 for NO) = "); delete_another_again: /*Label for Goto Statement.*/ scanf("%d",&delete_another); if(delete_another!=1 && delete_another!=0) /*Validation Checking.*/ { printf("Invalid Choice!\n"); printf("Please Enter only (1 for YES / 0 for NO) = "); goto delete_another_again; /*Goto Statement.*/ } } break; } case 0: { fclose(fp); exit(0); break; } default: { printf("\t\tInvalid Choice!\n"); printf("\t\tPlease Enter a Valid choice = "); goto choice_again; /*Goto Statement.*/ } } } getch();