且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C语言项目:学生成绩管理系统

更新时间:2022-09-19 23:27:24

C语言项目:学生成绩管理系统

   1、数据结构:学生信息:学号、姓名、年龄、性别、3课成绩
   2、功能:
  1)增加学生记录
   (2)  删除学生记录
   (3)  查找学生信息(学号、姓名)
   (4)  修改学生信息
 (5)按照成绩排序、求平均值、最大值、最小值
   3、用户界面
   主菜单
   子菜单
   4、 批量生成测试数据
 
C语言项目:学生成绩管理系统
  1 //
  2 //  main.c
  3 //  Student System
  4 //
  5 //  Created by ma c on 15/7/22.
  6 //  Copyright (c) 2015年. All rights reserved.
  7 //  要求:编写一个学生成绩管理系统。
  8 
  9 #include <stdio.h>
 10 #include<string.h>
 11 #include<stdlib.h>
 12 #define N 50
 13 struct Student{
 14     char name[20];
 15     int sno;
 16     int age;
 17     char gender;
 18     float EnglishScore;
 19     float mathScore;
 20     float chineseScore;
 21 }stu[N]={{"zhao",1000,20,'M',98,99,97},
 22          {"zhao",1001,21,'F',97,96,95},
 23          {"qian",1002,23,'M',95,96,92},
 24          {"hong",1003,22,'F',91,93,97},
 25          {"zhou",1004,25,'M',90,90,90},
 26          {"feng",1005,21,'F',96,93,96},
 27          {"wang",1006,23,'M',97,91,90},
 28          {"chen",1007,21,'F',94,92,91},
 29          {"geng",1008,20,'F',90,99,91},
 30          {"tang",1009,24,'M',99,99,99}};
 31 
 32 //添加数据
 33 void add(struct Student stu[],int pos,int nums);
 34 
 35 
 36 //删除数据
 37 void Delete_name(struct Student *stu,char Name[]);//(按姓名)
 38 void Delete_sno(struct Student *stu,int Sno);//(按学号)
 39 
 40 
 41 //修改数据
 42 void update(struct Student stu[],int Sno,int len);
 43 
 44 
 45 //查询子菜单
 46 void menu(struct Student stu[],int m);
 47 void search(struct Student stu[],int n,char Name[]);//按姓名查询
 48 void search1(struct Student stu[],int n,int Num);//按学号查询
 49 void sort(struct Student stu[],int n); //按总分高低排序
 50 void print(struct Student stu[],int n);
 51 void My_print_sum(struct Student stu[],int n);
 52 void max_min(struct Student stu[],int n);
 53 
 54 
 55 //主菜单
 56 void PrintScreen()
 57 {
 58     printf("------------------\n");
 59     printf("** 1.增加学生记录 **\n");
 60     printf("** 2.删除学生记录 **\n");
 61     printf("** 3.查找学生记录 **\n");
 62     printf("** 4.修改学生记录 **\n");
 63     printf("** 0.退出管理系统 **\n");
 64     printf("------------------\n");
 65 }
 66 
 67 //删除子菜单
 68 void deleteScreen()
 69 {
 70     printf("------------------\n");
 71     printf("** 0.按姓名删除数据**\n");
 72     printf("** 1.按学号删除数据**\n");
 73     printf("** 2.返回主菜单   **\n");
 74     printf("------------------\n");
 75     printf("please select 0-1:");
 76 }
 77 
 78 //查找子菜单
 79 void seekScreen()
 80 {
 81     printf("-------------------------\n");
 82     printf("****** 1.按姓名查找信息    *\n");
 83     printf("****** 2.按学号查找信息    *\n");
 84     printf("****** 3.查看所有学生成绩  *\n");
 85     printf("****** 4.成绩名次排序(总分)*\n");
 86     printf("****** 5.查看成绩最优最差  *\n");
 87     printf("****** 6.返回主菜单       *\n");
 88     printf("-------------------------\n");
 89     printf("please you select 1-6:");
 90 }
 91 
 92 //定义全局静态变量,统计目前结构体数组中的人数
 93 static int count = 10;
 94 
 95 
 96 
 97 
 98 //主函数
 99 int main(int argc, const char * argv[])
100 {
101  int nums,temp;
102  int snos;
103  char names[20];
104  while(1)
105  {
106     PrintScreen();
107     printf("please press enter_key continue!\n");
108     getchar();
109     printf("please select 0-4:");
110     char c = getchar();
111     switch(c)
112     {
113         case '1':
114               printf("please student'numbers you want to add:");
115               scanf("%d",&nums);
116               add(stu,count,nums);      //添加数据
117               getchar();
118               break;
119         case '2':
120               deleteScreen();
121               scanf("%d",&temp);
122               switch(temp)
123               {
124                   case 0:
125                       printf("please input delete name:");
126                       scanf("%s",names);;
127                       Delete_name(stu,names);  //删除数据(按姓名删除)
128                       break;
129                   case 1:
130                       printf("please input delete sno:");
131                       scanf("%d",&snos);
132                       Delete_sno(stu,snos); //删除数据(按学号删除)
133                       break;
134                   case 2:
135                       break;
136               }
137               getchar();
138               break;
139         case '3':
140               menu(stu,count);//查找数据
141               getchar();
142               break;
143         case '4':
144               printf("please input update sno:");
145               scanf("%d",&snos);
146               update(stu,snos,count);     //修改数据
147               break;
148         case '0':
149               exit(0);                    //退出系统
150         default:
151               printf("data is illeagel!\n");
152               getchar();
153               break;                      //输入非法
154     }
155  }
156  return 0;
157 }
158 
159 
160 
161 //添加数据
162 void add(struct Student stu[],int pos,int nums)//开始位置、添加人数
163 {
164     for(int i=pos;i<pos+nums;i++)
165     {
166         printf("please input name:");
167         scanf("%s",stu[i].name);
168         int flag = 1,sno;
169         while(flag)
170         {
171           printf("please input sno:");
172           scanf("%d",&sno);
173             for(int j=0;j<pos;j++)
174             {
175                 if(stu[j].sno==sno)
176                 {
177                     printf("sno is exist!\n");
178                     break;
179                 }
180                 else
181                 {
182                     flag = 0;
183                 }
184             }
185             stu[i].sno = sno;
186         }
187         printf("please input age:");
188         scanf("%d",&stu[i].age);
189         printf("please input gender:(f/m or F/M)");
190         getchar();
191         scanf("%c",&stu[i].gender);
192         printf("please input EnglishScore:");
193         scanf("%f",&stu[i].EnglishScore);
194         printf("please input mathScore:");
195         scanf("%f",&stu[i].mathScore);
196         printf("please input ChineseScore:");
197         scanf("%f",&stu[i].chineseScore);
198         printf("学生信息添加成功!\n");
199     }
200     count = count + nums;
201 }
202 
203 //按学号删除
204 void Delete_sno(struct Student *stu,int Sno)
205 {
206     if(count==0)
207     {
208         printf("成员已为空!\n");
209         return;
210     }
211     int flag=0;
212     for(int i=0;i<count;i++)
213     {
214         if((stu+i)->sno==Sno)
215         {
216             for(int j=i;j<count;j++)
217             {
218                 *(stu+j)=*(stu+j+1);
219             }
220             printf("\n");
221             printf("学号为%d的学生已被删除\n",Sno);
222             printf("\n");
223             flag=1;
224             count = count-1;
225             break;
226         }
227     }
228     if(flag==0)
229         printf("学号%d不存在.\n",Sno);
230 }
231 
232 //按姓名删除
233 void Delete_name(struct Student *stu,char Name[])
234 {
235     if(count==0)
236     {
237         printf("成员已为空!\n");
238         return;
239     }
240     int flag=0;
241     int n=count;
242     for(int i=0;i<n;i++)
243     {
244         if(strcmp((stu+i-flag)->name,Name)==0)
245         {
246             for(int j=i-flag;j<count;j++)
247             {
248                 *(stu+j)=*(stu+j+1);
249             }
250             printf("\n");
251             printf("学生:%s 已被删除.\n",Name);
252             printf("\n");
253             flag=flag+1;
254             count =count -1;
255         }
256     }
257     if(flag==0)
258         printf("学生:%s 不存在.\n",Name);
259 }
260 
261 //修改数据
262 void update(struct Student stu[],int sno,int len)
263 {
264     char cs,cs1,cs2,cs3;
265     char p[20];
266     int grade,i;
267     for(i=0; i<len; i++)
268     {
269         if(sno==stu[i].sno)
270         {
271             printf("please ask update name?(y/n):");
272             getchar();
273             cs = getchar();
274             if(cs == 'y')
275             {
276                 printf("please input a new name:");
277                 scanf("%s",p);
278                 getchar();
279                 strcpy(stu[i].name,p);
280                 printf("update is succeed!\n");
281             }
282             
283             printf("please ask update EnglishScore?(y/n):");
284             cs1 = getchar();
285             if(cs1 == 'y')
286             {
287                 printf("please input a new grade:");
288                 scanf("%d",&grade);
289                 stu[i].EnglishScore = grade;
290                 printf("update is succeed!\n");
291             }
292  
293             printf("please ask update mathScore?(y/n):");
294             getchar();
295             cs2 = getchar();
296             if(cs2 == 'y')
297             {
298                 printf("please input a new grade:");
299                 scanf("%d",&grade);
300                 stu[i].mathScore = grade;
301                 printf("update is succeed!\n");
302             }
303 
304             printf("please ask update chineseScore?(y/n):");
305             getchar();
306             cs3 = getchar();
307             if(cs3 == 'y')
308             {
309                 printf("please input a new grade:");
310                 scanf("%d",&grade);
311                 stu[i].chineseScore = grade;
312                 printf("update is succeed!\n");
313                 break;
314             }
315             else
316             {
317                 getchar();
318                 break;
319             }
320         }
321         else if(i==len-1)
322         {
323             printf("error,don't have the sno!");
324             break;
325         }
326         else
327         {
328             continue;
329         }
330     }
331 }
332 
333 //查询数据
334 void menu(struct Student stu[],int m)
335 {
336     int logel = 1;
337     while(logel)
338     {
339         seekScreen();
340         int n;
341         scanf("%d",&n);
342         char name[20];
343         int num;
344         switch(n)
345         {
346             case 1 :
347                 printf("请输入同学的姓名: ");
348                 scanf("%s",name);
349                 search(stu,count,name);
350                 break;
351             case 2 :
352                 printf("\n请输入同学的学号: ");
353                 scanf("%d",&num);
354                 search1(stu,count,num);
355                 break;
356             case 3:
357                 print(stu,count);
358                 break;
359             case 4:
360                 sort(stu,count);
361                 print(stu,count);
362                 break;
363             case 5:
364                 max_min(stu,count);
365                 break;
366             case 6:
367                 logel = 0;
368                 break;
369             default:
370                 logel = 0;
371                 printf("输入数字有误!\n");
372                 break;
373         }
374     }
375 }
376 void search(struct Student stu[],int n,char Name[])
377 {
378     char* p= Name;
379     int flag = 0;
380     for(int i=0;i<n;i++)
381     {
382         if(strcmp(stu[i].name,p)==0)
383         {
384             flag = 1;
385             My_print_sum(stu,i);
386         }
387     }
388     if(flag==0)
389     {
390         printf("the name is not exist!\n");
391     }
392 }
393 void search1(struct Student stu[],int n,int Num)
394 {
395     int flag = 0;
396     for(int i=0;i<n;i++)
397     {
398         if(Num==stu[i].sno)
399         {
400             flag = 1;
401             My_print_sum(stu,i);
402         }
403     }
404     if(flag==0)
405     {
406         printf("the sno is not exist!\n");
407     }
408 }
409 void sort(struct Student stu[],int n)
410 {
411     float sum[N];
412     for(int i=0;i<n;i++)
413     {
414         sum[i]=stu[i].EnglishScore+stu[i].mathScore+stu[i].chineseScore;
415     }
416     for(int i=0;i<n-1;i++)
417     {
418         for(int j=0;j<n-1-i;j++)
419         {
420             if(sum[j]<sum[j+1])
421             {
422                 float temp1 = sum[j];
423                 sum[j] = sum[j+1];
424                 sum[j+1] = temp1;
425                 
426                 struct Student temp;
427                 temp=stu[j];
428                 stu[j]=stu[j+1];
429                 stu[j+1]=temp;
430             }
431         }
432     }
433 }
434 void max_min(struct Student stu[],int n)
435 {
436     sort(stu,n);
437 
438     printf("成绩最优的同学:");
439     My_print_sum(stu,0);
440     
441     printf("成绩最差的同学:");
442     My_print_sum(stu,n-1);
443 }
444 
445 void print(struct Student stu[],int n)
446 {
447     for(int i=0;i<n;i++)
448     {
449         My_print_sum(stu,i);
450     }
451 }
452 
453 void My_print_sum(struct Student stu[],int n)
454 {
455     printf("\n姓名:%s,学号:%d,年龄:%d,性别:%c,英语:%.2f,数学:%.2f,语文: %.2f,总分:%.2f\n",
456            stu[n].name,stu[n].sno,stu[n].age,stu[n].gender,
457            stu[n].EnglishScore,stu[n].mathScore,stu[n].chineseScore,(stu[n].EnglishScore+stu[n].mathScore+stu[n].chineseScore));
458 }
C语言项目:学生成绩管理系统

 

程序猿神奇的手,每时每刻,这双手都在改变着世界的交互方式!


本文转自当天真遇到现实博客园博客,原文链接:http://www.cnblogs.com/XYQ-208910/p/4745371.html,如需转载请自行联系原作者