鱼C论坛

 找回密码
 立即注册
查看: 2130|回复: 2

[技术交流] 自己写的一个学生成绩管理的东东!

[复制链接]
发表于 2012-2-20 23:03:49 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 hy19970612 于 2012-2-20 23:12 编辑

请大家帮我看看 找找 BUG 我一定修改 !只是那个只有一个分数 !以后会继续完善!请大家帮忙找错!找BUG!
  1. #include <stdio.h>//用的编译器为:Code::Blocks  SVN 通过!vc6不给 不知道为什么!
  2. #include <stdlib.h>
  3. #include<windows.h>

  4. struct student//会逐完善!
  5. {
  6.     int num;
  7.     float fs;
  8.     struct student *next;
  9. };

  10. // ------------------------ 函数声明区 ------------------------------//
  11. struct student *del(struct student *head);
  12. struct student *link(void);
  13. struct student *insert(struct student *head);
  14. struct student *insertxz(struct student *head);
  15. struct student * xzcz(int xz,struct student *phead);
  16. struct student * xg(struct student *head);
  17. void print_head(struct student *head);
  18. struct student * xg_xz(struct student *head);
  19. int print_head_xz(struct student *head);
  20. int xzreturn(int max,int min);// 最大值,最小值
  21. void xxlr(struct student *p);
  22. // ------------------------ 函数声明区 ------------------------------//
  23. int n = 0;
  24. int main()
  25. {
  26.     printf("\t  以下任何情况中都您都可以用“Ctrl + C”组合键来整个结束程序!\n");
  27.     int num = 0,xz = 0;
  28.     struct student *head;
  29.     printf("\n\n\t\t\t  欢迎进入学生分数管理系统!\n");
  30.     printf("\n\t\t\t  开始创建动态链表!\n");
  31.     head = link();
  32.     printf("\n\t\t\t  创建完毕......");
  33.     printf("\n\t\t\t  请选择操作......");

  34.     while( 7 == 7)
  35.     {
  36.         printf("\n\t\t\t  1.删除 2.插入 3.输出 4.修改 5.退出");
  37.         fflush( stdin );
  38.         head = xzcz(xzreturn(6,0),head);
  39.     }

  40.     system("pause");
  41. return 0;
  42. }

  43. struct student *link(void)//测试无误!
  44. {
  45.     struct student *p1,*p2,*head;
  46.     p1 = p2 = (struct student*)malloc(sizeof(struct student));
  47.     xxlr(p1);
  48.     if(p1->num == 0)
  49.     {
  50.         return(head = NULL);
  51.     }
  52.     else
  53.     {
  54.         while(p1->num)
  55.         {
  56.             n++;
  57.             if(n==1)
  58.             {
  59.                 head = p1;
  60.             }
  61.             else
  62.             {
  63.                 p2->next = p1;
  64.             }

  65.             p2 = p1;

  66.             p1 = (struct student*)malloc(sizeof(struct student));
  67.             xxlr(p1);
  68.         }
  69.         p2->next = NULL;
  70.         return(head);
  71.     }

  72. }
  73. void print_head(struct student * head)//测试无误!
  74. {
  75.     if(head == NULL)
  76.     {
  77.         printf("\t\t\t  您这是空 Link,无法输出!\n");
  78.     }
  79.     else
  80.     {
  81.         printf("\n\t\t\t  一共 %d 位学生\n",n);
  82.         while(head)
  83.         {
  84.         printf("\n\t\t\t  学号:%d \n\t\t\t  分数:%f\n",head->num,head->fs);
  85.         head = head->next;
  86.         }
  87.     }
  88. }
  89. struct student *del(struct student *head)//测试无误!
  90. {
  91.     struct student *p1,*p2;
  92.     int num;
  93.     p2 = p1 = head;
  94.     if(p1 == NULL)
  95.     {
  96.         printf("\n\t\t\t  您这是空 Link 无法删除!\n");
  97.         return head;
  98.     }

  99.     printf("\n\t\t\t  请输入您要删除结点的Num:");
  100.     fflush(stdin);
  101.     scanf("%d",&num);

  102.     while(p1)
  103.     {
  104.         if(p1->num == num)
  105.         {
  106.             if(p1 == head)
  107.             {
  108.                 p2 = p1->next;
  109.                 n--;
  110.                 head = p2;
  111.                 free(p1);
  112.                 printf("\n\t\t\t  删除成功......\n");
  113.                 return head;
  114.             }
  115.             else
  116.             {
  117.                 p2 ->next = p1->next;
  118.                 free(p1);
  119.                 n--;
  120.                 printf("\n\t\t\t  删除成功......\n");
  121.                 return head;
  122.             }
  123.         }
  124.         else
  125.         {
  126.             p2 = p1;
  127.             p1 = p1->next;
  128.         }

  129.     }
  130.     printf("\n\t\t  删除失败.....没有找到结点!\n");
  131.     return head;
  132. }
  133. struct student *insertxz(struct student *head)
  134. {

  135.     int xz,i;
  136.     printf("\t\t\t  1.单次插入 2.多次插入\n");
  137.     xz = xzreturn(2,0);
  138.     if(1 == xz)
  139.     {
  140.         head = insert(head);
  141.         return(head);
  142.     }
  143.     else if(2 == xz)
  144.     {   printf("\t\t\t  请输入要插入的次数!");
  145.         i = xzreturn(99999,0);

  146.         while(i--)
  147.         {

  148.          head = insert(head);
  149.         }
  150.         return(head);
  151.     }
  152. }
  153. struct student *delxz(struct student *head)
  154. {
  155.     int xz,i;
  156.     printf("\t\t\t  1.单次删除 2.多次删除\n");
  157.     xz = xzreturn(2,0);
  158.     if(1 == xz)
  159.     {
  160.         head = del(head);
  161.         return(head);
  162.     }
  163.     else if(2 == xz)
  164.     {   printf("\t\t\t  请输入要删除的次数!最多可以删除%d次\n",n);
  165.         i = xzreturn(n,0);
  166.         while(i--)
  167.         {

  168.          head = del(head);
  169.         }
  170.         return(head);
  171.     }
  172. }
  173. int print_head_xz(struct student *head)
  174. {
  175.     int xz,num;
  176.     int i = n;
  177.     struct student *p1;
  178.     p1 = head;
  179.     if(NULL == head)
  180.     {
  181.         printf("\n\t\t\t  此为空Link!\n");
  182.         return (0);
  183.     }
  184.     printf("\t\t\t  1.查找输出 2.全部输出 \n");
  185.     xz = xzreturn(2,0);
  186.     if(1 == xz)
  187.     {

  188.         printf("\t\t\t  请输入学号:");
  189.         fflush(stdin);
  190.         scanf("%d",&num);
  191.         while(i--)
  192.         {
  193.             if(head ->num != num || head->next != NULL)
  194.             {
  195.                 p1 = head;
  196.                 head = head ->next;
  197.             }
  198.             else
  199.             {
  200.                 continue;
  201.             }
  202.         }
  203.         if(head == NULL)
  204.         {
  205.             printf("\t\t\t  没有找到您所输入的学号!");
  206.         }
  207.         else
  208.         {
  209.             printf("\n\t\t\t  学号:%d \n\t\t\t  分数:%f\n",p1->num,p1->fs);
  210.         }

  211.     }
  212.     else if(2 == xz)
  213.     {
  214.         print_head(head);
  215.     }

  216. }
  217. struct student *insert(struct student *head)
  218. {
  219.     struct student *phead,*p1,*p2,*pinsert;
  220.     p1 = p2 = phead = head;
  221.     pinsert = (struct student *)malloc(sizeof(struct student));
  222.     xxlr(pinsert);
  223.     printf("\n\t\t\t  正在插入中,请稍后......\n");
  224.     while(NULL == phead)
  225.     {
  226.             phead = pinsert;
  227.             pinsert->next = NULL;
  228.             printf("\n\t\t\t  插入成功......\n");
  229.             n++;
  230.             return(head = phead);
  231.     }

  232.     while(pinsert->num > p1->num && p1->next != NULL)
  233.     {
  234.          p2 = p1;
  235.          p1 = p1->next;
  236.     }

  237.     if(pinsert->num <= p1->num)
  238.     {
  239.         if(p1->next == phead->next)
  240.         {
  241.             phead = pinsert;
  242.             pinsert ->next = p2;
  243.             printf("\n\t\t\t  插入成功......\n");
  244.             n++;
  245.             return(head = phead);
  246.         }
  247.         else
  248.         {
  249.             p2->next = pinsert;
  250.             pinsert->next = p1;
  251.             printf("\n\t\t\t  插入成功......\n");
  252.             n++;
  253.             return(head = phead);
  254.         }
  255.     }
  256.     else
  257.     {
  258.             p1->next = pinsert;
  259.             pinsert ->next = NULL;
  260.             printf("\n\t\t\t  插入成功......\n");
  261.             n++;
  262.             return(head = phead);
  263.     }

  264.     return(head=phead);


  265. }
  266. int xzreturn(int max ,int min)//测试无误
  267. {
  268.     int xz;
  269.     char str[256];
  270.         printf("\n\t\t\t  选项:");
  271.     scanf("%s",str);
  272.         xz = atoi(str);//Windows API 函数 atoi 把一个字符串变为整数型返回,如果字符串为数字则返回数字如果为字母符号返回0!
  273.         while(xz > max || xz <= min)
  274.         {
  275.                 printf("\n\t\t\t  错误......");
  276.                 printf("\n\t\t\t  选项:");
  277.                 fflush(stdin);
  278.                 scanf("%s",str);
  279.                 xz = atoi(str);
  280.         }
  281.         return(xz);
  282. }
  283. struct student *xzcz(int xz,struct student *phead)//测试无误
  284. {
  285.     if(1 ==  xz)
  286.     {   if(1 == n)
  287.         {
  288.             phead = del(phead);
  289.         }
  290.         else
  291.         {
  292.             phead = delxz(phead);
  293.         }
  294.     }
  295.     else if(2 == xz)
  296.     {
  297.         phead = insertxz(phead);
  298.     }
  299.     else if(3 == xz)
  300.     {
  301.         if(1 == n)
  302.         {
  303.             print_head(phead);
  304.         }
  305.         else
  306.         {
  307.             print_head_xz(phead);
  308.         }
  309.     }
  310.     else if(4 == xz)
  311.     {

  312.         if(1 == n)
  313.         {
  314.             phead = xg(phead);
  315.         }
  316.         else
  317.         {
  318.             phead = xg_xz(phead);
  319.         }
  320.     }
  321.     else if(5 == xz)
  322.     {
  323.         exit(0);
  324.     }

  325.     return(phead);
  326. }
  327. struct student * xg(struct student *head)
  328. {
  329.     int i = n,num,scanfreturn;
  330.     struct student *p1,*p2;
  331.     p1 = p2 = head;
  332.     if(NULL == p1)
  333.     {
  334.         printf("\n\t\t\t  此为空Link!\n");
  335.         return (head);
  336.     }
  337.     printf("\t\t\t  请输入修改Num:");
  338.     fflush(stdin);
  339.     while(!(scanfreturn = scanf("%d",&num)))
  340.     {
  341.         printf("\t\t\t  对不起!您输入的不合理!请重新输入!\n");
  342.         printf("\t\t\t  请输入修改Num:");
  343.         fflush(stdin);
  344.     }
  345.     while(i--)
  346.     {
  347.         if(p1 ->num != num || p1->next != NULL)
  348.         {
  349.                 p2 = p1;
  350.                 p1 = p1 ->next;
  351.         }
  352.         else
  353.         {
  354.                 continue;
  355.         }
  356.     }
  357.     if(p1 == NULL)
  358.     {
  359.         printf("\t\t\t  没有找到您所输入的学号!");
  360.         return (head);
  361.     }
  362.     else
  363.     {

  364.         printf("\t\t\t  请输入分数:");
  365.         fflush(stdin);
  366.         scanf("%f",&p2->fs);
  367.         while(p2->fs < 0 || p2->fs > 100)
  368.         {
  369.             printf("\t\t\t  对不起!您输入的不合理!请重新输入!\n");
  370.             printf("\t\t\t  请输入分数:");
  371.             fflush(stdin);
  372.             scanf("%f",&p2->fs);
  373.         }
  374.         if( 1 == scanfreturn)
  375.         {
  376.             printf("\t\t\t  修改完成......\n");
  377.             return(head);
  378.         }
  379.         else if(0 == scanfreturn)
  380.         {
  381.             printf("\t\t\t  修改失败......\n\t\t\t  请选择您输入的是否正确!");
  382.             return(head);
  383.         }
  384.     }
  385. }
  386. struct student * xg_xz(struct student *head)
  387. {
  388.     int xz,i;
  389.     printf("\t\t\t  1.单次修改 2.多次修改\n");
  390.     xz = xzreturn(2,0);
  391.     if(1 == xz)
  392.     {
  393.         head = xg(head);
  394.         return(head);
  395.     }
  396.     else if(2 == xz)
  397.     {   printf("\t\t\t  请输入要删除的次数!,最多可以修改%d次\n",n);
  398.         i = xzreturn(n,0);
  399.         while(i--)
  400.         {
  401.          head = xg(head);
  402.         }
  403.         return(head);
  404.     }
  405. }
  406. void xxlr(struct student *p)
  407. {
  408.     int scanfreturn = 0;
  409.     bhlh:
  410.     printf("\n\t\t\t  请输入学号:");
  411.     fflush(stdin);
  412.     scanfreturn = scanf("%d",&p->num);
  413.     if(0 == scanfreturn)
  414.     {
  415.         printf("\t\t\t  对不起!您输入的不合理!请重新输入!\n");
  416.         goto bhlh;
  417.     }
  418.     bhlf:
  419.     printf("\t\t\t  请输入分数:");
  420.     fflush(stdin);
  421.     scanf("%f",&p->fs);
  422.     if(p->fs < 0 || p->fs > 100)
  423.     {
  424.         printf("\t\t\t  对不起!您输入的不合理!请重新输入!\n");
  425.         goto bhlf;
  426.     }
  427. }


复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2012-2-20 23:05:30 | 显示全部楼层
希望大家帮帮忙!再次谢过!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2012-2-20 23:48:37 | 显示全部楼层
硬是没看懂 一开始就是个死循环了??
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-5-28 06:37

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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