鱼C论坛

 找回密码
 立即注册
查看: 1834|回复: 14

[已解决]学生成绩管理系统求助

[复制链接]
发表于 2021-11-1 10:18:58 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
这个代码不知道为什么第一个指令只能运行2次。



  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. #include<math.h>

  5. struct Student
  6. {
  7.         char name[40];
  8.         int num;
  9.         int English_mark;
  10.         int Math_mark;
  11.         int c_mark;
  12.         int avermark;
  13. };

  14. struct Line
  15. {
  16.         struct Student student;
  17.         struct Line *next;
  18. };

  19. struct Line *head;

  20. void getInput(struct Line *student)
  21. {
  22.         printf("该学生的名字为:");
  23.         scanf("%s",student->student.name);
  24.         getchar();
  25.         printf("该学生的学号为:");
  26.         scanf("%d",&student->student.num);
  27.         getchar();
  28.         printf("该学生的英语成绩为:");
  29.         scanf("%d",&student->student.English_mark);
  30.         getchar();
  31.         printf("该学生的高数成绩为:");
  32.         scanf("%d",&student->student.Math_mark);
  33.         getchar();
  34.         printf("该学生的c语言程序设计成绩为:");
  35.         scanf("%d",&student->student.c_mark);
  36.         getchar();
  37.         student->student.avermark=(student->student.c_mark+student->student.English_mark+student->student.Math_mark)/3;
  38. }
  39. void addStudent(struct Line **head)
  40. {
  41.         struct Line *student,*temp,*previous,*current;
  42.         student=(struct Line*)malloc(sizeof(struct Line));
  43.         if(student==NULL)
  44.         {
  45.                 printf("内存分配失败!!");
  46.                 exit(1);
  47.         }
  48.         getInput(student);
  49.        
  50.         if(*head==NULL)
  51.         {
  52.                 *head=student;
  53.                 student->next=NULL;
  54.         }
  55.         else
  56.         {
  57.                 current=*head;
  58.                 previous=NULL;
  59.                 while(current->next!=NULL&&current->student.avermark<student->student.avermark)
  60.                 {
  61.                         previous=current;
  62.                         current=current->next;
  63.                 }
  64.                 if(current==NULL)
  65.                 {
  66.                         current->next=student;
  67.                         student->next=NULL;
  68.                 }
  69.                 else
  70.                 {
  71.                         student->next=current;
  72.                         previous->next=student;
  73.                 }
  74.                
  75.         }

  76. }

  77. /*struct Line *searchStudent(struct Line *head,char input)
  78. {
  79.         struct Line *student;
  80.         student=head;
  81.         while(student!=NULL)
  82.         {
  83.                 if(!strcmp(student->student.name,input)||!strcmp(student->student.c_mark,input)||!strcmp(student->student.English_mark,input)||!strcmp(student->student.Math_mark,input)||!strcmp(student->student.num,input))
  84.                 {
  85.                         break;
  86.                 }
  87.                 student=student->next;
  88.         }
  89.         return student;
  90. }*/


  91. void printStudent(struct Line *head)
  92. {
  93.         printf("姓名:%s\n",head->student.name);
  94.         printf("学号:%d\n",head->student.num);
  95.         printf("高数成绩:%d\n",head->student.Math_mark);
  96.         printf("英语成绩:%d\n",head->student.English_mark);
  97.         printf("c语言程序设计成绩:%d",head->student.c_mark);
  98.         printf("三科平均分为:%d",head->student.avermark);
  99. }


  100. void heart()
  101. {printf("      ****       ****\n");
  102.    printf("   *********   *********\n");
  103.    printf("************* *************\n");
  104.    int i,j;
  105.    for(i=0;i<3;i++)
  106.    {
  107.      for(j=0;j<29;j++)
  108.      {
  109.       printf("*");
  110.     }
  111.      printf("\n");
  112.   }
  113.   for(i=0;i<7;i++)
  114.    {
  115.      for(j=0;j<2*(i+1)-1;j++)
  116.      {
  117.       printf(" ");
  118.     }
  119.      for(j=0;j<27-i*4;j++)
  120.      {
  121.       printf("*");
  122.     }
  123.      printf("\n");
  124.     }
  125.   for(i=0;i<14;i++)
  126.   {
  127.     printf(" ");
  128.   }
  129.    printf("*\n") ;
  130. }

  131. void menu()
  132. {
  133.         printf("************************\n");
  134.         printf("1.添加学生信息\n");
  135.         printf("2.查看成绩表\n");
  136.         printf("3.查询成绩信息\n");
  137.         printf("4.删除学生信息\n");
  138.         printf("5.修改学生信息\n");
  139.         printf("0.退出程序\n");
  140.         printf("*************************\n");
  141. }
  142. int main()
  143. {
  144.           char ch;
  145.           struct Line *head;
  146.           char sh[20];
  147.           struct Line *student;
  148.         heart();
  149.         printf("欢迎使用学生成绩管理系统 \n");
  150.         printf("welcome to student manage system\n");
  151.         printf("====power by swaggy boi!!!====\n");
  152.         while(1)
  153.         {
  154.                 menu();
  155.                 printf("选哪个程序xd:");
  156.                 scanf("%d",&ch);
  157.                 getchar();
  158.                 switch(ch)
  159.                 {
  160.                         case 1: addStudent(&head);
  161.                                     char ch;
  162.                                
  163.                                         while(1)
  164.                                         {
  165.                                                 printf("学生信息录入成功!!!\n");
  166.                                                 printf("是否继续输入(Y/N):");
  167.                                                 ch=getchar();
  168.                                                 getchar();
  169.                                                 if(ch=='Y'||ch=='y')
  170.                                                 {
  171.                                                         addStudent(&head);
  172.                                                         printf(" 学生信息录入成功!!!\n");
  173.                                                        
  174.                                                 }
  175.                                                 else if(ch=='N'||ch=='n')
  176.                                                 {
  177.                                                         break ;
  178.                                                 }
  179.                                         }
  180.                                    break;
  181.                         case 2:;
  182.                         case 3:;                          
  183.                         case 4:;
  184.                         case 5:;
  185.                         case 0:;       
  186.                 }       
  187.         }  
  188. return 0;
  189. }
复制代码
最佳答案
2021-11-1 10:58:38
superswagy2002 发表于 2021-11-1 10:51
这里确实错了但我改了之后也只能运行两次

      还有两处也需要修改
      第一处是第 63 行
  1.                while(current->next!=NULL&&current->student.avermark<student->student.avermark)
复制代码

      应该改为:
  1.                 while(current != NULL && current -> student . avermark < student -> student . avermark)
复制代码

      第二处是第 156 行
  1.           struct Line *head;
复制代码

      必须改为:
  1.           struct Line * head = NULL ;
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-11-1 10:29:20 | 显示全部楼层

回帖奖励 +1 鱼币

本帖最后由 jackz007 于 2021-11-1 10:30 编辑

        第70行:
  1.                 if(current==NULL)
  2.                 {
  3.                         current->next=student;   // current = NULL,这行代码导致程序奔溃
  4.                         student->next=NULL;
  5.                 }
复制代码

        改为:
  1.                 if(current==NULL)
  2.                 {
  3.                         previous->next=student;
  4.                         student->next=NULL;
  5.                 }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-11-1 10:40:25 | 显示全部楼层

回帖奖励 +1 鱼币

又是C
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-11-1 10:51:39 | 显示全部楼层
jackz007 发表于 2021-11-1 10:29
第70行:

        改为:

这里确实错了但我改了之后也只能运行两次
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-11-1 10:58:38 | 显示全部楼层    本楼为最佳答案   
superswagy2002 发表于 2021-11-1 10:51
这里确实错了但我改了之后也只能运行两次

      还有两处也需要修改
      第一处是第 63 行
  1.                while(current->next!=NULL&&current->student.avermark<student->student.avermark)
复制代码

      应该改为:
  1.                 while(current != NULL && current -> student . avermark < student -> student . avermark)
复制代码

      第二处是第 156 行
  1.           struct Line *head;
复制代码

      必须改为:
  1.           struct Line * head = NULL ;
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-11-1 11:11:31 | 显示全部楼层
jackz007 发表于 2021-11-1 10:58
还有两处也需要修改
      第一处是第 63 行

感谢大佬
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-11-1 11:24:56 | 显示全部楼层

回帖奖励 +1 鱼币

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-11-1 11:29:25 | 显示全部楼层

回帖奖励 +1 鱼币

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-11-1 12:47:36 | 显示全部楼层

回帖奖励 +1 鱼币

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-11-1 16:59:16 | 显示全部楼层

回帖奖励 +1 鱼币

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-11-1 17:05:01 | 显示全部楼层

回帖奖励 +1 鱼币

.
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-11-1 17:05:32 | 显示全部楼层
..........
.........
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-11-1 17:42:21 | 显示全部楼层

回帖奖励 +1 鱼币

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-11-2 08:48:08 | 显示全部楼层

回帖奖励 +1 鱼币

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-11-2 16:18:45 | 显示全部楼层

回帖奖励 +1 鱼币

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-1 06:48

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表