#include
Struct info {char NUM [20]; char name [10]; float cj; struct info * next; structure;
void author (); struct info * input (struct info *); struct info * search (char *, struct info *); struct info * del (char *, struct info *); struct info * deleteMenu (struct info *) Void searchMenu (STRUCT INFO * FPTR); Void Savedata (STRUCT INFO *); Struct Info *); Void Showall (Struct Info *); Struct Info * Sort;
Void main () {
Struct info * first = 0; intangoose; author (); while (1) {printf ("*********************************** ******************************* / N "); Printf (" * 1: joining a new record 2: Delete a record 3: Query (modify) a record * / n "); Printf (" * 4: Exit program 5: Save Data 6: Load Data * / N "); Printf (" * 7: Show all records 8: Press grade Sort record * / n "); Printf (" ****************************************************** ******************* / n "); Printf (" Please select (1 ~ 8): "); scanf ("% d ", & choose); Printf "/ n"); switch (choise) {case 1: first = INPUT (FIRST); Break; Case 2: first = deleteMenu (first); break; case 3: searchmenu (first); break; casse 4: return; Case 5: Savedata (First); Break; Case 6: First = loadingdata (first); Break; Case 7: Showall (First); Break; Case 8: First = Sort (first); Break; default: printf ("Input Error! / N / n / n "); Break;} printf (" / n / n / n ");}}
Struct info * input (struct info * fptr) {struct info * i; i = (struct info *) malloc (SIZEOF (STRUCT INFO));
Printf ("Enter the Scholar:"); Scanf ("% S", I-> Num); Printf ("Enter the Name:"); Scanf ("% S", I-> Name); Printf ("Enter the results:"); scanf ("% f", & (i-> cj)); (i-> next) = fptr; if (fptr! = 0) {(fptr-> last) = I;} (I-> Last) = 0; FPTR = I; RETURN FPTR;} Struct Info * Del (Char * S, Struct Info * fptr) {struct info * r; r = Search (S, FPTR); IF (r == 0) {Printf ("No record can be deleted! / n / n / n"); Return FPTR;} else {if (r == fptr) {fptr = fptr-> next; free (r); Printf ("Delete Success! / N / N / N"); Return FPTR;} ((R-> Last) -> Next) = (R-> Next); Free (R); Printf ("Delete Success! / N / N / N "); return fptr;}}
Struct info * search (char * s, struct info * fptr) {int R; if (fptr == 0) {RETURN 0;} while (1) {r = strcmp (fptr-> Num, s); if (r == 0) {R = strcmp (fptr-> Name, s); if (r == 0) {RETURN FPTR;} if (fptr-> next)! = 0) {fptr = (FPTR -> Next);} else {return 0;}}}
Struct info * deletemenu (struct info * fptr) {char NN [20]; Printf ("Enter the name or student number:"); scanf ("% s", nn); Return del (NN, FPTR);}
Void searchMenu (struct info * fptr) {int yorn; char nn [2]; struct info * r; printf ("Enter the name or learn:"); scanf ("% s", nn); r = Search (NN, FPTR); if (r == 0) {Printf ("Check no record! / n / n / n"); return;} else {printf ("Learning:% s Name:% S) f / n / n / n ", r-> Num, r-> Name, r-> CJ); Printf (" Do you want to modify? (1 = Yes, 0 = no) "); scanf ("% D " , & yorn); IF (YORN == 1) {Printf ("Enter the alive:"); scanf ("% s", r-> num); Printf ("Enter the name:"); scanf "% s", r-> name); Printf ("Enter the results:"); scanf ("% f", & (r-> cj)); printf ("Successful modification! / n / N / N ");}}} Void savedata (struct info * fptr) {file * fp; if (fptr == 0) {printf (" No record can be saved! / N / n "); return;}
FP = FOPEN ("Info.stu", "WB "); While (1) {FWRITE (FPTR, SIZEOF (Struct Info), 1, FP); FPTR = (fptr-> next); if (fptr == 0 ) {Breaf;}} printf ("Saved! / N"); fclose (fp);
Struct Info * loadData {struct info * now = 0; struct info * Up = 0; file * fp; if ((fp = fopen ("info.stu", "rb") == null ) {Printf ("Unable to open file"); return fptr;} fptr = (struct info *) malloc (Struct info)); UP = fptr; Fread (FPTR, SIZEOF (Struct Info), 1, FP); IF ((fptr-> next) == 0) {printf ("Data loading success! / n / n / n"); return fptr;} while (1) {now = (Struct info *) Malloc (Sizeof (SIZEOF Struct info); FREAD (NOW, SIZEOF (STRUCT INFO), 1, FP); (now-> last) = Up; (UP-> Next) = now; UP = now; if ((now-> Next) == 0) {fclose (fp); Printf ("Data Load Success! / N / N / N"); Return FPTR;}}}
Void Showall (Struct Info * FPTR) {IF (FPTR == 0) {Printf ("No Record! / N / N / N"); Return;} While (1) {Printf ("Learn:% s Name: % s grades:% f / N --------------------------- / n ", fptr-> num, fptr-> Name , fptr-> cj); fptr = fptr-> next; if (fptr == 0) {printf ("Show success! / n / n / n"); return;}}} void author ()}}} void author ()}} ********************************************* / N " ); printf ( "* easy achievement of: Zhou Wei * / n"); printf ( "* statistical system version: 1.1 * / n"); printf ( "************** ********************** / N / N / N ");}
Struct info * sort (struct info * fptr) {struct info * now; struct info * ne; struct info * temp = 0;
IF (FPTR == 0) {Printf ("No record can be sorted!"); returnif;} while (1) {INT i = 0; int J = 1; now = fptr; ne = (fptr-> next) ; If ((now-> next) == 0) {Printf ("Sort Success!"); Return FPTR;} While (1) {IF ((NOW-> CJ) <(NE-> CJ)) {TEMP = (NE-> Next) = now; (now-> next) = Temp; Temp = (now-> last); (now-> last) = ne; (NE-> Last) = TEMP; if (Temp! = 0) {(TEMP-> Next) = ne;}} (j == 1) {fptr = Ne;} Ne = 1;} else { Now = ne; ne = (ne-> next);} J ; if ((now-> next) == 0) {Break;}} if (i == 0) {Printf ("Sort Success!"); Return fptr;}}}