鱼C论坛

 找回密码
 立即注册
查看: 1896|回复: 0

学生成绩管理系统

[复制链接]
发表于 2012-3-3 23:40:11 | 显示全部楼层 |阅读模式

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

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

x
  1. /************************************创建一个有n个节点的动态链表***********************************************/

  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<malloc.h>
  5. #include<string.h>

  6. #define LEN sizeof(struct student)

  7. int n;    //    定义n为全局变量

  8. struct student *head;
  9. struct student *creat(void);
  10. int print(struct student *head);
  11. struct student *del(struct student * head);
  12. struct student *Insert(struct student * head);
  13. int searbynum(struct student * head);
  14. int searbyname(struct student *head);
  15. void menu();


  16. struct student
  17. {
  18.       int num;
  19.       int age;
  20.       char sex[20];
  21.       char name[20];
  22.       struct student *next;       
  23.        
  24. };



  25. int main()
  26. {
  27.          
  28.          char choose_1;
  29.          int choose_2;
  30.      
  31.          menu();
  32.          scanf("%c",&choose_1);
  33.          
  34.          
  35.          switch(choose_1)
  36.               {
  37.                          case 'A': {
  38.                                                 creat();
  39.                                                          break;
  40.                                         }
  41.                          
  42.                          case 'B': {
  43.                                                 print(head);
  44.                                                 break;
  45.                                         }
  46.                                  
  47.                          case 'C': {
  48.                                                  del(head);
  49.                                                  printf("The information after delete is :\n");
  50.                                                  print(head);
  51.                                                  break;
  52.                                            }
  53.                                  
  54.                          case 'D': {
  55.                                                 Insert(head);
  56.                                                          printf("The information after delete is :\n");
  57.                                                 print(head);
  58.                                                 break;
  59.                                         }
  60.                                  
  61.                          case 'E': {
  62.                                                 printf("1,search by number .     2,search by name .\n");
  63.                                                 printf("please input your choice !\n");
  64.                                                 scanf("%d",&choose_2);
  65.                                                          switch(choose_2)
  66.                                                                  {
  67.                                                                       case 1 :searbynum(head);break;         
  68.                                                                          case 2 :searbyname(head);break;
  69.                                                                  }
  70.                                                          break;
  71.                                         }
  72.                          
  73.                          case 'F': {
  74.                                                  exit(1);
  75.                                            break;
  76.                                         }
  77.                                  
  78.                          default :{
  79.                                             printf("You input a wrong choose !\n");
  80.                                             break;
  81.                                  
  82.                                          }
  83.                          
  84.                  }
  85.        
  86.         return 0;
  87. }



  88. /*********************************************主菜单函数*****************************************************************/

  89. void menu()
  90. {
  91.           printf("\t\tWelcome to go into our system !\n");
  92.        
  93.       printf("**************************************************************\n*\n*\n");
  94.           printf("*    A : Input information !       B : Output information !  *\n*\n");
  95.           printf("*    C : Delete information!       D : Insert  information ! *\n*\n");
  96.           printf("*    E : Search information!       F :  Exit !               *\n*\n*\n");
  97.           printf("**************************************************************\n\n\n");
  98.        
  99.           printf("please input the operation you choose !");
  100.        
  101. }

  102. /******************************************创建链表*********************************************************/

  103. struct student *creat(void)
  104. {
  105.       int i;
  106.          struct student *p1,*p2;
  107.        
  108.       printf("please input the total number of student :\n");
  109.       scanf("%d",&n);
  110.       
  111.       p1=p2=(struct student *)malloc(LEN);
  112.          
  113.          printf("please input the 1 student's num,age,sex and name :\n");
  114.          scanf("%d,%d,%s,%s",&p1->num,&p1->age,p1->sex,p1->name);
  115.       
  116.       head=NULL;
  117.       i=1;
  118.      
  119.         if(n==1)
  120.               {
  121.                          head=p1;
  122.                          p2=p1;
  123.                  }
  124.        
  125.       else
  126.          do
  127.               {
  128.                          if(i==1)  head=p1;
  129.                          else
  130.                                  p2->next=p1;
  131.                          
  132.                          p2=p1;
  133.                          
  134.                          p1=(struct student *)malloc(LEN);
  135.                           
  136.                           printf("please input the %d student's num,age,sex and name :\n",i+1);
  137.                   scanf("%d,%d,%s,%s",&p1->num,&p1->age,p1->sex,p1->name);
  138.                          
  139.                          i=i+1;
  140.                  }while(i<n);       
  141.       p2->next=NULL;
  142.       return (head);                 
  143.              
  144. }

  145. /*********************************打印链表*********************************************/

  146. int print(struct student *head)
  147. {
  148.       struct student *p;
  149.       printf("\nThere are   %d records!\n\n"  ,n);

  150.       p = head;
  151.       
  152.       
  153.             for(;p!=NULL;p=p->next)
  154.                          printf("%d,%d,%s,%s",p->num,p->age,p->sex,p->name);
  155.       return 0;
  156. }

  157. /***********************************************删除链表中某节点*************************************************************/

  158. struct student *del(struct student *head)
  159. {
  160.          struct student *p1,*p2;
  161.          int number;
  162.        
  163.          p1=head;
  164.        
  165.          if(head==NULL)     
  166.               {
  167.                                  printf("this is a null linklist !");
  168.                                  exit(0);
  169.                  }
  170.        
  171.         else
  172.                  {
  173.                          p1=head;
  174.                          
  175.                          printf("please input the num of the student you want to delete :\n");
  176.                          scanf("%d",&number);
  177.                          
  178.                          while(number!=p1->num&&p1!=NULL)
  179.                               {
  180.                                       p2=p1;
  181.                           p1=p1->next;                                         
  182.                                  }
  183.                         if(p1==NULL)
  184.                      printf("There is no node you want to delete!");                               
  185.                          else
  186.                               {
  187.                                          if(p1==head)
  188.                                                  head=p1->next;
  189.                                          else
  190.                                                  p2->next=p1->next;
  191.                                  }         
  192.        

  193.                         }
  194.                        
  195.          n=n-1;               
  196.                        
  197.         return (head);      
  198. }




  199. /**********************************************插入节点**************************************************************/


  200. struct student *Insert(struct student * head)
  201. {
  202.          struct student *p1,*p2,*p;
  203.          p=NULL;
  204.        
  205.          printf("please input the student's num,age,sex and name you want to insert :\n");
  206.          scanf("%d,%d,%s,%s",&p->num,&p->age,p->sex,p->name);
  207.        
  208.          p1=p2=head;
  209.        
  210.          
  211.          if(NULL==head)    head=p;                 
  212.          else
  213.                  {
  214.                           while (p->num>p1->num&&p1->next!=NULL)
  215.                               {
  216.                                             p1=p2;
  217.                                          p1=p1->next;
  218.                               }
  219.                           
  220.                          if (p->num<=p1->num)
  221.                               {
  222.                                       if(head==p1)         
  223.                                               {
  224.                                                          head=p;
  225.                                                          p->next=p1;
  226.                                                  }
  227.                                       else
  228.                                              {
  229.                                                        p2->next=p;
  230.                                      p->next=p1;                                                       
  231.                                                  }
  232.                                  }                               
  233.                          else
  234.                                {
  235.                                          p1->next=p;
  236.                                          p->next=NULL;
  237.                                   }
  238.                      
  239.                          
  240.                  }
  241.                  
  242.          n=n+1;
  243.                  
  244.                  
  245.          return (head);
  246. }




  247. /**************************************通过学号查找**************************************************************************/


  248. int searbynum(struct student * head)
  249. {
  250.          struct student *p1,*p2,*p;

  251.          p=NULL;  
  252.          printf("please input the number  of the student you want to search :\n");
  253.          scanf("%d",&p->num);
  254.        
  255.          p1=head;
  256.          
  257.        
  258.          if(NULL==p1)  
  259.                  printf("This is a null linklist !");
  260.                  
  261.          else
  262.         {
  263.                  while(p->num!=p1->num&&p1->next!=NULL)
  264.                         {
  265.                               p2=p1;
  266.                      p1=p1->next;                                 
  267.                         }
  268.                  if(NULL==p1->next)
  269.                         {
  270.                                  if(p->num!=p1->num)
  271.                                          printf("There is no student you want to search\n\n !");
  272.                                                
  273.                                  else
  274.                                      {
  275.                                            printf("Searching successful !\n");
  276.                                               printf("%d,%d,%s,%s\n\n\n",p1->num,p1->age,p1->sex,p1->name);
  277.                                         }
  278.                         }
  279.                          
  280.                  else
  281.                           printf("Searching successful !\n");
  282.                           printf("%d,%d,%s,%s\n\n\n",p1->num,p1->age,p1->sex,p1->name);
  283.                           
  284.         }
  285.                  return 0;
  286.                
  287. }




  288. /*********************************************通过姓名查找*****************************************************************/

  289. int searbyname(struct student *head)
  290. {
  291.          struct student *p1,*p2,*p;
  292.          
  293.          p=NULL;
  294.          printf("please input the name of the student you want to search :\n");
  295.          scanf("%s",p->name);
  296.          
  297.          p1=head;
  298.          
  299.        
  300.          if(NULL==p1)
  301.                  printf("This is a null linklist !\n");
  302.                  
  303.         else
  304.                 {
  305.                  while((strcmp(p->name,p1->name)!=0)&&p1->next!=NULL)
  306.                       {
  307.                                   p2=p1;
  308.                                   p1=p1->next;
  309.                          }
  310.                           
  311.               if(NULL==p1->next)
  312.                         {
  313.                               if(strcmp(p->name,p1->name)!=0)
  314.                                          printf("There is no student you want to search !\n");
  315.                                                  
  316.                                  else
  317.                                         {   
  318.                                                  printf("Searching successful !!\n");
  319.                                               printf("%d,%d,%s,%s",p1->num,p1->age,p1->sex,p1->name);
  320.                                         }
  321.                         }
  322.                   else
  323.                         {
  324.                       printf("Searching successful !!\n");
  325.                                printf("%d,%d,%s,%s",p1->num,p1->age,p1->sex,p1->name);
  326.                         }                            
  327.                 }
  328.                
  329.          return 0;
  330. }




  331. /******************************修改学生信息(通过学号查找)*************************************************/

  332. struct student *chabynum(struct student * head)
  333. {
  334.        
  335.       struct student *p1,*p2,*p;
  336.          
  337.          p=NULL;   
  338.          printf("please input the number  of the student you want to change :\n");
  339.          scanf("%d",&p->num);
  340.        
  341.          p1=head;
  342.          
  343.        
  344.          if(NULL==p1)
  345.                  printf("This is a null linklist !");
  346.                  
  347.          else
  348.                  while(p->num!=p1->num&&p1->next!=NULL)
  349.                       {
  350.                               p2=p1;
  351.                      p1=p1->next;                                 
  352.                          }
  353.                  if(NULL==p1->next)
  354.                      {      if(p->num!=p1->num)
  355.                                       printf("There is no student you want to change !\n\n ");
  356.                                          
  357.                                  else
  358.                                      {
  359.                                                  printf("Searching successful !\n");
  360.                                                  printf("please input the %d number student's age :\n",p1->num);
  361.                                                  scanf("%d",&p->age);
  362.                                                  p1->age=p->age;   
  363.                                                  
  364.                                                  printf("please input the %d number student's sex :\n",p1->num);
  365.                                                  scanf("%s",p->sex);
  366.                                                  strcpy(p1->sex,p->sex);
  367.                                                        
  368.                                                  printf("please input the %d number sthdent's name :\n",p1->num);
  369.                                                  scanf("%s",p->name);
  370.                                                  strcpy(p1->name,p->name);
  371.                                
  372.                                          }
  373.                         }
  374.                          
  375.                  else
  376.                            {
  377.                                                  printf("Searching successful !\n");
  378.                                                  printf("please input the %d number student's age :\n",p1->num);
  379.                                                  scanf("%d",&p->age);
  380.                                                  (p1->age)=(p->age);   
  381.                                                  
  382.                                                  printf("please input the %d number student's sex :\n",p1->num);
  383.                                                  scanf("%s",p->sex);
  384.                                                  strcpy(p1->sex,p->sex);
  385.                                                        
  386.                                                  printf("please input the %d number sthdent's name :\n",p1->num);
  387.                                                  scanf("%s",p->name);
  388.                                                  strcpy(p1->name,p->name);
  389.                                        
  390.                                 }
  391.                  
  392.                  return  0;     
  393.        
  394.                  }       

  395. /*************************************修改信息(通过姓名)******************************************/       

  396. struct student *chabyname(struct student *head)

  397. {
  398.          struct student *p1,*p2,*p;
  399.          
  400.          p=NULL;
  401.          printf("please input the name of the student you want to search :\n");
  402.          scanf("%s",p->name);
  403.          
  404.          p1=head;
  405.          
  406.        
  407.          if(NULL==p1)
  408.                  printf("This is a null linklist !\n");
  409.                          
  410.         else
  411.                 {
  412.                          while((strcmp(p->name,p1->name)!=0)&&p1->next!=NULL)
  413.                                  {
  414.                                           p2=p1;
  415.                                           p1=p1->next;
  416.                                  }
  417.                                  
  418.                          if(NULL==p1->next)
  419.                                 {
  420.                                          if(strcmp(p->name,p1->name)!=0)
  421.                                                 printf("There is no student you want to change  !");
  422.                                                          
  423.                                         else
  424.                                                 {   
  425.                                                          printf("Searching successful !\n");
  426.                                                        
  427.                                                          printf("please input the %s student's number :\n",p1->name);
  428.                                                          scanf("%d",&p->num);
  429.                                                          p1->num=p->num ;
  430.                                                          
  431.                                                       printf("please input the %s  student's age :\n",p1->name);
  432.                                                       scanf("%d",&p->age);
  433.                                                       p1->age=p->age;   
  434.                                                  
  435.                                                       printf("please input the %s  student's sex :\n",p1->name);
  436.                                                          scanf("%s",p->sex);
  437.                                                       strcpy(p1->sex,p->sex);
  438.                                                        
  439.                                                  
  440.                                                 }
  441.                                          
  442.                                 }
  443.                           else
  444.                                 {
  445.                                                 printf("Searching successful !\n");
  446.                                                        
  447.                                                          printf("please input the %s student's number :\n",p1->name);
  448.                                                          scanf("%d",&p->num);
  449.                                                          p1->num=p->num;
  450.                                                          
  451.                                                       printf("please input the %s  student's age :\n",p1->name);
  452.                                                       scanf("%d",&p->age);
  453.                                                       p1->age=p->age;   
  454.                                                  
  455.                                                       printf("please input the %s  student's sex :\n",p1->name);
  456.                                                          scanf("%s",p->sex);
  457.                                                       strcpy(p1->sex,p->sex);          
  458.                                 }                            
  459.                 }
  460.                
  461.         return(head);       
  462. }



  463.                  最近自己敲了一个学生成绩管理系统的代码,可是运行的时候总是运行不了,求各位大牛指点迷津
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-4-20 16:11

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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