当前位置导航:炫浪网>>网络学院>>编程开发>>C++教程>>C++进阶与实例

一个简单的学生成绩管理程序

    #include<stdlib.h>
    #include<stdio.h>
    struct list{
       int num;
       char name[256];
       int china;
       int english;
       int math;
       struct list *next;
    };
    typedef struct list node;
    typedef node *link;
    printf_list(link head)
    {
      link pointer;
      pointer=head;
      while(pointer!=NULL)
      {
       printf("number:%d\n",pointer->num);
       printf("name:%s\n",pointer->name);
       printf("china:%d\n",pointer->china);
       printf("english:%d\n",pointer->english);
       printf("math:%d\n",pointer->math);
       pointer=pointer->next;
      }
      }
    link creat_list(link head)
    {
       int cnum;
       char cname[256];
       int cchina;
       int cenglish;
       int cmath;
       link pointer,new;
       int i;
       head=(link)malloc(sizeof(node));
       if(head==NULL)
         { printf("memory allocate failure!!\n");
           exit(0);}
       else{
         printf("please input number:");
         scanf("%d",&cnum);
         printf("please input name:");
         scanf("%s",&cname);
         printf("please input china:");
         scanf("%d",&cchina);
         printf("please input english:");
         scanf("%d",&cenglish);
         printf("please input math:");
         scanf("%d",&cmath);
         head->num=cnum;
         for(i=0;i<256;i++)
         {
         head->name[i]=cname[i];
          }
         head->china=cchina;
         head->english=cenglish;
         head->math=cmath;
         head->next=NULL;
         pointer=head;
       while(1)
       {
         new=(link)malloc(sizeof(node));
         if(new==NULL){
          printf("memory allocate failure!!\n");
          exit(0);}
          printf("please input number:");
          scanf("%d",&cnum);
           if(cnum==0){
    break;    }
          printf("please input name:");
          scanf("%s",cname);
          printf("please input china:");
          scanf("%d",&cchina);
          printf("please input english:");
          scanf("%d",&cenglish);
          printf("please input math:");
          scanf("%d",&cmath);
          new->num=cnum;
          for(i=0;i<256;i++){
          new->name[i]=cname[i];}
          new->china=cchina;
          new->english=cenglish;
          new->math=cmath;
          new->next=NULL;
          pointer->next=new;
          pointer=new;
          }
          }
          return head;
    }
    search_chengji(int key1,link head)
    {
       link pointer;
       pointer=head;
       while(pointer!=NULL)
       {
        if(pointer->num==key1)
        {
        printf("number:%d\n",pointer->num);
        printf("name:%s\n",pointer->name);
        printf("china:%d\n",pointer->china);
        printf("english:%d\n",pointer->english);
        printf("math:%d\n",pointer->math);
        }
        pointer=pointer->next;
       }
    }
    link modify_chengji(link head,int key3)
    {

        link pointer;
        char xname[256];
        int xchina;
        int xenglish;
        int xmath;
        int choose,i;
        pointer=head;
        printf("enter 0 exit modefiy\n");
        printf("enter 1 modefiy name\n");
        printf("enter 2 modefiy china\n");
        printf("enter 3 modefiy english\n");
        printf("enter 4 modefiy math\n");
        scanf("%d",&choose);
        switch(choose)
      {
      case 1:
        printf("please input name:");
        scanf("%s",&xname);
        break;
      case 2:
        printf("please input china:");
        scanf("%d",&xchina);
        break;
      case 3:
        printf("please input english:");
        scanf("%d",&xenglish);
        break;
      case 4:
        printf("please input math:");
        scanf("%d",&xmath);
        break;
      }
      while(1){
        pointer=pointer->next;
        if(pointer->num==key3)
           {
           if(choose==1)
           { for(i=0;i<256;i++)
           {
    pointer->name[i]=xname[i];
    }
    break;
    }
           else if(choose==2)
           { pointer->china=xchina;
           break;}
           else if(choose==3)
           { pointer->english=xenglish;
          break;
          }
           else if(choose==4)
    {pointer->math=xmath;
      break;}
           }
           }
        return head;
    }
 

共2页 首页 上一页 1 2 下一页 尾页 跳转到
相关内容
赞助商链接