Course design of student information management system for C language data structure

  • 2020-06-01 10:24:11
  • OfStack

The example of this paper for you to share the student information management system design of the specific code, for your reference, the specific content is as follows

Establish a dynamic linked list. Each node in the list includes: student id, name, gender, age, and score. The program can achieve the following functions:

Build list
According to the list
Find out if there is an element in the list, and display all the information for that element. If there is no element, show "no record!" The information.
Deletes the node with the specified student number in the linked list.
Insert a new node at the specified location in the list (the student number cannot be repeated with other nodes).

Requirements: in the operation of the program, display the menu composed of the above functions first, and then according to the options to call the corresponding program and display its corresponding results, and then display the menu program, until the "exit" option, the program execution ended.

The complete code is as follows:


#include "stdio.h" 
#include "stdlib.h" 
typedef struct student 
{ 
 int id; // Student id  
 char name[20]; // The name  
 char sex; // Gender, f or m )  
 int age; // age  
 int score; // results  
 struct student *next; 
}student; 
student *head=NULL; 
int length; // The length of the list  
void create() 
{ 
 student *p1,*p2; 
 length=0; 
 p1=(student *)malloc(sizeof(student)); 
 p1->id=-1; 
 if(head==NULL) 
 head=p1; 
 printf(" Please enter the student's student number, name, gender, age and grade information: \n"); 
 while(1) // Student id for 0 Time to quit  
 { 
 p2=(student *)malloc(sizeof(student)); 
 scanf("%d %s %c %d %d",&p2->id,p2->name,&p2->sex,&p2->age,&p2->score); // Enter student information  
 if(p2->id==0) 
 { 
  printf(" Linked list creation complete! \n"); 
  break; 
 } 
 length++; // The length of the list  
 p1->next=p2; 
 p2->next=NULL; 
 p1=p1->next; 
 } 
 return ; 
} 
 
void display() 
{ 
 student *p=head->next; 
 printf(" All the students in the list are listed below :\n"); 
 while(p!=NULL) 
 { 
 printf("%d %s %c %d %d\n",p->id,p->name,p->sex,p->age,p->score); 
 p=p->next; 
 } 
 return ; 
} 
void search() 
{ 
 int num; 
 student *p=head->next; 
 printf(" The student id to look for is: "); 
 scanf("%d",&num); 
 
 while(p!=NULL) 
 { 
 
 if(p->id==num) 
 { 
  printf(" Student id for %d The information of the students is as follows: \n",num); 
  printf("%d %s %c %d %d\n",p->id,p->name,p->sex,p->age,p->score); 
  return; 
 } 
 p=p->next; 
 } 
 if(p==NULL) 
 printf(" No record! \n"); 
 return ; 
} 
 
void insert() 
{ 
 int num,i; 
 student *p,*q; 
 p=head; 
 
 printf(" Please enter the position you want to insert : "); 
 scanf("%d",&num); 
 if(num>length) 
 { 
 printf(" The position to insert was not found \n"); 
 return ; 
 } 
 else 
 { 
 printf(" Please enter the student number, name, gender, age and grade information of the student you want to insert :\n"); 
 q=(student *)malloc(sizeof(student)); 
 scanf("%d %s %c %d %d",&q->id,q->name,&q->sex,&q->age,&q->score); 
 
 while(p!=NULL) 
 { 
  if(p->id==q->id) 
  { 
  printf(" This student number already exists, cannot insert! \n"); 
  return ; 
  } 
  p=p->next; 
 } 
 p=head; 
 for(i=0;i<num;i++) 
  p=p->next; 
 q->next=p->next; 
 p->next=q; 
 length++; 
 printf(" Insert successfully! \n"); 
 return ; 
 } 
} 
 
void Delete() 
{ 
 int num; 
 student *p,*q; 
 q=head,p=head->next; 
 printf(" Please enter the student number to delete :\n"); 
 scanf("%d",&num); 
 
 while(p!=NULL) 
 { 
 if(p->id==num) 
 { 
  q->next=p->next; 
  free(p); 
  length--; 
  printf(" Deleted successfully! \n"); 
  return ; 
 } 
 p=p->next; 
 q=q->next; 
 } 
 if(p==NULL) 
 { 
 printf(" Cannot find the number to delete! \n"); 
 return ; 
 } 
} 
void menu() 
{ 
 printf("________________________________________________________________\n"); 
 printf("|   Student information management system     |\n"); 
 printf("|  0 ,   Log out      |\n"); 
 printf("|  1 ,   Build list      |\n"); 
 printf("|  2 ,   According to the list      |\n"); 
 printf("|  3 ,   Find an element in a linked list    |\n"); 
 printf("|  4 ,   Deletes the node with the specified student number in the linked list    |\n"); 
 printf("|  5 ,   Inserts at the specified location 1 A new node    |\n"); 
 printf("________________________________________________________________\n"); 
 return ; 
} 
int main(void) 
{ 
 int a; 
 menu(); 
 while(1) 
 { 
 printf(" Please select the appropriate function: "); 
 scanf("%d",&a); 
 switch(a) 
 { 
 case 0: 
  return 0; 
 case 1: 
  create(); 
  menu(); 
  break; 
 case 2: 
  if(head) 
  { 
  display(); 
  menu(); 
  } 
  else 
  { 
  printf(" The list is empty, please create the list first! \n"); 
  menu(); 
  } 
  break; 
 case 3: 
  if(head) 
  { 
  search(); 
  menu(); 
  } 
  else 
  { 
  printf(" The list is empty, please create the list first! \n"); 
  menu(); 
  } 
  break; 
 case 4: 
  if(head) 
  { 
  Delete(); 
  menu(); 
  } 
  else 
  { 
  printf(" The list is empty, please create the list first! \n"); 
  menu(); 
  } 
  break; 
 case 5: 
  if(head) 
  { 
  insert(); 
  menu(); 
  } 
  else 
  { 
  printf(" The list is empty, please create the list first! \n"); 
  menu(); 
  } 
  break; 
 default: 
  break; 
 } 
 } 
 system("pause"); 
 return 0; 
} 

Program description: join has added 4 student information head- > liuwei- > zhanghua- > lina- > liuxiang, the length of the linked list is 4. When inserting, enter 4, and a student information will be inserted after liuxiang. Enter 1, and a student information will be inserted after liuwei.

For more information, please refer to the topic "management system development".


Related articles: