C language to achieve a simple student performance management system

  • 2020-06-01 10:38:06
  • OfStack

In this paper, the example of C language to achieve student performance management system of the specific code, for your reference, the specific content is as follows

C language small project

Realize a student achievement management system

System functions:

1. Realize the input of all students' scores (using structural array), and finish the input when the input character is end;
2. Realize the output of all student information
3. Input the name of the designated student and output the information of the student
4. Rank students' grades according to their Chinese and math scores

Ideas:
1. First of all, frame the small project well. Consider how many files to write, and what functions to implement in each file. Considering the amount of code for this small project and the readability of the program, I decided to write three files. 1 main.c, which contains the functions to be used; One teacher. c mainly implements the specific contents in the main. c function; One teacher.h for this project we need to use some macro definitions and functions to call in the other two C files. (note: the teacher.h files should be included in the two C files).
2. Secondly, analyze the functions to be realized in this system. There are four functions. We can write 1 function for each function, realizing all input, all output, specifying 4 functions for the output of student information and the sorting of Chinese and math scores. Put the implementation of these four functions in the teacher.c file. Main.c is responsible for calling these functions directly.
3. Finally, students' information should be recorded, including their names, student Numbers, gender, Chinese scores and math scores. So, consider implementing it as a struct array.

Teacher h file


#ifndef _TEACHER_H_ 
#define _TEACHER_H_ 
 
struct student 
{ 
 char name[20]; 
 int id; 
 char sex; 
 int chinese; 
 int math; 
}; 
 
typedef struct student stu; 
 
void show_message(stu *st, int len); 
 
int input(stu *st); 
 
void find(stu *st, int len); 
 
void sort(stu *st, int len); 
 
void out(stu *st, int i); 
 
void welcome(); 
 
void showchoice(); 
 
#endif 

Main c file


#include <stdio.h> 
#include <string.h> 
#include "teacher.h" 
#include <stdlib.h> 
 
int main() 
{ 
 int len; 
 int m; 
 stu st[100]; 
  
 welcome(); 
 
 while(1) 
 { 
  showchoice(); 
   
  scanf("%d", &m); 
  switch(m) 
  { 
   case 1: len = input(st);break; 
   case 2: show_message(st , len);break; 
   case 3: find(st , len);break; 
   case 4: sort(st , len);break; 
   default : exit(0); 
  } 
 } 
 
 return 0; 
} 

Teacher c file


#include <string.h> 
#include <stdio.h> 
#include "teacher.h" 
 
void welcome() // System interface welcome function  
{ 
 system("clear"); 
  
 printf("*********************************\n"); 
 printf("WELCOME TO TEACHER SYSTEM!\n"); 
 printf("*********************************\n"); 
 sleep(2); 
  
} 
 
void showchoice() // Select prompt function  
{ 
 //system("clear"); 
  
 printf("*********************************\n"); 
 printf("1 input!   2 showinfor!\n"); 
 printf("3 find!   4 sort!\n"); 
 printf("*********************************\n"); 
 printf("Please input your choice :\n"); 
  
} 
 
void out(stu *st, int i) // Output the first i Student information  
{ 
 printf("%s ",st[i].name); 
 printf("%d ",st[i].id); 
 printf("%c ",st[i].sex); 
 printf("%d ",st[i].chinese); 
 printf("%d",st[i].math); 
 printf("\n"); 
} 
 
int input(stu *st) // Input student information  
{ 
 int i; 
  
 printf("Input name, id, sex, Chinese score, Math score:\n"); 
 for(i = 0; i < 100; i++) 
 { 
  scanf("%s", st[i].name); 
  if((!strcmp(st[i].name , "end"))) 
  { 
   return i; 
  }  
  scanf("%d", &st[i].id); 
  scanf("%s", &st[i].sex); 
  scanf("%d", &st[i].chinese); 
  scanf("%d", &st[i].math); 
 } 
 return i; 
} 
 
void show_message(stu *st, int len) // Output all student information  
{ 
 int i; 
 printf("name, id, sex, Chinese score, Math score:\n"); 
 for(i = 0; i < len; i++) 
 { 
  out(st, i); 
 }  
} 
 
void find(stu *st,int len) // Find out about specific students  
{ 
 char tmp[20]; 
 int i; 
  
 printf("Please input the target student:\n"); 
 scanf("%s", tmp); 
 for(i = 0; i < len; i++ ) 
 { 
  if(!strcmp(st[i].name,tmp)) 
  { 
   out(st, i); 
  } 
 } 
} 
 
void sort(stu *st, int len) // Math, Chinese grades bubble sort  
{ 
 int tmp; 
 int i,j,k; 
 int id,sex,chinese,math; 
 char name[20]; 
 int choice; 
  
 printf("\n"); 
 printf("Please input your sort choice:\n"); // Selection prompt: 1  Mathematical ranking  2  Language ranking   
 printf("1 math grade!  2 chinese grade!\n"); 
 printf("\n"); 
 scanf("%d",&choice); 
 
 if(1 == choice) 
 { 
  for(i = 0;i < len-1;i++) 
  { 
   for(j = 0;j < len-1-i;j++) 
   { 
    if(st[j].math > st[j+1].math) // Put the information of the students with higher grades behind the ones with lower grades  
    { 
     tmp = st[j].math; 
     st[j].math = st[j+1].math; 
     st[j+1].math = tmp; 
     
     strcpy(name,st[j].name); 
     strcpy(st[j].name,st[j+1].name); 
     strcpy(st[j+1].name,name); 
     
     id = st[j].id; 
     st[j].id = st[j+1].id; 
     st[j+1].id = id; 
     
     sex = st[j].sex; 
     st[j].sex = st[j+1].sex; 
     st[j+1].sex = sex; 
     
     chinese = st[j].chinese; 
     st[j].chinese = st[j+1].chinese; 
     st[j+1].chinese = chinese; 
    } 
   } 
     
  } 
  
  printf("After sort math grade :\n"); 
  for(k = 0;k < len;k++) 
  { 
   out(st, k); 
  } 
 } 
 else if(2 == choice) 
 { 
  for(i = 0;i < len-1;i++) 
  { 
   for(j = 0;j < len-1-i;j++) 
   { 
    if(st[j].chinese > st[j+1].chinese) 
    { 
     tmp = st[j].chinese; 
     st[j].chinese = st[j+1].chinese; 
     st[j+1].chinese = tmp; 
    
     math = st[j].math; 
     st[j].math = st[j+1].math; 
     st[j+1].math = math; 
     
     strcpy(name,st[j].name); 
     strcpy(st[j].name,st[j+1].name); 
     strcpy(st[j+1].name,name); 
     
     id = st[j].id; 
     st[j].id = st[j+1].id; 
     st[j+1].id = id; 
      
     sex = st[j].sex; 
     st[j].sex = st[j+1].sex; 
     st[j+1].sex = sex; 
     
    
    } 
   } 
     
  } 
  
 printf("After sort chinese grade :\n"); 
 for(k = 0;k < len;k++) 
 { 
  out(st,k); 
 } 
} 
else 
 { 
  printf("Input error!\nPlease input again!\n"); 
 } 
  
} 

Small project procedures I have tested, if you find that there is a wrong place please point out. Everyone 1 from learning, 1 from progress!

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


Related articles: