首页 > 用户发贴区 > 编程问题提问区 > 高人帮忙调试一下!
2008
03-05

高人帮忙调试一下!

这是小弟的”学生成绩管理系统”有很大问题,高人帮忙调试一下!


代码如下:(有点臃肿)


先谢了!!!


高人帮忙调试一下!》有 11 条评论

  1. wfnh 说:

    #include <stdio.h>
    #include<stdlib.h>
    #include<time.h>
    #include<math.h>
    #include<ctype.h>
    #include <conio.h>
    #define STR struct student
    #define LEN sizeof(struct student)
    #define TURE 1
    #define FALSE 0
    STR * addnew(STR * head);/* 添加学生信息 */
    STR * upgrade_meun(STR * head);/* 修改学生信息界面  */
    STR * chioc_project(STR * head,char key);/* 修改项目  */
    void upgrade(STR * cur,char key);/* 修改学生信息  */
    STR * del_meun(STR * head);/* 删除界面  */
    STR * del(STR * head,char key);/* 删除学生信息 */
    STR * search_meun(STR * head);/* 查询个人信息 */
    void search(STR * head,char key);/* 查询 */
    void show_all_info(STR * head);/* 显示全部学生信息 */
    int help();/* 帮助 */
    /* —————全局变量———– */
    STR
    {char num[11];
    char name[21];
    char sex;
    char class[4];
    float scores[3];
    float aver;
    STR *next;
    }stu;
    /* ———————————- */
    int main(void)
    {
        struct student *phead=NULL;
        time_t start,end;
        char chioc;
        do
        {
           system(“cls”);/*  清除文本模式窗口  */
           printf(“\t******************************************************\n”);
           printf(“\t\t\t欢迎使用学生信息管理系统\t\t\t\n”);
           printf(“\t******************************************************\n”);
           printf(“1.添加学生信息\n”);
           printf(“2.修改学生信息\n”);
           printf(“3.删除学生信息\n” );
           printf(“4.查询学生信息\n”);
           printf(“5.显示全部学生信息\n”);
           printf(“6.帮助\n”);
           printf(“7.退出系统\n”);
           printf(“请选择操作:”);
           chioc=getche();
           switch(chioc)
           {
                     case ’1′:phead=addnew(phead);break;;/* 输入学生个人信息 */
                     case ’2′:phead=upgrade_meun(phead);break;/* 修改个人信息界面  */
                     case ’3′:phead=del_meun(phead);break;/* 删除个人信息 */
                     case ’4′:search_meun(phead);break;/* 查询界面 */
                     case ’5′:show_all_info(phead);break;/* 显示全部学生信息 */
                     case ’6′:help();
                     case ’7′:exit(0);
                     default:
                            start=time(NULL);
                            end=time(NULL);
                            printf(“\n没有该选项,请重新选择!”);
                            while(end-start<2)
                                              end=time(NULL);
                           
           }
        }while(1);
        getch();
    }

  2. wfnh 说:

    /* ——————添加模块 —————- */
    STR * addnew(STR * head)
    {
        STR * ppre=NULL;
        STR * pafter=NULL;
        STR * new_node=NULL;
        char flag;
        int n,count=0;/* as counter */
        float sum=0;
        time_t start,end;
        ppre=pafter=head;
        do
        {
                         system(“cls”);
                         printf(“\t******************************************************\n”);
                         printf(“\t\t\t添加学生信息\t\t\t\n”);
                         printf(“\t******************************************************\n”);
                         printf(“提示:学号为0,则返回 \n\n\n”);
                         new_node=(STR*)malloc(LEN);
                         if(new_node==NULL)
                         {
                                           printf(“分配内存错误!”);
                                           exit(0);
                         }
                         printf(“请输入:\n”);
                         printf(“学号:”);
                         scanf(“%10s”,new_node->num);/* 取前10位 */
                         if(strcmp(new_node->num,”0″)!=0)
                         {
                                                     printf(“姓名:”);
                                                     scanf(“%20s”,new_node->name);
                                                     for(;;)
                                                     {
                                                            printf(“性别:”);
                                                            scanf(” %1c”,&new_node->sex);
                                                            new_node->sex=toupper(new_node->sex);/* 将sex转换为大写 */
                                                            if((new_node->sex!=’F')&&(new_node->sex!=’M'))
                                                                                                                       printf(“性别只能是F(女)或M(男)\n”);
                                                            else
                                                                break;
                                                     }
                                                     printf(“班别:”);
                                                     scanf(“%3s”,new_node->class);
                                                     /* —–以下为三科成绩– */
                                                     n=0;
                                                     do
                                                     {
                                                                           
                                                                            do
                                                                            {
                                                                                  if(n==0)printf(“语文:”);
                                                                                  else if(n==1)printf(“数学:”);
                                                                                  else
                                                                                  printf(“英语:”);
                                                                                  scanf(“%f”,&new_node->scores[n]);
                                                                                  if(fabs(new_node->scores[n])>100)
                                                                                                         printf(“最高分为100,请重新输入!\n”);
                                                                                  else break;
                                                                            }while(1);
                                                                            n++;
                                                     }while(n<3);
                                                     /* 算平均分 */
                                                     sum=0;
                                                     for(n=0;n<3;n++)
                                                                     sum+=new_node->scores[n];
                                                     new_node->aver=sum/n;
                                                     /* 插入排序 */
                                                     if(head==NULL)
                                                     {
                                                                   head=new_node;
                                                                   new_node->next=NULL;
                                                     }
                                                     else
                                                     {
                                                         while((strcmp(new_node->num,pafter->num)>0)&&(pafter->next!=NULL))
                                                         {
                                                                                                                          ppre=pafter;
                                                                                                                          pafter=pafter->next;
                                                         }
                                                         if(strcmp(new_node->num,pafter->num)<0)
                                                         {
                                                                                                if(head==pafter)
                                                                                                                head=new_node;
                                                                                                else
                                                                                                    ppre->next=new_node;
                                                         }
                                                         else
                                                         {
                                                             pafter->next=new_node;
                                                             new_node->next=NULL;
                                                         }
                                                     }
                                                     count++;
                         }
                         else
                         {   if(count>0)
                             {
                                        start=time(NULL);
                                        end=time(NULL);
                            
                                        printf(“全部添加成功,程序将返回主界面”);
                                        while(end-start<4)
                                        {
                                               
                                                end=time(NULL);
                                        }
                                        free(new_node);
                                        break;
                             }
                                
                            
                         }
                         if(count==0)
                         {
                                     printf(“此次操作没有输入任何数据,确定返回请按Y/y,否则重新输入!(Y/y)”);
                                     scanf(” %c”,&flag);
                                     if((flag==’Y')||(flag==’y'))
                                                                 break;
                         }
        }while(1);
    }

  3. wfnh 说:

    /* ——————————————————————————— */
    /* ————————–删除模块 ———————————————- */
    STR * del_meun(STR * head)
    {
        char chioc;
        time_t start,end;
        do
        {
            system(“cls”);
            printf(“\t******************************************************\n”);
            printf(“\t\t\t删除学生信息\t\t\t\n”);
            printf(“\t******************************************************\n”);
            printf(“删除方式:\n”);
            printf(“1.按学号\n”);
            printf(“2.按姓名\n”);
            printf(“3.返回\n”);
            printf(“请选择:”);
            chioc=getche();
            if(chioc==’3′)
                break;
            switch(chioc)
            {
                case ’1′:
                case ’2′:head=del(head,chioc);break;
                default:
                    start=time(NULL);
                    end=time(NULL);
                    while(end-start<4)
                    {
                        printf(“\r没有该选项,请重新选择!”);
                        end=time(NULL);
                    }
                    break;
            }
        }while(1);
        return(head);
    }
    STR * del(STR * head,char key)
    {
        char sure;
        char num[11];
        char name[21];
        STR *ppre=NULL,*pafter=NULL;
        if(head==NULL)
        {
            printf(“数据库为空”);
            getch();
        }
        else
        {
            do
            {
                if(key==’1′)
                {
                    printf(“请输入学号:”);
                    scanf(“%10s”,num);
                    if(strcmp(num,”0″)!=0)
                    {     
                        do    
                        {                 
                            printf(“确定要删除吗?(Y/N)”);
                            sure=getche();
                            if((sure==’Y')||(sure==’y'))
                            {         
                                if(strcmp(num,head->num)==0)
                                    head=head->next;
                                else
                                {            
                                    ppre=head;
                                    pafter=head->next;
                       
                                    while(pafter!=NULL)
                                    {         
                                        if(strcmp(num,pafter->num)==0)
                                        {
                                            ppre->next=pafter->next;
                                            break;
                                        }
                                        else                   
                                            ppre=pafter;
                                        pafter=pafter->next;
                                    }
           if(pafter==NULL)
            printf(“没有该学生\n”);
           else
            printf(“已删除\n”);
           break;
           }
                               
          }
         

                            else
                            {
                                if((sure==’N')||(sure==’n'))
                                break;
                            else
                                printf(“没有该选项\n”);
                            }
                        }while(1);
                            if((sure==’N')||(sure==’n'))
                                break;
                    }/* compare “0″ */
                    else
                        break;
                }/* #if */
        else
        {
            printf(“请输入姓名:”);
            scanf(“%21s”,name);
            if(strcmp(name,”0″)!=0)
            {
                do
                {
                    printf(“确定要删除吗?(Y/N)”);
                    sure=getche();
                    if((sure==’Y')||(sure==’y'))
                    {
                        if(strcmp(name,head->name)==0)
                            head=head->next;
                        else
                        {
                            ppre=head;
                            pafter=head->next;
                       
                        while(pafter!=NULL)
                        {
                            if(strcmp(name,pafter->name)==0)
                            {
                                ppre->next=pafter->next;
                                break;
                            }
                            else
                                ppre=pafter;
                            pafter=pafter->next;
                        }
                        if(pafter==NULL)
                            printf(“没有该学生\n”);
                        else
                            printf(“已删除\n”);
                        break;
                        }
                    }
                    else
                    {
                        if((sure==’N')||(sure==’n'))
                            break;
                        else
                            printf(“没有该选项\n”);
                    }
                }while(1);
                if((sure==’N')||(sure==’n'))
                    break;
            }/* compare “0″ */
            else
                break;
        }/* #else if */
       
        }while(1);
        }
        return(head);
    }

  4. wfnh 说:

    void show_all_info(STR * head)
    {
        system(“cls”);
        struct student *pafter=NULL;
        pafter=head;
        if(head!=NULL)
        {
                      printf(“全部学生信息如下:\n”);
                      printf(“学号\t姓名\t性别\t班别\t语文\t数学\t英语\t平均分\n”);
                      do
                      {  
           
                          printf(“%s\t%s\t%c\t%s\t%.1f%.1f%.1f%.1f\n”,pafter->num,pafter->name,pafter->sex,pafter->class,pafter->scores[0],pafter->scores[1],pafter->scores[2]);
                          pafter=pafter->next;
                      }while(pafter!=NULL);
        }
        else
        {
             printf(“数据库为空\n”);
             system(“pause”);
        }
    }                                                                              
    int help()
    {
         system(“cls”);
         printf(“个人预览版本!\n”);
         system(“pause”);
         return 0;
    }                                     
                      

  5. younger 说:

    你应该先估计错误位置,再发上来。

    其次你的程序的确有些累赘,我以前写的也只有500+行。

  6. wfnh 说:

    每人 吗 ?

     

  7. xstar 说:

    问题都没提出来怎么解答啊!

  8. wfnh 说:

    我的 问题是 第二次输入英语的 时候就 不能 下去 了 ,死了!!!

  9. 独孤傲天 说:

    为什么死啊,呵呵,谁没事给你读那么长的东西啊?

留下一个回复