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

一、功能实现:

0、浏览学生信息
1、输入学生信息
2、增加学生信息
3、修改学生信息
4、删除学生信息
5、按学号查询
6、按班级查询
7、按姓名查询
8、按课堂名称查询
9、按总分高低排序
10、单科成绩排名
11、查询班级优秀率
12、清屏
13、退出系统

二、运用到的核心知识:

0、动态链表的创建、输出、查找、增加、修改、删除等

1、链表的冒泡排序

三、代码如下:

   1 #include <stdio.h>
   2 #include <stdlib.h>
   3 #include <string.h>
   4 #define lis struct stu
   5 #define setup (lis *)malloc(sizeof(lis))
   6 
   7 struct score
   8 {
   9     float ord_scor;
  10     //expe_scor,exam_scor;//可增加学生单科各类成绩,为简便,在此忽略
  11 };
  12 
  13 struct stu
  14 {
  15     int num;
  16     char name[10];
  17     struct score Chinese,Math,English,Physics,Chem,Bio;
  18     float fina_scor;
  19     lis *next;
  20 };
  21 
  22 lis *p;
  23 
  24 lis* input()//输入学生信息
  25 {
  26     lis *head,*tail;
  27     int cnt=0;
  28 
  29     p=setup;
  30 
  31     printf("学号  姓名  语文  数学  英语  物理  化学  生物\n");
  32     scanf("%d",&p->num);
  33     while(1)
  34     {
  35         if(p->num==0)
  36             break;
  37         cnt++;
  38         scanf("%s%f%f%f%f%f%f",p->name,&(p->Chinese).ord_scor,&(p->Math).ord_scor,&(p->English).ord_scor,&(p->Physics).ord_scor,&(p->Chem).ord_scor,&(p->Bio).ord_scor);
  39         if(cnt==1)
  40         {
  41             head=tail=p;
  42         }
  43         else
  44         {
  45             tail->next=p;
  46             tail=p;
  47         }
  48 
  49         p=setup;
  50         scanf("%d",&p->num);
  51     }
  52     tail->next=NULL;
  53 
  54     return (head);
  55 }
  56 
  57 lis* alter(lis *head)//修改学生信息
  58 {
  59     float alt_num,alt_scor;
  60     int course;
  61 
  62     printf("请输入要修改的学生学号(0代表结束): ");
  63     scanf("%f",&alt_num);
  64     while(alt_num!=0)
  65     {
  66         p=head;
  67         while(p!=NULL)
  68         {
  69             if(p->num!=alt_num)
  70                 p=p->next;
  71             else
  72                 break;
  73         }
  74         if(p==NULL)
  75         {
  76             printf("输入学号有错!请重新输入(0代表结束): ");
  77         }
  78         else
  79         {
  80             printf("请输入要修改的课程代表的编号(1-语文,2-数学,3-英语,4-物理,5-化学,6-生物,0-修改结束): ");
  81             scanf("%d",&course);
  82 
  83             while(course>6||course<0)
  84             {
  85                 printf("输入编号有错!请重新输入编号(0代表结束): ");
  86                 scanf("%d",&course);
  87             }
  88 
  89             while(course!=0)
  90             {
  91                 if(course>6||course<0)
  92                     printf("输入编号有错!请重新输入编号(0代表结束): ");
  93                 else
  94                 {
  95                     p=head;
  96                     while(p!=NULL)
  97                     {
  98                         if(p->num==alt_num)
  99                         {
 100                             printf("请输入新成绩:\n");
 101                             scanf("%f",&alt_scor);
 102 
 103                             switch(course)
 104                             {
 105                                 case 1:(p->Chinese).ord_scor=alt_scor;break;
 106                                 case 2:(p->Math).ord_scor=alt_scor;break;
 107                                 case 3:(p->English).ord_scor=alt_scor;break;
 108                                 case 4:(p->Physics).ord_scor=alt_scor;break;
 109                                 case 5:(p->Chem).ord_scor=alt_scor;break;
 110                                 case 6:(p->Bio).ord_scor=alt_scor;break;
 111                             }
 112                         }
 113                         p=p->next;
 114                     }
 115                     printf("若继续修改该学生成绩,请输入编号(0代表结束): ");
 116                 }
 117                 scanf("%d",&course);
 118             }
 119             printf("请输入学号(0代表结束): ");
 120         }
 121         scanf("%f",&alt_num);
 122     }
 123     return (head);
 124 }
 125 
 126 lis* add(lis *head)//增加学生信息
 127 {
 128     lis *tail,*z,*q;
 129 
 130     q=tail=head;
 131     while(q!=NULL)
 132     {
 133         z=tail; //z指向倒数第二个结点
 134         tail=q;
 135         q=q->next;
 136     }           //tail->next==NULL
 137 
 138     p=setup;
 139     printf("请增加学生信息(学号为0无效,且结束增加):\n学号  姓名  语文  数学  英语  物理  化学  生物\n");
 140     scanf("%d%s%f%f%f%f%f%f",&p->num,p->name,&(p->Chinese).ord_scor,&(p->Math).ord_scor,&(p->English).ord_scor,&(p->Physics).ord_scor,&(p->Chem).ord_scor,&(p->Bio).ord_scor);
 141 
 142     int flag;
 143     while(p->num!=0)
 144     {
 145         flag=0;
 146         while(flag==0||flag==1)
 147         {
 148             q=head;
 149             while(q!=NULL)
 150             {
 151                 if(q->num==p->num)//学号重复
 152                 {
 153                     flag=1;
 154                     break;
 155                 }
 156                 else
 157                     q=q->next;
 158             }
 159 
 160             if(flag==1)
 161             {
 162                 flag=0;
 163                 printf("已存在该学生,请重新输入:\n");
 164                 p=setup;
 165                 scanf("%d%s%f%f%f%f%f%f",&p->num,p->name,&(p->Chinese).ord_scor,&(p->Math).ord_scor,&(p->English).ord_scor,&(p->Physics).ord_scor,&(p->Chem).ord_scor,&(p->Bio).ord_scor);
 166             }
 167             else
 168                 break;
 169         }
 170 
 171         z->next=p;
 172         p->next=tail;
 173         z=p;
 174 
 175         p=setup;
 176         scanf("%d%s%f%f%f%f%f%f",&p->num,p->name,&(p->Chinese).ord_scor,&(p->Math).ord_scor,&(p->English).ord_scor,&(p->Physics).ord_scor,&(p->Chem).ord_scor,&(p->Bio).ord_scor);
 177     }
 178     return (head);
 179 }
 180 
 181 lis* delet(lis *head)//删除学生信息
 182 {
 183     int del_num;
 184     lis *t;
 185 
 186     printf("请输入要删除的成绩对应的学号(0表示删除结束):\n");
 187     scanf("%d",&del_num);
 188 
 189     while(del_num)
 190     {
 191         p=head;
 192         while(p!=NULL)
 193         {
 194             if(head->num==del_num)
 195             {
 196                 head=p->next; break;
 197             }
 198             else if(p->num==del_num)
 199             {
 200                 t->next=p->next; break;
 201             }
 202             t=p;
 203             p=p->next;
 204         }
 205         if(p==NULL)
 206             printf("输入学号有错!请重新输入:\n");
 207 
 208         scanf("%d",&del_num);
 209     }
 210 
 211     return (head);
 212 }
 213 
 214 void search_print(lis *p)
 215 {
 216     printf("%d%7s%8.2f%10.2f%10.2f%10.2f%10.2f%10.2f\n",p->num,p->name,(p->Chinese).ord_scor,(p->Math).ord_scor,(p->English).ord_scor,(p->Physics).ord_scor,(p->Chem).ord_scor,(p->Bio).ord_scor);
 217 }
 218 
 219 void search(lis *head,int key)//各种方式查询学生信息
 220 {
 221     lis *q=head;
 222     int sear_num,sear_class,sear_course,flag1=0,flag2=0;
 223     char sear_name[10];
 224 
 225     if(key==5)
 226     {
 227         printf("请输入学号:");
 228         scanf("%d",&sear_num);
 229     }
 230     else if(key==6)
 231     {
 232         flag1=1;                        //标记按班级查询
 233         printf("请输入班级:");
 234         scanf("%d",&sear_class);
 235     }
 236     else if(key==7)
 237     {
 238         printf("请请输入姓名:");
 239         scanf("%s",sear_name);
 240     }
 241     else if(key==8)
 242     {
 243         flag2=1;                        //标记按课程查询
 244         printf("请输入课程代表的编号(1-语文,2-数学,3-英语,4-物理,5-化学,6-生物):");
 245         scanf("%d",&sear_course);
 246     }
 247 
 248     if(flag2)                           //按课程查询
 249     {
 250         switch(sear_course)
 251         {
 252             case 1:
 253             {
 254                 printf("学号    姓名    语文\n");
 255                 while(q!=NULL)
 256                 {
 257                     printf("%d%7s%8.2f\n",q->num,q->name,(q->Chinese).ord_scor);
 258                     q=q->next;
 259                 }
 260             }break;
 261             case 2:
 262             {
 263                 printf("学号    姓名    数学\n");
 264                 while(q!=NULL)
 265                 {
 266                     printf("%d%7s%8.2f\n",q->num,q->name,(q->Math).ord_scor);
 267                     q=q->next;
 268                 }
 269             }break;
 270             case 3:
 271             {
 272                 printf("学号    姓名    英语\n");
 273                 while(q!=NULL)
 274                 {
 275                     printf("%d%7s%8.2f\n",q->num,q->name,(q->English).ord_scor);
 276                     q=q->next;
 277                 }
 278             }break;
 279             case 4:
 280             {
 281                 printf("学号    姓名    物理\n");
 282                 while(q!=NULL)
 283                 {
 284                     printf("%d%7s%8.2f\n",q->num,q->name,(q->Physics).ord_scor);
 285                     q=q->next;
 286                 }
 287             }break;
 288             case 5:
 289             {
 290                 printf("学号    姓名    化学\n");
 291                 while(q!=NULL)
 292                 {
 293                     printf("%d%7s%8.2f\n",q->num,q->name,(q->Chem).ord_scor);
 294                     q=q->next;
 295                 }
 296             }break;
 297             case 6:
 298             {
 299                 printf("学号    姓名    生物\n");
 300                 while(q!=NULL)
 301                 {
 302                     printf("%d%7s%8.2f\n",q->num,q->name,(q->Bio).ord_scor);
 303                     q=q->next;
 304                 }
 305             }break;
 306             default:printf("输入错误!\n");
 307         }
 308     }
 309     else
 310     {
 311         if(flag1)                       //按班级查询
 312         {
 313             int flag3=0;                //标记是否有输入的班级
 314 
 315             while(q!=NULL)
 316             {
 317                 if((q->num)/100==sear_class)
 318                 {
 319                     flag3=1;
 320                     break;
 321                 }
 322                 q=q->next;
 323             }
 324 
 325             if(flag3)
 326             {
 327                 q=head;//q要指向头节点
 328 
 329                 printf("学号    姓名    语文    数学    英语    物理    化学    生物\n");
 330                 while(q!=NULL)
 331                 {
 332                     if((q->num)/100==sear_class)
 333                         search_print(q);
 334                     q=q->next;
 335                 }
 336 
 337             }
 338             else
 339                 printf("输入错误!\n");
 340         }
 341         else                            //按学号或姓名查询
 342         {
 343             while(q!=NULL)
 344             {
 345                 if(q->num==sear_num)
 346                     break;
 347                 if(strcmp(q->name,sear_name)==0)
 348                     break;
 349                 q=q->next;
 350             }
 351 
 352             if(q==NULL)
 353                 printf("输入错误!\n");
 354             else
 355             {
 356                 printf("学号    姓名    语文    数学    英语    物理    化学    生物\n");
 357                 search_print(q);
 358             }
 359         }
 360     }
 361 }
 362 
 363 lis* bubble_sort(lis *head,int len,int key)//冒泡排序
 364 {
 365     lis *t=setup;
 366     int i=len;
 367 
 368     if(key==100)//交换总分
 369     {
 370         while(i>1)
 371         {
 372             p=head;
 373             while(p->next!=NULL)
 374             {
 375                 if(p->fina_scor<(p->next)->fina_scor)
 376                 {
 377                     t->num=p->num;//交换学号
 378                     p->num=(p->next)->num;
 379                     (p->next)->num=t->num;
 380 
 381                     strcpy(t->name,p->name);//交换姓名
 382                     strcpy(p->name,(p->next)->name);
 383                     strcpy((p->next)->name,t->name);
 384 
 385                     t->fina_scor=p->fina_scor;
 386                     p->fina_scor=(p->next)->fina_scor;
 387                     (p->next)->fina_scor=t->fina_scor;
 388                 }
 389                 p=p->next;
 390             }
 391             i--;
 392         }
 393         return (head);
 394     }
 395     else if(key==1)//交换语分
 396     {
 397         while(i>1)
 398         {
 399             p=head;
 400             while(p->next!=NULL)
 401             {
 402                 if((p->Chinese).ord_scor<((p->next)->Chinese).ord_scor)
 403                 {
 404                     t->num=p->num;//交换学号
 405                     p->num=(p->next)->num;
 406                     (p->next)->num=t->num;
 407 
 408                     strcpy(t->name,p->name);//交换姓名
 409                     strcpy(p->name,(p->next)->name);
 410                     strcpy((p->next)->name,t->name);
 411 
 412                     (t->Chinese).ord_scor=(p->Chinese).ord_scor;
 413                     (p->Chinese).ord_scor=((p->next)->Chinese).ord_scor;
 414                     ((p->next)->Chinese).ord_scor=(t->Chinese).ord_scor;
 415                 }
 416 
 417                 p=p->next;
 418             }
 419             i--;
 420         }
 421         return (head);
 422     }
 423     else if(key==2)//交换数分
 424     {
 425         while(i>1)
 426         {
 427             p=head;
 428             while(p->next!=NULL)
 429             {
 430                 if((p->Math).ord_scor<((p->next)->Math).ord_scor)
 431                 {
 432                     t->num=p->num;//交换学号
 433                     p->num=(p->next)->num;
 434                     (p->next)->num=t->num;
 435 
 436                     strcpy(t->name,p->name);//交换姓名
 437                     strcpy(p->name,(p->next)->name);
 438                     strcpy((p->next)->name,t->name);
 439 
 440                     (t->Math).ord_scor=(p->Math).ord_scor;
 441                     (p->Math).ord_scor=((p->next)->Math).ord_scor;
 442                     ((p->next)->Math).ord_scor=(t->Math).ord_scor;
 443                 }
 444 
 445                 p=p->next;
 446             }
 447             i--;
 448         }
 449         return (head);
 450     }
 451     else if(key==3)//交换英分
 452     {
 453         while(i>1)
 454         {
 455             p=head;
 456             while(p->next!=NULL)
 457             {
 458                 if((p->English).ord_scor<((p->next)->English).ord_scor)
 459                 {
 460                     t->num=p->num;//交换学号
 461                     p->num=(p->next)->num;
 462                     (p->next)->num=t->num;
 463 
 464                     strcpy(t->name,p->name);//交换姓名
 465                     strcpy(p->name,(p->next)->name);
 466                     strcpy((p->next)->name,t->name);
 467 
 468                     (t->English).ord_scor=(p->English).ord_scor;
 469                     (p->English).ord_scor=((p->next)->English).ord_scor;
 470                     ((p->next)->English).ord_scor=(t->English).ord_scor;
 471                 }
 472                 p=p->next;
 473             }
 474             i--;
 475         }
 476         return (head);
 477     }
 478     else if(key==4)//交换物分
 479     {
 480         while(i>1)
 481         {
 482             p=head;
 483             while(p->next!=NULL)
 484             {
 485                 if((p->Physics).ord_scor<((p->next)->Physics).ord_scor)
 486                 {
 487                     t->num=p->num;//交换学号
 488                     p->num=(p->next)->num;
 489                     (p->next)->num=t->num;
 490 
 491                     strcpy(t->name,p->name);//交换姓名
 492                     strcpy(p->name,(p->next)->name);
 493                     strcpy((p->next)->name,t->name);
 494 
 495                     (t->Physics).ord_scor=(p->Physics).ord_scor;
 496                     (p->Physics).ord_scor=((p->next)->Physics).ord_scor;
 497                     ((p->next)->Physics).ord_scor=(t->Physics).ord_scor;
 498                 }
 499                 p=p->next;
 500             }
 501             i--;
 502         }
 503         return (head);
 504     }
 505     else if(key==5)//交换化分
 506     {
 507         while(i>1)
 508         {
 509             p=head;
 510             while(p->next!=NULL)
 511             {
 512                 if((p->Chem).ord_scor<((p->next)->Chem).ord_scor)
 513                 {
 514                     t->num=p->num;//交换学号
 515                     p->num=(p->next)->num;
 516                     (p->next)->num=t->num;
 517 
 518                     strcpy(t->name,p->name);//交换姓名
 519                     strcpy(p->name,(p->next)->name);
 520                     strcpy((p->next)->name,t->name);
 521 
 522                     (t->Chem).ord_scor=(p->Chem).ord_scor;
 523                     (p->Chem).ord_scor=((p->next)->Chem).ord_scor;
 524                     ((p->next)->Chem).ord_scor=(t->Chem).ord_scor;
 525                 }
 526                 p=p->next;
 527             }
 528             i--;
 529         }
 530         return (head);
 531     }
 532     else if(key==6)//交换生分
 533     {
 534         while(i>1)
 535         {
 536             p=head;
 537             while(p->next!=NULL)
 538             {
 539                 if((p->Bio).ord_scor<((p->next)->Bio).ord_scor)
 540                 {
 541                     t->num=p->num;//交换学号
 542                     p->num=(p->next)->num;
 543                     (p->next)->num=t->num;
 544 
 545                     strcpy(t->name,p->name);//交换姓名
 546                     strcpy(p->name,(p->next)->name);
 547                     strcpy((p->next)->name,t->name);
 548 
 549                     (t->Bio).ord_scor=(p->Bio).ord_scor;
 550                     (p->Bio).ord_scor=((p->next)->Bio).ord_scor;
 551                     ((p->next)->Bio).ord_scor=(t->Bio).ord_scor;
 552                 }
 553                 p=p->next;
 554             }
 555             i--;
 556         }
 557         return (head);
 558     }
 559 }
 560 
 561 void final_score_sort(lis *head)//按总分高低排序
 562 {
 563     int cnt=0,z=100;
 564 
 565     p=head;
 566     while(p!=NULL)
 567     {
 568         cnt++;
 569 
 570         p->fina_scor=(p->Chinese).ord_scor+(p->Math).ord_scor+(p->English).ord_scor+(p->Physics).ord_scor+(p->Chem).ord_scor+(p->Bio).ord_scor;
 571         p=p->next;
 572     }
 573 
 574     head=bubble_sort(head,cnt,z);
 575 
 576     printf("名次    学号\t    姓名    总分\n");
 577 
 578     cnt=1;
 579     p=head;
 580     while(p!=NULL)
 581     {
 582         printf("%d\t%d\t%7s%8.2f\n",cnt++,p->num,p->name,p->fina_scor);
 583         p=p->next;
 584     }
 585 }
 586 
 587 void  single_course_sort(lis *head)//单科成绩排名
 588 {
 589     int select,cnt=0;
 590 
 591     p=head;
 592     while(p!=NULL)
 593     {
 594         cnt++;
 595         p=p->next;
 596     }
 597 
 598     printf("请输入课程代表的编号(1-语文,2-数学,3-英语,4-物理,5-化学,6-生物):");
 599     scanf("%d",&select);
 600 
 601     switch(select)
 602     {
 603         case 1:
 604             {
 605                 head=bubble_sort(head,cnt,select);
 606                 printf("名次    学号\t    姓名    语文分数\n");
 607 
 608                 cnt=1;
 609                 p=head;
 610                 while(p!=NULL)
 611                 {
 612                     printf("%d\t%d\t%7s%8.2f\n",cnt++,p->num,p->name,(p->Chinese).ord_scor);
 613                     p=p->next;
 614                 }
 615             }break;
 616         case 2:
 617             {
 618                 head=bubble_sort(head,cnt,select);
 619                 printf("名次    学号\t    姓名    数学分数\n");
 620                 cnt=1;
 621                 p=head;
 622                 while(p!=NULL)
 623                 {
 624                     printf("%d\t%d\t%7s%8.2f\n",cnt++,p->num,p->name,(p->Math).ord_scor);
 625                     p=p->next;
 626                 }
 627             }break;
 628         case 3:
 629             {
 630                 head=bubble_sort(head,cnt,select);
 631                 printf("名次    学号\t    姓名    英语分数\n");
 632                 cnt=1;
 633                 p=head;
 634                 while(p!=NULL)
 635                 {
 636                     printf("%d\t%d\t%7s%8.2f\n",cnt++,p->num,p->name,(p->English).ord_scor);
 637                     p=p->next;
 638                 }
 639             }break;
 640         case 4:
 641             {
 642                 head=bubble_sort(head,cnt,select);
 643                 printf("名次    学号\t    姓名    物理分数\n");
 644                 cnt=1;
 645                 p=head;
 646                 while(p!=NULL)
 647                 {
 648                     printf("%d\t%d\t%7s%8.2f\n",cnt++,p->num,p->name,(p->Physics).ord_scor);
 649                     p=p->next;
 650                 }
 651             }break;
 652         case 5:
 653             {
 654                 head=bubble_sort(head,cnt,select);
 655                 printf("名次    学号\t    姓名    化学分数\n");
 656                 cnt=1;
 657                 p=head;
 658                 while(p!=NULL)
 659                 {
 660                     printf("%d\t%d\t%7s%8.2f\n",cnt++,p->num,p->name,(p->Chem).ord_scor);
 661                     p=p->next;
 662                 }
 663             }break;
 664         case 6:
 665             {
 666                 head=bubble_sort(head,cnt,select);
 667                 printf("名次    学号\t    姓名    生物分数\n");
 668                 cnt=1;
 669                 p=head;
 670                 while(p!=NULL)
 671                 {
 672                     printf("%d\t%d\t%7s%8.2f\n",cnt++,p->num,p->name,(p->Bio).ord_scor);
 673                     p=p->next;
 674                 }
 675             }break;
 676         default:printf("输入错误!\n");
 677     }
 678 }
 679 
 680 struct class_excel_rate
 681 {
 682     int class_num,all_stu,excel_stu;
 683     struct class_excel_rate *next;
 684 };
 685 
 686 void bubble_sort_print(struct class_excel_rate* head,int lenth)//冒泡排序并输出班级优秀率
 687 {
 688     struct class_excel_rate *t=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
 689 
 690     int len=0;
 691     float s;
 692 
 693     t=head;
 694     while(t!=NULL)
 695     {
 696         len++;
 697         t=t->next;
 698     }
 699 
 700     while(len>1)
 701     {
 702         t=head;
 703         while(t->next!=NULL)
 704         {
 705             if((t->next)->excel_stu/((t->next)->all_stu*0.1)>t->excel_stu/(t->all_stu*0.1))
 706             {
 707                 s=t->excel_stu;
 708                 t->excel_stu=(t->next)->excel_stu;
 709                 (t->next)->excel_stu=s;
 710 
 711                 s=t->all_stu;
 712                 t->all_stu=(t->next)->all_stu;
 713                 (t->next)->all_stu=s;
 714             }
 715             t=t->next;
 716         }
 717         len--;
 718     }
 719 
 720     printf("名次\t班级\t     总人数    优秀人数    优秀率\n");
 721     int i=1;
 722     t=head;
 723     while(t!=NULL)
 724     {
 725         printf("%d\t%d\t\t%d\t  %d\t   %.2f%%\n",i++,t->class_num,t->all_stu,t->excel_stu,t->excel_stu/(t->all_stu*0.1)*10);
 726         t=t->next;
 727     }
 728 }
 729 
 730 void select_class_find(lis *head,int len,int key)//查询班级优秀率
 731 {
 732 
 733     struct class_excel_rate *head1,*q,*r,*k;//创建新链表
 734 
 735     switch(key)
 736     {
 737         case 1://查询语文
 738             {
 739                 p=head;
 740 
 741                 head1=q=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
 742 
 743                 head1->class_num=p->num/100;//初始化头节点
 744                 head1->all_stu=1;
 745                 if((p->Chinese).ord_scor>=90.0)
 746                     head1->excel_stu=1;
 747                 else
 748                     head1->excel_stu=0;
 749 
 750                 p=p->next;
 751                 while(p->next!=NULL)//先建立两个两个首、尾结点,以便其它班级的插入
 752                 {
 753                     if(p->num/100==head1->class_num)//相同班级
 754                     {
 755                         head1->all_stu++;
 756                         if((p->Chinese).ord_scor>=90.0)
 757                             head1->excel_stu++;
 758                     }
 759                     else
 760                     {
 761                         q=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
 762 
 763                         q->class_num=p->num/100;
 764                         q->all_stu=1;
 765                         if((p->Chinese).ord_scor>=90.0)
 766                             q->excel_stu=1;
 767                         else
 768                             q->excel_stu=0;
 769 
 770                         head1->next=q;
 771                         q->next=NULL;
 772                         break;//建立链尾结点
 773                     }
 774                     p=p->next;
 775                 }
 776 
 777                 p=p->next;
 778                 while(p!=NULL)//检索所有剩余的班级
 779                 {
 780                     r=k=head1;//问题:最后一个班级检索没有被处理
 781                     while(r!=NULL)//检索班级是否相同
 782                     {
 783                         if(p->num/100==r->class_num)
 784                         {
 785                             r->all_stu++;
 786                             if((p->Chinese).ord_scor>=90.0)
 787                                 r->excel_stu++;
 788                             break;
 789                         }
 790                         else
 791                         {
 792                             k=r;
 793                             r=r->next;
 794                         }
 795                     }
 796 
 797                     if(r==NULL)//没有相同的班级,插入新结点
 798                     {
 799                         q=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
 800 
 801                         q->class_num=p->num/100;
 802                         q->all_stu=1;
 803                         if((p->Chinese).ord_scor>=90.0)
 804                             q->excel_stu=1;
 805                         else
 806                             q->excel_stu=0;
 807 
 808                         k->next=q;
 809                         q->next=r;
 810                     }
 811 
 812                     p=p->next;//检索下一个处理的班级
 813                 }
 814 
 815                 bubble_sort_print(head1,len);
 816 
 817             }break;
 818         case 2://查询数学
 819             {
 820                 p=head;
 821 
 822                 head1=q=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
 823 
 824                 head1->class_num=p->num/100;//初始化头节点
 825                 head1->all_stu=1;
 826                 if((p->Math).ord_scor>=90.0)
 827                     head1->excel_stu=1;
 828                 else
 829                     head1->excel_stu=0;
 830 
 831                 p=p->next;
 832                 while(p->next!=NULL)//先建立两个两个首、尾结点,以便其它班级的插入
 833                 {
 834                     if(p->num/100==head1->class_num)//相同班级
 835                     {
 836                         head1->all_stu++;
 837                         if((p->Math).ord_scor>=90.0)
 838                             head1->excel_stu++;
 839                     }
 840                     else
 841                     {
 842                         q=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
 843 
 844                         q->class_num=p->num/100;
 845                         q->all_stu=1;
 846                         if((p->Math).ord_scor>=90.0)
 847                             q->excel_stu=1;
 848                         else
 849                             q->excel_stu=0;
 850 
 851                         head1->next=q;
 852                         q->next=NULL;
 853                         break;//建立链尾结点
 854                     }
 855                     p=p->next;
 856                 }
 857 
 858                 p=p->next;
 859                 while(p!=NULL)//检索所有剩余的班级
 860                 {
 861                     r=k=head1;//问题:最后一个班级检索没有被处理
 862                     while(r!=NULL)//检索班级是否相同
 863                     {
 864                         if(p->num/100==r->class_num)
 865                         {
 866                             r->all_stu++;
 867                             if((p->Math).ord_scor>=90.0)
 868                                 r->excel_stu++;
 869                             break;
 870                         }
 871                         else
 872                         {
 873                             k=r;
 874                             r=r->next;
 875                         }
 876                     }
 877 
 878                     if(r==NULL)//没有相同的班级,插入新结点
 879                     {
 880                         q=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
 881 
 882                         q->class_num=p->num/100;
 883                         q->all_stu=1;
 884                         if((p->Math).ord_scor>=90.0)
 885                             q->excel_stu=1;
 886                         else
 887                             q->excel_stu=0;
 888 
 889                         k->next=q;
 890                         q->next=r;
 891                     }
 892 
 893                     p=p->next;//检索下一个处理的班级
 894                 }
 895 
 896                 bubble_sort_print(head1,len);
 897             }break;
 898         case 3://查询英语
 899             {
 900                  p=head;
 901 
 902                 head1=q=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
 903 
 904                 head1->class_num=p->num/100;//初始化头节点
 905                 head1->all_stu=1;
 906                 if((p->English).ord_scor>=90.0)
 907                     head1->excel_stu=1;
 908                 else
 909                     head1->excel_stu=0;
 910 
 911                 p=p->next;
 912                 while(p->next!=NULL)//先建立两个两个首、尾结点,以便其它班级的插入
 913                 {
 914                     if(p->num/100==head1->class_num)//相同班级
 915                     {
 916                         head1->all_stu++;
 917                         if((p->English).ord_scor>=90.0)
 918                             head1->excel_stu++;
 919                     }
 920                     else
 921                     {
 922                         q=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
 923 
 924                         q->class_num=p->num/100;
 925                         q->all_stu=1;
 926                         if((p->English).ord_scor>=90.0)
 927                             q->excel_stu=1;
 928                         else
 929                             q->excel_stu=0;
 930 
 931                         head1->next=q;
 932                         q->next=NULL;
 933                         break;//建立链尾结点
 934                     }
 935                     p=p->next;
 936                 }
 937 
 938                 p=p->next;
 939                 while(p!=NULL)//检索所有剩余的班级
 940                 {
 941                     r=k=head1;//问题:最后一个班级检索没有被处理
 942                     while(r!=NULL)//检索班级是否相同
 943                     {
 944                         if(p->num/100==r->class_num)
 945                         {
 946                             r->all_stu++;
 947                             if((p->English).ord_scor>=90.0)
 948                                 r->excel_stu++;
 949                             break;
 950                         }
 951                         else
 952                         {
 953                             k=r;
 954                             r=r->next;
 955                         }
 956                     }
 957 
 958                     if(r==NULL)//没有相同的班级,插入新结点
 959                     {
 960                         q=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
 961 
 962                         q->class_num=p->num/100;
 963                         q->all_stu=1;
 964                         if((p->English).ord_scor>=90.0)
 965                             q->excel_stu=1;
 966                         else
 967                             q->excel_stu=0;
 968 
 969                         k->next=q;
 970                         q->next=r;
 971                     }
 972 
 973                     p=p->next;//检索下一个处理的班级
 974                 }
 975 
 976                 bubble_sort_print(head1,len);
 977             }break;
 978         case 4://查询物理
 979             {
 980                  p=head;
 981 
 982                 head1=q=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
 983 
 984                 head1->class_num=p->num/100;//初始化头节点
 985                 head1->all_stu=1;
 986                 if((p->Physics).ord_scor>=90.0)
 987                     head1->excel_stu=1;
 988                 else
 989                     head1->excel_stu=0;
 990 
 991                 p=p->next;
 992                 while(p->next!=NULL)//先建立两个两个首、尾结点,以便其它班级的插入
 993                 {
 994                     if(p->num/100==head1->class_num)//相同班级
 995                     {
 996                         head1->all_stu++;
 997                         if((p->Physics).ord_scor>=90.0)
 998                             head1->excel_stu++;
 999                     }
1000                     else
1001                     {
1002                         q=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
1003 
1004                         q->class_num=p->num/100;
1005                         q->all_stu=1;
1006                         if((p->Physics).ord_scor>=90.0)
1007                             q->excel_stu=1;
1008                         else
1009                             q->excel_stu=0;
1010 
1011                         head1->next=q;
1012                         q->next=NULL;
1013                         break;//建立链尾结点
1014                     }
1015                     p=p->next;
1016                 }
1017 
1018                 p=p->next;
1019                 while(p!=NULL)//检索所有剩余的班级
1020                 {
1021                     r=k=head1;//问题:最后一个班级检索没有被处理
1022                     while(r!=NULL)//检索班级是否相同
1023                     {
1024                         if(p->num/100==r->class_num)
1025                         {
1026                             r->all_stu++;
1027                             if((p->Physics).ord_scor>=90.0)
1028                                 r->excel_stu++;
1029                             break;
1030                         }
1031                         else
1032                         {
1033                             k=r;
1034                             r=r->next;
1035                         }
1036                     }
1037 
1038                     if(r==NULL)//没有相同的班级,插入新结点
1039                     {
1040                         q=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
1041 
1042                         q->class_num=p->num/100;
1043                         q->all_stu=1;
1044                         if((p->Physics).ord_scor>=90.0)
1045                             q->excel_stu=1;
1046                         else
1047                             q->excel_stu=0;
1048 
1049                         k->next=q;
1050                         q->next=r;
1051                     }
1052 
1053                     p=p->next;//检索下一个处理的班级
1054                 }
1055 
1056                 bubble_sort_print(head1,len);
1057             }
1058             break;
1059         case 5://查询化学
1060             {
1061                  p=head;
1062 
1063                 head1=q=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
1064 
1065                 head1->class_num=p->num/100;//初始化头节点
1066                 head1->all_stu=1;
1067                 if((p->Chem).ord_scor>=90.0)
1068                     head1->excel_stu=1;
1069                 else
1070                     head1->excel_stu=0;
1071 
1072                 p=p->next;
1073                 while(p->next!=NULL)//先建立两个两个首、尾结点,以便其它班级的插入
1074                 {
1075                     if(p->num/100==head1->class_num)//相同班级
1076                     {
1077                         head1->all_stu++;
1078                         if((p->Chem).ord_scor>=90.0)
1079                             head1->excel_stu++;
1080                     }
1081                     else
1082                     {
1083                         q=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
1084 
1085                         q->class_num=p->num/100;
1086                         q->all_stu=1;
1087                         if((p->Chem).ord_scor>=90.0)
1088                             q->excel_stu=1;
1089                         else
1090                             q->excel_stu=0;
1091 
1092                         head1->next=q;
1093                         q->next=NULL;
1094                         break;//建立链尾结点
1095                     }
1096                     p=p->next;
1097                 }
1098 
1099                 p=p->next;
1100                 while(p!=NULL)//检索所有剩余的班级
1101                 {
1102                     r=k=head1;//问题:最后一个班级检索没有被处理
1103                     while(r!=NULL)//检索班级是否相同
1104                     {
1105                         if(p->num/100==r->class_num)
1106                         {
1107                             r->all_stu++;
1108                             if((p->Chem).ord_scor>=90.0)
1109                                 r->excel_stu++;
1110                             break;
1111                         }
1112                         else
1113                         {
1114                             k=r;
1115                             r=r->next;
1116                         }
1117                     }
1118 
1119                     if(r==NULL)//没有相同的班级,插入新结点
1120                     {
1121                         q=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
1122 
1123                         q->class_num=p->num/100;
1124                         q->all_stu=1;
1125                         if((p->Chem).ord_scor>=90.0)
1126                             q->excel_stu=1;
1127                         else
1128                             q->excel_stu=0;
1129 
1130                         k->next=q;
1131                         q->next=r;
1132                     }
1133 
1134                     p=p->next;//检索下一个处理的班级
1135                 }
1136 
1137                 bubble_sort_print(head1,len);
1138             }
1139             break;
1140         case 6://查询生物
1141             {
1142                  p=head;
1143 
1144                 head1=q=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
1145 
1146                 head1->class_num=p->num/100;//初始化头节点
1147                 head1->all_stu=1;
1148                 if((p->Bio).ord_scor>=90.0)
1149                     head1->excel_stu=1;
1150                 else
1151                     head1->excel_stu=0;
1152 
1153                 p=p->next;
1154                 while(p->next!=NULL)//先建立两个两个首、尾结点,以便其它班级的插入
1155                 {
1156                     if(p->num/100==head1->class_num)//相同班级
1157                     {
1158                         head1->all_stu++;
1159                         if((p->Bio).ord_scor>=90.0)
1160                             head1->excel_stu++;
1161                     }
1162                     else
1163                     {
1164                         q=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
1165 
1166                         q->class_num=p->num/100;
1167                         q->all_stu=1;
1168                         if((p->Bio).ord_scor>=90.0)
1169                             q->excel_stu=1;
1170                         else
1171                             q->excel_stu=0;
1172 
1173                         head1->next=q;
1174                         q->next=NULL;
1175                         break;//建立链尾结点
1176                     }
1177                     p=p->next;
1178                 }
1179 
1180                 p=p->next;
1181                 while(p!=NULL)//检索所有剩余的班级
1182                 {
1183                     r=k=head1;//问题:最后一个班级检索没有被处理
1184                     while(r!=NULL)//检索班级是否相同
1185                     {
1186                         if(p->num/100==r->class_num)
1187                         {
1188                             r->all_stu++;
1189                             if((p->Bio).ord_scor>=90.0)
1190                                 r->excel_stu++;
1191                             break;
1192                         }
1193                         else
1194                         {
1195                             k=r;
1196                             r=r->next;
1197                         }
1198                     }
1199 
1200                     if(r==NULL)//没有相同的班级,插入新结点
1201                     {
1202                         q=(struct class_excel_rate*)malloc(sizeof(struct class_excel_rate));
1203 
1204                         q->class_num=p->num/100;
1205                         q->all_stu=1;
1206                         if((p->Bio).ord_scor>=90.0)
1207                             q->excel_stu=1;
1208                         else
1209                             q->excel_stu=0;
1210 
1211                         k->next=q;
1212                         q->next=r;
1213                     }
1214 
1215                     p=p->next;//检索下一个处理的班级
1216                 }
1217 
1218                 bubble_sort_print(head1,len);
1219             }
1220             break;
1221     }
1222 }
1223 
1224 void select_course_find(lis *head)//选择查询课程优秀率
1225 {
1226 
1227     int select,cnt=0;
1228 
1229     p=head;
1230     while(p!=NULL)
1231     {
1232         cnt++;
1233         p=p->next;
1234     }
1235 
1236     printf("请输入课程代表的编号(1-语文,2-数学,3-英语,4-物理,5-化学,6-生物):");
1237     scanf("%d",&select);
1238 
1239     switch(select)
1240     {
1241         case 1:select_class_find(head,cnt,select);break;
1242         case 2:select_class_find(head,cnt,select);break;
1243         case 3:select_class_find(head,cnt,select);break;
1244         case 4:select_class_find(head,cnt,select);break;
1245         case 5:select_class_find(head,cnt,select);break;
1246         case 6:select_class_find(head,cnt,select);break;
1247         default:printf("输入错误!\n");
1248     }
1249 }
1250 
1251 void output(lis *head)//输出学生信息
1252 {
1253     p=setup;
1254     p=head;
1255     printf("学号    姓名    语文      数学      英语      物理      化学      生物\n");
1256 
1257     while(p!=NULL)
1258     {
1259         printf("%d%7s%8.2f%10.2f%10.2f%10.2f%10.2f%10.2f\n",p->num,p->name,(p->Chinese).ord_scor,(p->Math).ord_scor,(p->English).ord_scor,(p->Physics).ord_scor,(p->Chem).ord_scor,(p->Bio).ord_scor);
1260         p=p->next;
1261     }
1262 }
1263 
1264 void print()
1265 {
1266     printf("\t\t-------学生成绩管理系统-------\n");
1267     printf("\t\t\t0、浏览学生信息\n\t\t\t1、输入学生信息\n\t\t\t2、增加学生信息\n\t\t\t3、修改学生信息\n\t\t\t4、删除学生信息\n\t\t\t5、按学号查询\n");
1268     printf("\t\t\t6、按班级查询\n\t\t\t7、按姓名查询\n\t\t\t8、按课堂名称查询\n\t\t\t9、按总分高低排序\n\t\t\t10、单科成绩排名\n\t\t\t11、查询班级优秀率\n\t\t\t12、清屏\n\t\t\t13、退出系统\n");
1269     printf("\t\t------------------------------\n");
1270     printf("\n>>请输入要实现功能前的序号:  ");
1271 }
1272 
1273 int main()
1274 {
1275     int fun;
1276     lis *student;
1277 
1278     print();
1279 
1280     while(1)
1281     {
1282         scanf("%d",&fun);
1283         switch(fun)
1284         {
1285             case 0:output(student); break;
1286             case 1:student=input(); break;
1287             case 2:student=add(student); break;
1288             case 3:student=alter(student);break;
1289             case 4:student=delet(student); break;
1290             case 5:
1291             case 6:
1292             case 7:
1293             case 8:search(student,fun); break;
1294             case 9:final_score_sort(student); break;
1295             case 10:single_course_sort(student); break;
1296             case 11:select_course_find(student); break;
1297             case 12:{
1298                         system("cls");
1299                         print();
1300                     }
1301         }
1302         if(fun==1)
1303         {
1304             system("cls");
1305             print();
1306         }
1307         else if(fun==13)
1308             break;
1309         else if(fun>13)
1310             printf("\n\t**输入错误!\n>>请输入要实现功能前的序号: ");
1311         else if(fun!=12)
1312             printf("\n>>请输入要实现功能前的序号: ");
1313     }
1314     return 0;
1315 }
1316 
1317 /*测试数据
1318 150901 james  100  99    94   89.9    93    95
1319 130118 bryant 93   98    75   78.9    99.2  97.1
1320 161226 lu     85   99    78   79      66    66.9
1321 130821 jordon 99   100   98.1 90.6    91    89.9
1322 150928 antony 98   97.4  91.9 89      78    79.4
1323 161127 durant 100  98    93   82      97    80
1324 161222 love   90   89    90   91.2    93    82.7
1325 130156 duncan 99   98    91   82.5    89    78
1326 160703 paul   90   91.5  98   89      87.9  80
1327 150433 wade   93   93.4  95   91      89    80.9
1328 161316 irving 96   89    91.8 95      91    98.8
1329 161205 harden 89   88    93   95      96.7  99
1330 161305 curry  89.9 92    89   46.9    39    100
1331 160739 bosh   91.5 78    98   69.9    89    85
1332 0
1333 */

转载于:https://www.cnblogs.com/gonsedup/p/6985327.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值