C language to achieve student performance management system

  • 2020-06-01 10:40:57
  • OfStack

Design a student score management system, to achieve the dynamic management of student scores, to achieve the input of student scores, display, delete, find, insert, the best, save, calculation, sorting and other major functions.

Functional requirements

1. Each record includes one student's student number, name, grades of three courses and average scores.
2. Input function: it can input several records once.
3. Display function: display all student records.
4. Search function: search student records by name and display them.
5. Sorting function: sort students according to their average scores.
6. Insertion function: insert one student record according to the average score
7. Delete function: delete student records if you make a mistake;
8. Quit.

Code:


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE_NAME 10
#define SIZE_ID 20

int Record = 0;

typedef struct {
 char name[SIZE_NAME];
 char id[SIZE_ID];
 int a, b, c;
 int ava;
}pInfo;

typedef struct node {
 pInfo people;
 struct node *next;
}linkList;

int menu();
int create(linkList *head);
int display(linkList *head);
int search(linkList *head, char *info);
int modify(linkList *head, char *pid);
int add2(linkList *head, char *pid);
int delt(linkList *head, char *info);
int compare(int ava1, int ava2);
int sort(linkList *head, int boolean);//1 ascending  0 Descending order  


int main()
{
 linkList head, *p;
 char info[SIZE_ID];
 int temp, chus, i;
 head.next = NULL;

 while (1) {
 switch (menu()) {
 case 1:
  create(&head);
  break;
 case 2:
  display(&head);
  break;
 case 3:
  printf(" Please enter the student number or name you want to inquire : ");
  scanf("%s", info);
  p = &head;
  p = p->next;
  for (i = 0; i < search(&head, info); i++) {
  p = p->next;
  }
  printf(" To search :\n");
  printf("\t\t\t\t Student information \n");
  printf("--------------------------------------------------------------------------------\n");
  printf("\t\t Student id \t\t The name \t\t\t The average scores \n");
  printf("--------------------------------------------------------------------------------\n");
  printf("%20s\t", p->people.id);
  printf("%10s\t", p->people.name);
  printf("%20d\n", p->people.ava);
  break;
 case 4:
  printf(" Please enter the student number that needs to be modified : ");
  scanf("%s", info);
  modify(&head, info);
  break;
 case 5:
  printf(" Please enter the student number you want to add : ");
  scanf("%s", info);
  add2(&head, info);
  break;
 case 6:
  printf(" Please enter the student number or name to delete : ");
  scanf("%s", info);
  delt(&head, info);
  break;
 case 7:
  printf(" Please enter the 1 or 0:\n\t1: ascending \n\t0: Descending order \n");
  scanf("%d", &temp);
  sort(&head, temp);
  break;
 case 8:
  exit(0);
  break;
 default:
  printf(" If you make a mistake, try again 1 time \n");
 }
 system("pause");
 system("cls");
 }
 system("pause");
 return 0;
}

int menu()
{
 int chus;
 printf("\t Student information \n\n");
 printf(" Please enter the (1 -- 8):\n");
 printf("\t1. Creating student information \n");
 printf("\t2. Display student information \n");
 printf("\t3. Search for student information \n");
 printf("\t4. Modify student information \n");
 printf("\t5. Add student information \n");
 printf("\t6. Delete student information \n");
 printf("\t7. Ranking students' scores \n");
 printf("\t8. exit \n");
 scanf("%d", &chus);
 return chus;
}

int create(linkList *head)
{
 linkList *s, *p;
 p = head;
 printf(" Please enter your student number   The name  3 subjects , The input end The end of the \n");
 while (1) {
 s = (linkList*)malloc(sizeof(linkList));
 scanf("%s", s->people.id);
 if (!strcmp(s->people.id, "end")) {
  return 0;
 }
 scanf("%s", s->people.name);
 scanf("%d", &s->people.a);
 scanf("%d", &s->people.b);
 scanf("%d", &s->people.c);
 s->people.ava = (s->people.a + s->people.b + s->people.c) / 3;

 s->next = p->next;
 p->next = s;
 p = s;
 Record++;
 }
 return 0;
}

int display(linkList *head)
{
 int i;
 linkList *p;
 p = head;
 p = p->next;
 printf("\t\t\t\t Student information \n");
 printf("--------------------------------------------------------------------------------\n");
 printf("\t\t Student id \t\t The name \t\t\t The average scores \n");
 printf("--------------------------------------------------------------------------------\n");
 for (i = 0; i < Record; i++, p = p->next) {
 printf("%20s\t", p->people.id);
 printf("%10s\t", p->people.name);
 printf("%20d\n", p->people.ava);
 }

 return 0;
}

int search(linkList *head, char *info)
{
 int i;
 linkList *p;
 p = head;
 p = p->next;
 for (i = 0; i < Record; i++, p = p->next) {
 if ((!strcmp(p->people.id, info)) || (!strcmp(info, p->people.name))) {
  return i;
 }
 }
 return -1;
}

int modify(linkList *head, char *pid)
{
 int i;
 linkList *p;
 p = head;
 p = p->next;
 for (i = 0; i < search(head, pid); i++) {
 p = p->next;
 }
 printf(" Please enter new information :\n");
 scanf("%s", p->people.id);
 scanf("%s", p->people.name);
 scanf("%d", &p->people.a);
 scanf("%d", &p->people.b);
 scanf("%d", &p->people.c);
 p->people.ava = (p->people.a + p->people.b + p->people.c) / 3;
 return 0;
}

int add2(linkList *head, char *pid)
{
 int i;
 linkList *p, *s;
 p = head;
 p = p->next;
 s = (linkList*)malloc(sizeof(linkList));
 while (p->next != NULL) {
 p = p->next;
 }
 printf(" Please enter the name and grade you want to add :\n");
 strcpy(s->people.id, pid);
 scanf("%s", s->people.name);
 scanf("%d", &s->people.a);
 scanf("%d", &s->people.b);
 scanf("%d", &s->people.c);
 s->people.ava = (s->people.a + s->people.b + s->people.c) / 3;
 if (search(head, s->people.id) == -1) {
 s->next = p->next;
 p->next = s;
 Record++;
 }
 else {
 printf(" Student id number repeated \n");
 }
 sort(head, 0);
 return 0;
}

int delt(linkList *head, char *info)
{
 int i, n;
 linkList *p, *s;
 p = head;
 n = search(head, info);
 if (-1 == n) {
 printf(" Could not find \n");
 return 0;
 }
 for (i = 0; i < n; i++) {
 p = p->next;
 }
 p->next = p->next->next;
 Record--;
 return 0;
}
int compare(int ava1, int ava2)
{
 if (ava1 < ava2) {
 return 1;
 }
 return 0;
}

int sort(linkList *head, int boolean)
{
 linkList *p, *pre;
 pInfo temp;
 if (boolean) {
 for (p = head->next; p != NULL; p = p->next) {
  for (pre = p->next; pre != NULL; pre = pre->next) {
  if (0 == compare(p->people.ava, pre->people.ava)) {
   temp = p->people;
   p->people = pre->people;
   pre->people = temp;
  }
  }
 }
 }
 else {
 for (p = head->next; p != NULL; p = p->next) {
  for (pre = p->next; pre != NULL; pre = pre->next) {
  if (1 == compare(p->people.ava, pre->people.ava)) {
   temp = p->people;
   p->people = pre->people;
   pre->people = temp;
  }
  }
 }
 }
 return 0;
}

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


Related articles: