C语言实现简单学生成绩管理系统

2022-10-20,

这篇文章主要为大家详细介绍了C语言实现简单学生成绩管理系统,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了C语言实现学生成绩管理系统的具体代码,供大家参考,具体内容如下

C语言小项目

实现一个学生成绩管理系统

系统功能:

 1.实现所有学生成绩的录入(利用结构体数组),当输入字符为end时候,结束成绩的录入;
 2.实现所有学生信息的输出
 3.输入指定学生姓名,并能输出这名学生的信息
 4.将学生成绩按照语文和数学成绩排序

思路:
1. 首先,先把这个小项目的框架打好。考虑要写几个文件,每一个文件里面实现怎样的功能。考虑到这个小项目的代码量以及程序的易读性,我决定将写三个文件。一个main.c,里面就写需要用到的函数;一个teacher.c主要实现main.c函数里面具体的内容;一个teacher.h里面主要写这个项目我们需要用到一些宏定义和函数,以便在另外两个C文件里面调用。(注意:在两个C文件里面要包括teacher.h文件)。
2. 其次,分析一下这个系统要实现的功能,有四个功能。我们可以每一个功能写一个函数,分别实现全部录入,全部输出,指定学生信息输出以及语文和数学成绩的排序这四个函数。将这四个函数的具体实现放在teacher.c文件里面。Main.c就负责直接调用这些函数。
3. 最后,考虑到需要录入的时学生信息,包括姓名,学号,性别,语文成绩,数学成绩这些内容。所以,考虑用结构体数组来实现。

Teacher.h文件

#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文件

#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文件

#include <string.h> 
#include <stdio.h> 
#include "teacher.h" 
 
void welcome() //系统界面欢迎函数 
{ 
 system("clear"); 
  
 printf("*********************************\n"); 
 printf("WELCOME TO TEACHER SYSTEM!\n"); 
 printf("*********************************\n"); 
 sleep(2); 
  
} 
 
void showchoice() //选择提示函数 
{ 
 //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) //输出第i个学生的信息 
{ 
 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) //录入学生信息 
{ 
 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) //输出全部学生信息 
{ 
 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) //查找出特定学生信息 
{ 
 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) //将数学,语文成绩冒泡排序 
{ 
 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"); //选择提示:1 数学成绩排序 2 语文成绩排序  
 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) //将成绩较大的学生信息放到成绩较低的后面 
    { 
     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"); 
 } 
  
} 

小项目程序我自己测试过,如果大家发现有不对的地方请多多指出。大家一起学习,一起进步!

更多学习资料请关注专题《管理系统开发》。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持北冥有鱼。

《C语言实现简单学生成绩管理系统.doc》

下载本文的Word格式文档,以方便收藏与打印。