#include <stdio.h> #include <malloc.h> #include <string.h> #define Len sizeof (struct stu) typedef long L
Ong ll;
struct Stu//build the student information structure, including the number, name, score three children {ll num;
Char a[50];
Double score;
struct Stu *next;
} ;
struct Stu *creat ()//build a linked list {struct Stu *head;
struct Stu *p;
struct Stu *tail; Head=tail=null;
The header footer pointer is initialized to empty printf ("Please enter the student's information according to the number of students arriving from the school, separated by a space, the number of input 0 indicates the end of the input: \ n number: \ t name: \ t score: \ n");
ll X; scanf ("%lld", &x);
Enter study number GetChar (); while (x!=0) {p= (struct stu*) malloc (len);
Enter 0 for the end of the study number, when the study number is not 0 o'clock, establish a new node p->num=x;
if (head==null)//If the head pointer is empty, the head pointer points to the first node head=p;
if (tail!=null) tail->next=p; Tail=p; The tail pointer also points to the newly established node scanf ("%s%lf%lld", p->a,&p->score,&x);
Enter the name score and the next study number} if (Tail!=null)//To set the trailing node's successor to null tail->next=null; Return Head;
} void list (struct Stu *p)//display the information in the list {struct Stu *head;
Head=p; if (head==null) printf ("You did not enter any information \ n");
If the header is empty then the proof is not entered any and information else {printf ("study number: \ t name: \ t: \ n"); while (Head!=null) {printf ("%lld\t%s\t%5.1lf\n", Head->num,head->a,head->score); Student information head=head->next; in the output node
Read Next Node}}} void query (char c[],struct stu *head)//Find student information by name {struct Stu *p;
P=head;
while (strcmp (p->a,c)!=0) {p=p->next;
} printf ("study number: \ t name: \ t fraction: \ n");
printf ("%lld\t%s\t%5.1lf\n", P->num,p->a,p->score); } struct Stu *delet (char c[],struct stu *head) {struct Stu *p,*temp;
Set two structure pointers, pointing to the information node to delete the student and its precursor node p=temp=head; if (p==null) {printf ("does not have any student information \ n");//If the list is empty then output} else {while (strcmp (p->a,c)!=0 && p->next!=
NULL)//Backward query {Temp=p when there is no query to the specified student and no traversal of the linked list;
p=p->next; } if (strcmp (p->a,c) ==0) {if (P==head)//IFThe student information to be deleted is dropped directly on the head node of the linked list and the head node is set to the next node {printf ("Student information with Name:%s deleted, press 2 to view \ n", c);
head=head->next;
Free (p);
} else//In other cases the tail pointer of the predecessor node that removed the node points to the next node of the delete node {printf ("The Student information named:%s was deleted, press 2 to view \ n", c);
temp->next=p->next;
Free (p); }} else {printf ("No students found this name \ n");
If not found then output}} return head;
} struct Stu *add (ll K,char name[],int scor,struct stu *head) {struct Stu *p,*temp,*q; p=temp=head;
if (P->num > K)//Add student information by number, the head node is larger than the current number when inserted into the table header {p= (struct Stu *) malloc (len);
p->next=head;
Head=p; p->num=k; strcpy (P->a,name);
p->score=scor;
printf ("Student Information added, press 2 to view \ n");
} else {while (p->next!=null) {temp=p;
p=p->next; if (Temp->num < K && p->num>k)//When the number to be inserted is between a two study number and inserted between the two nodes {q= (struct Stu *) Mall
OC (LEN);
temp->next=q;
q->next=p; q->num=k; strcpy (q->A,name);
q->score=scor;
printf ("Student Information added, press 2 to view \ n");
}} if (P->num < K)//When you want to add a student number greater than the footer number when inserting to the end of the table {q= (struct Stu *) malloc (len); p->next=q;
q->next=null; q->num=k; strcpy (Q->a,name);
q->score=scor;
printf ("Student Information added, press 2 to view \ n");
}} return head; } struct Stu *pos1 (ll K, Char name[], int scor, int pos, struct stu *head) {struct Stu *p,*temp; p=temp=head;
Add student information by location int num=0;
while (p!=null) {p=p->next;
num++;
} P=temp=head;
if (pos==1)//When location is 1 o'clock added to table header {p= (struct Stu *) malloc (len); p->next=head;
Head=p;
strcpy (P->a,name); p->num=k;
p->score=scor;
printf ("Student information has been added, press 2 to view:");
} else if (pos>1 && pos<=num)//When you want to add a student position in the table when added to the table {int l=0;
while (p!=null) {temp=p;
p=p->next;
l++;
if (l=pos) {struct Stu *q= (struct stu *) malloc (len); q->next=p;
temp->next=q; strcpy (q->a,name); q->num=k;
q->score=scor;
printf ("Student information has been added, press 2 to view:");
Break
}}}} else if (pos==num+1)//When the position is last added to the end of the table {struct Stu *q= (struct stu *) malloc (len);
while (p->next!=null) {p=p->next; } p->next=q;
q->next=null;
strcpy (Q->a,name); q->num=k;
q->score=scor;
printf ("Student information has been added, press 2 to view:"); } else printf ("Sorry, the location you entered is invalid \ n");
In other cases, the output position is invalid information return head;
} struct stu *pos2 (int n,struct stu *head)//query student information by location, traverse the linked list, and output student information {struct Stu *p,*temp when location is met; P=head;
int m=0,ans=0;
if (p==null) printf ("No student information \ n");
else {while (p!=null) {temp=p;
p=p->next;
m++;
if (m==n) {printf ("study number: \ t name: \ t fraction: \ n");
printf ("%lld\t%s\t%5.1lf\n", Temp->num,temp->a,temp->score);
Ans=1;
Break
}} if (ans==0) printf ("Sorry, the location you entered is invalid \ n");
} return head; } void Query2 (struct stu *head) Query the number of students {struct Stu *p;
P=head;
int n=0;
while (p!=null) {n++;
p=p->next;
} printf ("Number of students:%d \ n"); } int main () {printf ("\t\t\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\
2\1\2\1\2\1\2\n ");
printf ("\n\n\t\t\t\t Student performance Management System \n\n\n"); printf ("\t\t\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1\2\1
\2\n ");
printf ("\N\N\N\T\T\T\T1: Enter student information \ n");
printf ("\N\T\T\T\T2: Show student information \ n");
printf ("\N\T\T\T\T3: Query student information by name \ n");
printf ("\N\T\T\T\T4: Delete student information by name \ n");
printf ("\N\T\T\T\T5: Add student information according to the school number \ n");
printf ("\N\T\T\T\T6: Add student information to input location \ n");
printf ("\N\T\T\T\T7: Input location query student information \ n");
printf ("\n\t\t\t\t8: Query number of students \ n");
printf ("\n\t\t\t\t0: Exit system \ n");
printf ("\n\t\t\t\t Please press 0-4 to select menu item: \ n"); int n,k,scor,pos,m=0;
Char b[50],name[50];
struct Stu *head;
while (scanf ("%d", &n)} {if (n==0) break;
if (m==0&&n!=1) {printf ("Please enter your score before you can operate \ n");
Continue
} m=1;
Switch (n) { Case 1:head=creat ();
Break Case 2:list (head);
Break
Case 3:printf ("Please enter the name of the student to be queried:"); scanf ("%s", b); Query (B,head);
Break
Case 4:printf ("Please enter the name of the student to be deleted:"); scanf ("%s", b); Head=delet (B,head);
Break
Case 5:printf ("Please enter the information for the student to be added: study number: \ t name: \ t score:"); scanf ("%lld", &k); GetChar (); scanf ("%s%d", Name,&scor); Head=add (K,name,scor,head);
Break
Case 6:printf ("Please enter the information for the student to be added: study number: \ t name: \ t score: \ t location:"); scanf ("%lld", &k); GetChar (); scanf ("%s%d%d", Name,&scor,&pos); HEAD=POS1 (K,name,scor,pos,head);
Break
Case 7:printf ("Please enter the location of the student to be queried:"); scanf ("%d", &pos); Head=pos2 (Pos,head);
Break
Case 8:query2 (head);
}} return 0; }