Write C program that helps a Professor to manage student records. Each student’s
ID: 3781337 • Letter: W
Question
Write C program that helps a Professor to manage student records. Each student’s record contains information like Student ID, Name, Course Major & CGPA, and are then stored in a text file.
The following software reads students’ information from a file, and allows the Professor to do the following:
1) Print The List Of Student Records.
2) Add New Student Record.
3) Update Information On Existing Record,
4) Sort Student Records (according to student identification number) Into Ascending Order,
5) Save The Updated Student Records In A File.
In updating student’s details, one needs to search for the student record from the existing records. In this application, linear search and binary search are to be implemented. On the other hand, selection sort and insertion sort algorithms are to be implemented to sort data.
Note that two for each sorting and searching algorithms are used in the program. Your program should select the suitable algorithms accordingly. For example, if the Professor opts to search for a student details from a medium size of an unsorted student records, in this case binary search is more preferable over linear search for faster time complexity. However, binary search requires input data to be sorted. In selecting sorting algorithm, the program might want to consider the randomness of the data.
Options Display should be mentioned after every task completed to as user to continue to main menu or quit program.
Explanation / Answer
#include struct Student { int studentID; char name[25]; char course[25]; float cgpa; }; Student s,s2; void display(FILE *); void insert(File *); int search(FILE *,int); void print(Student s); void main() { int i,n,studentID,opn; FILE *fp; do { printf("Press 1>Display list of students 2>Add new student record 3>Update student record Search 4>Sort records 4> Exit select choice?"); scanf("%d",&opn); switch(opn) { case 1: printf(" Student Records in the File "); display(fp); break; case 2: insert(fp); break; case 3: printf(" Enter the student id of the student to be updates ?"); scanf("%d",&studentID); if(search(fp,studentID)) { printf("Success ! Record found in the file "); update(fp,studentID); } else printf(" Failure!! Record with studentID %d not found ",studentID); break; case 5: printf(" Exit!! Press a key . . ."); getch(); break; default: printf(" Invalid Option!!! Try again !!! "); break; } }while(opn != 3); fclose(fp); } /* End of main() */ void display(FILE *fp){ fp=fopen("student.dat","r"); rewind(fp); while(fread(&s,sizeof(s),1,fp)){ print(s); } fclose(fp); } void print(Student s){ printf(" Info of the Student: "); printf("Student id : %d ",s.studentID); printf("Name : %d ",s.name); printf("Course : %d ",s.course); printf("CGPA : %d ",s.cgpa); } void insert(FILE *fp){ printf(" How many Records ? "); scanf("%d",&n); fp=fopen("student.dat","w"); fseek(fp, 0, SEEK_END); for(i=0;iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.