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

时间:2022-11-07 11:44:54

本文实例为大家分享了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文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#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文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#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文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#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");
 }
  
}

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

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

原文链接:http://blog.csdn.net/csdnxmj/article/details/78393085