1, password login;
2, through the keyboard input student information, including students study number, name, results;
3, the input information is saved to the specified file;
4, read the student information from the file;
5, display all student information;
6, according to the total score of students in descending order;
7. Deletion of student information;
8, find student information, can be found by the number of students, can also be searched by name;
9, statistics of student information, the highest score and the number of students;
10, exit the system;
Source:
[email protected]:~$ cat main.c #include <stdio.h> #include <stdlib.h> #include <string.h>struct student{char num[9];char name[9];int scorem;int scoree;int scorec; int sum;struct student *next;}; Struct student *creat (STRUCT&NBSP;STUDENT&NBSP;*P)//Create a linked list {struct student *p1 = null;p1 = (struct student*) malloc (sizeof (struct student));p -> next = p1;p1 -> next = null;printf ("Please enter the information for the student to be added \ n");p rintf ("Study No.:"); scanf ("%s", p1 -> num);p rintf ("name: "), scanf ("%s", P1 -> name);p rintf ("Math score:"); scanf ("%d",& P1 -> scorem);p rintf ("English Score:"), scanf ("%d", &p1 -> scoree);p rintf ("C-language score:"); scanf ("%d", &p1 -> scorec);p 1 -> sum = 0;p1 -> sum = p1 -> scorem + p1 -> scorec + p1 -> scoree; printf ("Total score:%d", p1 -> sum); return p1;} VOID&NBSP;SAVE1 (STRUCT&NBSP;STUDENT&NBSP;*P)//Save the list from memory to a file {file *fp;if (Fp = fopen (" Student_system.txt "," ab+ ")) == null) printf (" Create failed!\n "), while (P != null) {fwrite (p,sizeof ( struct student), 1,FP);p = p -> next;} Fclose (FP);p rintf ("Save successfully!\n");} Void save2 (STRUCT&NBSP;STUDENT&NBSP;*P)//will be stored in the file with a variable list of information {file *fp;if (Fp = fopen (" Student_system.txt "," WB ")) == null) printf (" Create failed!\n "), while (P != null) {fwrite (p,sizeof ( struct student), 1,FP);p = p -> next;} Fclose (FP);} Struct student *read ()//Read the data in the file into the linked list {file *fp;struct student *head=null,*p1=null,*p2= null;if ((fp=fopen ("Student_system.txt", "rb+") ==null) {printf ("File open failed when reading!\n");return NULL;} head=p1= (struct student *) malloc (sizeof (Struct student );while (fp != null) {if (Fread (p1,sizeof (struct student ), 1,FP) != 1) break;p1 -> next = (struct student *) malloc (sizeof (struct student ));p 2= p1;p1= p1 -> next;} p2->next = null;fclose (FP); return head;} Struct student *input ()//Add function {char ch;struct student *p = null,*head=null; head=p = (struct student*) malloc (sizeof (struct student));p-> next = null ;p rintf ("Please enter the information for the student to be added \ n");p rintf ("Study No.:"), &NBSP;SCANF ("%s", P -> num);p rintf ("name: "); scanf ("%s", P -> name);p rintf ("Math score:"), scanf ("%d", &p -> scorem);p rintf ("English score:"); scanf ("%d", &p -> scoree);p rintf ("C Language score:"); scanf ("%d", &p -> scorec);p - > sum = 0;p -> sum = p -> scorem + p -> scorec + p -> scoree; printf ("Total score:%d", p -> sum); (;;) {printf ("\ ndo you want to continue entering student information? ( y / n ): \ n "), GetChar ( );ch = getchar ( );if (ch == ' Y ' | | ch == ' Y ') p = creat (p); else if (ch== ' n ' | | ch== ' N ') {save1 (head); else printf ("Your input is wrong, please re-enter,");} Return p->next;} Struct student *output ()//Output function, view all student information {struct student *p ;p = read (); if (Read==null) exit (1);p rintf ("\n *************************student***********************\n");p rintf (" -------------------------------------------------------\ n");p rintf (" | | name | math | english | C language | Total |\n ");p rintf (" -------------------------------------------------------\ n ");while (p != null) {P -> sum = 0;p -> sum = p -> scorem + p -> scoree + p -> scorec;printf ("|%4s |%-4s|%3d |%3d|%3d|%3d|\n",p->num, P->name,p->scorem,p->scoree,p->scorec,p->sum);p rintf (" ----------------------------------- --------------------\ n ");p = p -> next;} Return p;} Struct student *search ()//lookup function {int n;char a[9],b[9];struct student *p = null,*head = null;printf ("Please select the way you want to find:1 by name 2 by number \ n"), scanf ("%d", &n); if (n==1) { printf ("Please enter the name of the student you are looking for: \ n"); scanf ("%s", a);p =head=read (); while (P!=null) {if (p==null) {printf ("Sorry, there are no people you're looking for.") \ n ");} if (strcmp (p -> name,a) ==0) {printf ("\n *************************student********************** *\n ");p rintf (" -------------------------------------------------------\ n ");p rintf (" | Study number | name | math | English |&NBSP;C language | total score |\n ");p rintf (" -------------------------------------------------------\ n "); printf (" | %4s |%-4s|%3d&nbsP;| %3d|%3d|%3d|\n ", p->num, p->name,p->scorem,p->scoree,p->scorec,p->sum);p rintf (" -------------------------------------------------------\ n "); P=p->next;}} if (n==2) {printf ("Please enter the student number you want to find: \ n"), scanf ("%s", b);p =head=read (); while (P!=null) {if (p==null) {printf ("Sorry, there are no people you're looking for.") \ n ");} if (strcmp (p -> num,b) ==0) {printf ("\n *************************student*********************** \ n ");p rintf (" -------------------------------------------------------\ n ");p rintf (" | Study No. | name | math | English |&NBSP;C language | total score |\n ");p rintf (" -------------------------------------------------------\ n "); printf (" | %4s |%-4s|%3d | %3d|%3d|%3d|\n ",p->num, p->name,p-> Scorem,p->scoree,p->scorec,p->sum);p rintf (" ---------------------------------------------------- ---\ n "); break;} P=p->next;}} Return head;} Struct student *dele ()//delete function {struct student *p1=null,*p2=null,*head=Null;char a[9];output ();p rintf ("Please enter the name of the person who needs to delete the information: \ n");scanf ("%s", a);p 1=head=read (); if (head== NULL) {printf ("Sorry, there is no information temporarily, cannot be deleted.") \ n ");} while (head!=null) {if (strcmp (a,head -> name) != 0 && p1->next !=null ) {p2=head ;head= head->next ;if (head==null) break;} if (strcmp (a,head -> name) == 0 && p1==head) {p1=head->next ;} if (strcmp (a,head->name) ==0) {p2->next=head->next;save2 (p1);p rintf ("The student's information was deleted successfully! "); break;}} if (head==null) printf ("Sorry, there is no information for the student.") \ n "); return head;} Struct student *change ()//Modify function {int a;char x[9];struct student *p = Null,*head = null,*q = null;output ();p = head = read ();p rintf (" Please enter the name of the person to be modified: \ n "), scanf ("%s ", x), if (p == null) {printf (" Without this person!\n "); exit (1); while (p != null) {if (strcmp (p -> name,x) == 0) {q = p; break;} P = p -> next;} if (p!=null) {printf ("Please select modified content: \ n");p rintf ("1. Name \ n");p rintf ("2.");p rintf ("3. Math result \");p rintf ("4. English result \ n"); printf ("5.C result \ n");d o {scanf ("%d", &a); if (a < 0 | | a > 6) printf ("You entered the wrong number, please re-enter: \ n");} while (a<=0| | a>=6);switch (a) {case 1 :p rintf ("Please enter the changed name: \ n"); scanf ("%s", P -> name); break;case 2 :p rintf ("Please enter the changed number: \ n"); scanf ("%s", p -> num); break;case 3 : printf ("Please enter the changed math score: \ n"), scanf ("%d", &p -> scorem);break;case 4 :p rintf (" Please enter the changed English score: \ n "), scanf ("%d ", &p -> scoree);break;case 5 :p rintf (" Please enter the changed C score: \ n "); &NBSP;SCANF ("%d", &p -> scorec); p->sum =0;p->sum=p->scorem +p->scoree +p->scorec ;p rintf ("Total after change:%d",p-> sum);save2 (head); output ();} if (p==null) {printf ("Sorry, no this person.") \ n ");} Return head;} Struct&nBsp;student *sortsum (Struct student*head)//Sort function {struct student*p,*p1,*p2,*p3;struct student m, n;if (head == null) return NULL;m.next=head;p=&m;while (P->next!=null) {P=p->next;} p=p->next=&n;while (P!=m.next) {p3=&m;p1=p3->next;p2=p1->next;while (p2!=p) {if (p1 -> sum) < (p2 -> sum) ) {p1->next=p2->next; P2->next=p1;p3->next=p2;p3=p2; p2=p1->next;} Else{p3=p1;p1=p2;p2=p2->next;}} P=P1;} while (p->next!=&n) {p=p->next;} P->next=null;return m.next;} Struct student *outputsortsum ()//score sort Output {Int i=0;struct student *head = null , *p = null;head = read ();p = sortsum (head);p rintf ("\n*************** student****************************\n ");p rintf ("---------------------------------------------------- --------\ n ");p rintF ("| | School Number | name | Mathematics | English | c language | total |\n");p rintf ("----- -------------------------------------------------------\ n "), while (p != null) {i++;p rintf (" | %3d| %4s |%-4s|%3d|%3d|%3d|%3d|\n ",i,p->num,p->name,p->scorem,p->scoree,p->scorec,p-> SUM);p rintf ("------------------------------------------------------------\ n");p =p->next;} Return head;} Struct student *statistic ()//Statistical function {int m = 0;struct student *head=null; Struct student *p,*q;p = head = read (); while ( p != null) {m++;p = p -> next;} printf ("A total of%d student information. \ n", m); Q= sortsum (head);p rintf ("Information of the students with the highest scores: \ n");p rintf ("\n*********************** student*************************\n ");p rintf ("-------------------------------------------------------\ n "); printf ("| | name | math | English | c language | score |\n");p rintf ("-------------------------------------------------------\ n ");p rintf (" | %4s |%-4s|%3d |%3d |%3d| %3d |\n ", Q >num,q->name,q->scorem,q->scoree,q->scorec,q->sum);p rintf ("--------------------------------- ----------------------\ n "); return head;} void login1 () {while (1) {int a=1;int i;char ch[10];char num[20]={"ABCDE"};p rintf ( "Please enter the password \ n" before entering the admin score Management system;p rintf ("Please enter your password : ") scanf ("%s", ch); if (strcmp (num,ch) ==0) {a = 0;} if (a!=0) { printf ("\ n this password is wrong! "); printf (" \ n Please enter the correct password: ");} Else{break;}}} void login2 () {while (1) {int a=1;int i;char ch[10];char num[20]={"12345"}; printf ("Please enter the password before entering the student performance management system \ n");p rintf ("Please enter your password :"); scanf ("%s", ch); if (strcmp (num,ch) ==0) a = 0;if (a==0) {printf ("\ n welcome into Student performance management System !\n"); GetChar (); break;} else {printf ("\ n this password is wrong! ");p rintf (" \ n Please enter the correct password: ");}}} Void menu1 () {System ("clear");p rintf ("Welcome to admin Management System! \ n ");p rintf (" ************************Main Menu ****************************\n ");p rintf (" *1 Add student Achievement *\n ");p rintf (" *2 Find student Achievement *\n ");p rintf (" Delete designated student *\n ");p rintf (" * 4 Modify student Information *\n ");p rintf (" *5 Total sorting information *\n ");p rintf (" *6 View all Information *\n "); printf ("*7 Statistics *\n"), printf ("*8 Stop program Run *\n");p rintf ("**************************************** \ n ");} Void menu2 () { system ("clear");p rintf ("Welcome to the Student management system! \ n ");p rintf (" ******************************* main Menu ****************************\n ");p rintf (" *1 Find student Achievement *\n "); printf ("*2 Score sorting Information *\n");p rintf ("* 3 View all Information *\n");p rintf ("*4 Statistics students *\n"); printf ("* 5 Stop program Run *\n ");p rintf (" *****************************************************************\n ");} Void main () {Int a,m;int b = 1;system ("clear");p rintf ("★★★★★★★★★★★★★★★★★★★★★★★★★★★\n") ;p rintf ("!\n Welcome");p rintf ("Please select the management system \n you want to enter") printf ("1. Admin management System. \ n ");p rintf (" 2. Student management System. \ n ");p rintf (" 3. Exit the System! \ n ");p rintf (" ★★★★★★★★★★★★★★★★★★★★★★★★★★★\n ");p rintf (" Please select: ") scanf ("%d ", &m); if (m==1) {login1 ();} if (m==2) {login2 ();} while (b == 1) {if (m==1) {menu1 (); scanf ("%d", &a); switch (a) {case 1 :input (); break; Case 2 :search (); break;case 3 :d ele (); Break;case 4 :change (); break; Case 5 :outputsortsum (); Break;case 6 :output (); break;case 7 :statistic (); Break; case 8 :exit (1);d efault :p rintf ("Input Error! \ n "); printf ("\ n \ nyou Choose Next action: \ n");p rintf (" 1 . Return to main Menu 2 . exit program \ n"); scanf ("%d", &b);} if (m==2) {menu2 (); scanf ("%d", &a); switch (a) {Case 1 :search (); break;case 2 :o Utputsortsum (); Break;case 3 :output (); break;case 4 :statistic (); break; case 5 :exit (1);d efault :p rintf ("Input Error! \ n "); printf ("\ n \ nyou Choose Next action: \ n");p rintf (" 1 . Return to main Menu 2 . exit program \ n"); scanf ("%d", &b);} if (m==3) exit (1);}} [email protected]:~$
Compile run:
[email protected]:~$ gcc main.c && ./a.out ★★★★★★★★★★★★★★★★★★★★★★★★★★★ Educational Administration System welcome you! Please select the management system 1 you want to enter. Administrator Management System. 2. Student management System. 3. Exit the System! ★★★★★★★★★★★★★★★★★★★★★★★★★★★ Please choose: 1 Enter the Administrator score management system before you enter the password please enter your password &NBSP;:&NBSP;ABCDE Welcome to the Administrator management system! Main Menu *****************************1 Add student scores **2 find student scores **3 Delete designated students * * 4 Modify student Information **5 Total score Sort Information **6 View all information **7 Statistics students **8 stop program run ******************************* 6 *************************student*********************** ------- ------------------------------------------------ | | name | math | english | C language | Total | -------------------------------------------------------|&NBSP;&NBSP;&NBSP;1&NBSP;|LUCY|&NBSP;12 | 32| 0| 44| -------------------------------------------------------| 45 |34 |354 |343|4234|4931| -------------------------------------------------- -----Please select the following: &Nbsp;1 . back to main Menu 2 . exit program
This article is from the "Soul Bucket" blog, please be sure to keep this source http://990487026.blog.51cto.com/10133282/1792587
"C Project" file, structure, list, sort, student information management system