# Include "stdio. H "# include" stdlib. H "# include" string. H "# include" process. H "typedef struct subjects {int num; // course No. Char name [20]; // Course name char kind [10]; // Course Nature int stime; // int tTime in total; // int etime in course of teaching; // int score in lab or computer; // int term in credits; // struct subjects * Next in course class term ;} sub; sub * create_form () // create a linked list {sub * head, * tail, * P; int num, stime, tTime; int etime, score, term; char name [20], kind [10]; int size = Sizeof (sub); Head = tail = NULL; printf ("Enter the elective course information: \ n "); scanf ("% d % S % d", & num, name, kind, & stime, & tTime, & etime, & score, & term); While (num! = 0) {P = (sub *) malloc (size); P-> num = num; strcpy (p-> name, name); strcpy (p-> kind, kind); P-> stime = stime; P-> tTime = tTime; P-> etime = etime; P-> score = score; P-> term = term; if (Head = NULL) Head = P; else tail-> next = P; tail = P; scanf ("% d % S % d", & num, name, kind, & stime, & tTime, & etime, & score, & term) ;}tail-> next = NULL; return head;} void SaveFile (sub * head) // Save the created linked list to the file {sub * P; file * FP; if (FP = fopen ("E: \ subje Cts.txt "," W ") = NULL) {printf (" Open fail! \ N "); exit (0);} fprintf (FP," course No. Course name course nature when teaching lab or on-board course class term \ n "); for (P = head; P = p-> next) fprintf (FP, "% 5d % 12 S % 9 S % 9d % 9d % 11d % 11d % 7D \ n", p-> num, p-> name, p-> kind, p-> stime, p-> tTime, p-> etime, p-> score, p-> term); If (fclose (FP) {printf ("Close fail! \ N "); exit (0);} printf (" \ n "in \ n");} void savefileadd (sub * head) // Save the modified information to the new file {sub * P; file * FP; If (FP = fopen ("E: \ subjectsadd.txt", "W ")) = NULL) {printf ("Open fail! \ N "); exit (0);} fprintf (FP," course No. Course name course nature when teaching lab or on-board course class term \ n "); for (P = head; P = p-> next) fprintf (FP, "% 5d % 12 S % 9 S % 9d % 9d % 11d % 11d % 7D \ n", p-> num, p-> name, p-> kind, p-> stime, p-> tTime, p-> etime, p-> score, p-> term); If (fclose (FP) {printf ("Close fail! \ N "); exit (0);} printf (" \ n "in the latest subjectsadd.txt file where the modified information is stored in the edisk root directory);} void savefiledel (sub * head) // Save the modified information to the new file {sub * P; file * FP; If (FP = fopen ("E: \ subjectsdel.txt", "W ")) = NULL) {printf ("Open fail \ n"); exit (0);} fprintf (FP, "course No. Course name Course Nature total class hours lab or on-board class credits course class term \ n"); For (P = head; P = p-> next) fprintf (FP, "% 5d % 12 S % 9 S % 9d % 9d % 11d % 11d % 7D \ n", p-> num, p-> name, p-> kind, p-> stime, p-> tTime, p-> etime, p-> score, p-> T ERM); If (fclose (FP) {printf ("Close fail! \ N "); exit (0);} printf (" \ n "in the latest subjectsdel.txt file where the modified information is stored in the edisk root directory);} void Prin (sub * head) // output information {sub * PTR; if (Head = NULL) {printf ("no records! \ N "); return;} printf (" course No. Course name Course Nature total class hours practice or on-board credits course class term \ n "); For (PTR = head; PTR; PTR = PTR-> next) printf ("% 5d % 12 S % 9 S % 9d % 9d % 11d % 11d % 7D \ n", PTR-> num, PTR-> name, PTR-> kind, PTR-> stime, PTR-> tTime, PTR-> etime, PTR-> score, PTR-> term );} void search (sub * head) // query information {int A, num; int T = 1; char type [10]; char CH = 'A', substring; sub * PTR; while (Ch! = '') {Printf (" if you want to search by course nature, enter 1. If you want to search by credit, enter 2: \ n "); scanf (" % d ", & A); Switch (a) {Case 1: printf ("Enter the nature of the course to be searched: \ n"); scanf ("% s", type ); printf ("course No. Course name Course Nature total class hours practice or on-board class credits course class term \ n"); For (PTR = head; PTR = PTR-> next) if (strcmp (type, PTR-> kind) = 0) {printf ("% 5d % 12 S % 9 S % 9d % 9d % 11d % 11d % 7D \ n", PTR-> num, PTR-> name, PTR-> kind, PTR-> stime, PTR-> tTime, PTR-> etime, PTR-> score, PTR-> term); t = 0;} If (t) printf ("not found! \ N "); t = 1; break; Case 2: printf (" Enter the credits of the course to be searched \ n "); scanf (" % d ", & num ); printf ("course No. Course name Course Nature total class hours practice or on-board class credits course class term \ n"); For (PTR = head; PTR = PTR-> next) if (PTR-> score = num) {printf ("% 5d % 12 S % 9 S % 9d % 9d % 11d % 11d % 7D \ n ", PTR-> num, PTR-> name, PTR-> kind, PTR-> stime, PTR-> tTime, PTR-> etime, PTR-> score, PTR-> term); t = 0;} If (t) printf ("not found! \ N "); t = 1;} printf (" continue searching press enter, End Press space: \ n "); character = getchar (); // assign the carriage return key to the carriage return key. Otherwise, the carriage return key entered in the case will be assigned to the CH key, so use the carriage return key to fill the key. Ch = getchar () ;}} sub * insert (sub * head) // insert information {sub * PTR, * ptr2, * subj; int size = sizeof (sub ); char CH = 'A', while; while (Ch! = '') {Subj = (sub *) malloc (size); PTR = subj; printf (" Enter the course information to insert: \ n "); scanf ("% d % S % d", & subj-> num, subj-> name, subj-> kind, & subj-> stime, & subj-> tTime, & subj-> etime, & subj-> score, & subj-> term); If (Head = NULL) {head = PTR; head-> next = NULL;} else {for (ptr2 = head; ptr2; ptr2 = ptr2-> next) if (ptr2-> next = NULL) {ptr2-> next = subj; subj-> next = NULL; break;} printf ("continue inserting, press enter, and press the space: \ n "); keys = getchar (); // assign the carriage return key to Ch 1. Otherwise, the input return key after the input of subj-> term is assigned to CH, so use limit to fill it. Ch = getchar ();} return head;} sub * del (sub * head) // delete information {sub * P1, * P2; char CH = 'A', cursor; int num; while (Ch! = '') {Printf (" Enter the course number you want to delete: \ n "); scanf (" % d ", & num ); if (Head-> num = num) {P2 = head; head = head-> next; free (P2);} If (Head = NULL) return NULL; p1 = head; P2 = head-> next; while (P2) {If (P2-> num = num) {p1-> next = P2-> next; free (P2);} else p1 = P2; P2 = p1-> next;} printf ("continue to delete, press enter, and press space: \ n "); keys = getchar (); // assign the Enter key to keys. Otherwise, the Enter key after num is input will be assigned to CH, so use keys to fill it. Ch = getchar ();} return head;} void choose (sub * head) // Student Course Selection {sub * P, * q; int A [5]; int num, total = 0, I = 0, J; printf ("Enter the number of the course to be selected, separate the numbers with spaces, and end with 0 after the input "); scanf ("% d", & num); While (num! = 0) {for (P = head; P = p-> next) if (p-> num = num) {Total = total + P-> score; A [I] = num; I ++;} scanf ("% d", & num);} If (total <60) printf ("the total number of elective credits is less than 60, failed to select course! \ N "); else {printf (" selected successfully! \ N "); printf (" the course you selected is \ n "); For (j = 0; j For (q = head; q; Q = Q-> next) if (Q-> num = A [J]) printf ("% s", Q-> name ); printf ("\ n") ;}} void readfile () // re-read the first created file {int num, stime, tTime, etime; int score, term; char C, name [20], kind [10]; file * fp = fopen ("E: \ subjects.txt", "R"); While (! Feof (FP) {If (C = fgetc (FP) = '\ n') break ;} printf ("course No. Course name course nature when teaching lab or on-board course class term \ n"); While (! Feof (FP) {fscanf (FP, "% d % S % d \ n", & num, name, kind, & stime, & tTime, & etime, & score, & term ); printf ("% 5d % 12 S % 9 S % 9d % 9d % 11d % 11d % 7D \ n", num, name, kind, stime, tTime, etime, score, term);} fclose (FP);} void main () {sub * head; int I; char C; printf ("\ n "); for (I = 0; I <34; I ++) printf ("*"); printf ("course information entry"); for (I = 0; I <34; I ++) printf ("*"); printf ("\ n"); Head = create_form (); SaveFile (head ); printf ("\ n"); for (I = 0; I <34; I ++) printf ("*"); printf ("course information output"); for (I = 0; I <34; I ++) printf ("*"); printf ("\ n"); Prin (head); printf ("\ n"); for (I = 0; I <34; I ++) printf ("*"); printf ("course info search"); for (I = 0; I <34; I ++) printf ("*"); printf ("\ n"); search (head); printf ("\ n"); for (I = 0; I <34; I ++) printf ("*"); printf ("course information insertion"); for (I = 0; I <34; I ++) printf ("*"); printf ("\ n"); Head = insert (head); // pay attention to the necessity. The return value of the insert function is re-assigned to the head! Savefileadd (head); printf ("modified information: \ n"); Prin (head); printf ("\ n"); for (I = 0; I <34; I ++) printf ("*"); printf ("course information deletion"); for (I = 0; I <34; I ++) printf ("*"); printf ("\ n"); Head = del (head); // pay attention to the necessity. the return value of the del function is re-assigned to the head! Savefiledel (head); printf ("the modified course information is \ n"); Prin (head); printf ("\ n "); for (I = 0; I <34; I ++) printf ("*"); printf ("course optional"); for (I = 0; I <34; I ++) printf ("*"); printf ("\ n"); choose (head); printf ("Why re-display the contents of File Upload subjects.txt" (y/n )? \ N "); getchar (); // receives the carriage return character c = getchar (); if (C = 'y' | C = 'y') {printf ("\ n"); printf ("“subjects.txt" file information is: \ n "); readfile () ;}else printf (" program ended! \ N ");}