| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1023 人关注过本帖
标题:数据结构课程设计本科生导师制,求大神帮忙
只看楼主 加入收藏
haky
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2014-6-19
收藏
 问题点数:0 回复次数:1 
数据结构课程设计本科生导师制,求大神帮忙
这是一个同学的,但是有错误(vc++6.0),求大神看看

#include<iostream>
void menu()
{
    printf("*********************************************************************\n");
    printf("1.%35s\n","建立广义表");
    printf("2.%35s\n","插入学生");
    printf("3.%35s\n","删除学生");
    printf("4.%35s\n","查询信息");
    printf("5.%35s\n","统计导师的研究生,本科生人数");
    printf("6.%35s\n","输出广义表");
    printf("7.%35s\n","退出");
    printf("*********************************************************************\n");
}

int main(int argc,char *argv[])
{
    typedef *head;
    char str[100];
    int choice;
    while(1)
    {
        menu();
        printf("请输入你要选择的序号:\n");
        scanf("%d",&choice);
        switch(choice)
        {
            case 1:{
            printf("请输入你想建立的标准广义表,例如:((高老师-教授-0,(李平-一班-2,杨梅-二班-2)),(李平-博士-0,(李平-三班-1,(李平-四班-2))))\n");
            scanf("%s",str);
            head=glistcreate(str);
            }
            break;
            case 2:head=studentinsert(head);
                break;
            case 3:head=studentdelete(head);
                break;
            case 4:enquire(head);
                break;
            case 5:studentcount(head);
                break;
            case 6:glistprint(head);
            break;
            case 7:return 0;
        }
    }   
    return 0;
}
glist *glistcreate(char *str)
{
    glist *head,*p,*q,*m,*a;
    int i=0,j=0,flag=0,flag1=0,flag2=0,len=strlen(str);
    head=p=q=m=a=NULL;
    while(i<len)
    {
        if(str[i]==')'||str[i]=='('||str[i]==',')
        {
            i++;
            continue;
        }
        else
        {
            if(!(m=(glist *)malloc(sizeof(glist))))
            exit(1);
            for(j=0;str[i]!='-';)
            m->name[j++]=str[i++];
            m->name[j]='\0';
            for(j=0,++i;str[i]!='-';)
            m->prof[j++]=str[i++];
            m->prof[j]='\0';
            m->type=str[++i]-48;
            m->ptr.hp=m->ptr.tp=NULL;
            i++;
            if(m->type==0)
            {
                if(flag)
                {
                    p->ptr.hp=m;
                    p=m;
                }
                else{
                    head=p=m;
                    flag=1;
                }
                flag1=0;
                a=q=m;
            }
            else if(m->type==1)
            {
                if(flag1)
                {
                    q->ptr.hp=m;
                    q=m;
                }
                else{
                    q->ptr.tp=m;
                    q=m;
                    flag1=1;
                }
                flag2=0;
                a=m;
            }
            else{
                if(flag2)
                {
                    a->ptr.hp=m;
                    a=m;
                }
                else{
                    a->ptr.tp=m;
                    a=m;
                    flag2=1;
                }
            }
        }
    }
    return head;
}
void glistprint(glist *head)
{
    glist *p,*q,*a;
    int flag=0,flag1=0,flag2=0;
    p=head;
    printf("(");
    while(1)
    {
        if(p==NULL) break;
        if(flag)
            printf(",(%s-%s-%d",p->name,p->prof,p->type);
        else
        {
            printf("(%s-%s-%d",p->name,p->prof,p->type);
            flag=1;
        }
        q=p->ptr.tp;
        flag2=flag1=0;
        while (1)
        {
            if(q==NULL)break;
            if(flag1)
                if(q->type==1)
                    printf(",(%s-%s-%d",q->name,q->prof,q->type);
                else
                    printf(",%s-%s-%d",q->name,q->prof,q->type);
            else
            {
                printf(",(%s-%s-%d",q->name,q->prof,q->type);
                flag1=1;
            }
            a=q->ptr.tp;
            flag2=0;
            while(1)
            {
                if(a==NULL)break;
                if(flag2)
                    printf(",%s-%s-%d",a->name,a->prof,a->type);
                else
                {
                    printf(",(%s-%s-%d",a->name,a->prof,a->type);
                    flag2=1;
                }
                a=a->ptr.hp;
            }
            if(flag2)printf(")");
            if(q->type==1||(q->ptr.hp==NULL))
                printf(")");
            q=q->ptr.hp;
        }
        printf(")");
        p=p->ptr.hp;
    }
    printf(")\n");
}
glist *studentinsert(glist *head)
{
    char slen[100],teacher[100],graduate[100];
    glist *Slen,*p,*q;
    int i,j;
    p=head;
    printf("请输入待插入学生的信息,如:李刚-二班-1\n");
    scanf("%s",slen);
    if(!(Slen=(glist *)malloc(sizeof(glist))))
        exit(1);
    for(i=0,j=0;slen[i]!='-';)
        Slen->name[j++]=slen[i++];
    Slen->name[j]='\0';
    for(j=0,++i;slen[i]!='-';)
        Slen->prof[j++]=slen[i++];
    Slen->prof[j]='\0';
    Slen->type=slen[++i]-48;
    Slen->ptr.hp=Slen->ptr.tp=NULL;
    if(Slen->type==2)
    {
        printf("请输入所属导师\n");
        scanf("%s",teacher);
        while(strcmp(p->name,teacher))
        {
            p=p->ptr.hp;
            if(p==NULL)break;
        }
        if(p==NULL)
            printf("不存在此导师\n") ;
        else
        {
            if(p->ptr.hp==NULL||p->ptr.tp->type==2)
            {
                Slen->ptr.hp=p->ptr.tp;
                p->ptr.tp=Slen;
                printf("插入成功\n");
            }
            else
            {
                printf("请输入所属研究生\n");
                scanf("%s",graduate);
                q=q->ptr.tp;
                while(strcmp(q->name,graduate))
                {
                    q=q->ptr.hp;
                    if(q==NULL)break;
                }
            
            }
            if(q==NULL)
                printf("该研究生不存在,不能插入\n");
            else
            {
                Slen->ptr.hp=q->ptr.tp;
                q->ptr.tp=Slen;
                printf("插入成功\n");
            }
        }
    }

else
{
    printf(" 请输入所属导师:\n");
    scanf("%s",teacher);
    while(strcmp(p->name,teacher))
    {
        p=p->ptr.hp;
        if(p==NULL)
        break;
    }
    if(p==NULL)
        printf("不存在此导师\n");
    else{
        if(p->ptr.tp==NULL||p->ptr.tp->type==1)
        {
            Slen->ptr.hp=p->ptr.tp;
            p->ptr.tp=Slen;
            printf("插入成功\n");
        }
        else
        {
            Slen->ptr.tp=p->ptr.tp;
            p->ptr.tp=Slen;
        }
        }
}
printf("\n");
return head;
}
glist *studentdelete(glist *head)
{
    char slen[100];
    glist *Slen,*p,*q,*a,*m;
    int i,j;
    int flag=0;
    char ch;
    p=head;
    printf("请输入待删除学生信息,如李刚-二班-1 \n");
    scanf("%s",slen);
    if(!(Slen=(glist *)malloc(sizeof(glist))))
        exit(1);
    for(i=0,j=0;slen[i]!='-';)
    Slen->name[j++]=slen[i++];
    Slen->name[j]='\0';
    for(j=0,++i;slen[i]!='-';)
        Slen->prof[j++]=slen[i++];
    Slen->prof [j]='\0';
    Slen->type=slen[++i]-48;
    if(Slen->type==2)
    {
        while(p!=NULL&&flag==0)
        {
            if(!strcmp(q->name,Slen->name)&&!strcmp(p->prof,Slen->prof))
            {
                printf("\n是否要删除这名本科学生:");
            printf("学生:%6s %6s,导师:%6s %6s\n",Slen->name,Slen->prof,p->name,p->prof);
            printf("y删除,n不删除\n");
            scanf("%c",&ch);
            if(ch=='y'||ch=='Y')
            {
                if(p->ptr.tp==q)
                    p->ptr.tp=q->ptr.hp;
                else
                    m->ptr.hp=q->ptr.hp;
                free(p);
                printf("删除成功\n");
            }
            flag=1;
            }
            else
            {
                m=q;
                q=q->ptr.hp;
            }
        }
        
        
    }
   

else if(q->type==1)
while (q!=NULL&&flag==0)
{
    a=q->ptr.tp;
    m=a;
    while(a!=NULL&&flag==0)
    {
        if(!strcmp(a->name,Slen->name)&&strcmp(a->prof,Slen->prof))
        {
            printf("是否要删除这名学生:\n");
            printf("学生:%6s %6s\n",Slen->name,Slen->prof);
            printf("导师:%6s %6s\n",p->name,p->prof);
            printf("研究生:%6s %6s\n",q->name,q->prof);
            printf("y删除,n不删除\n");
        
            scanf("%c",&ch);
            if(ch=='y'||ch=='Y')
            {
                if(q->ptr.tp==a)
                    q->ptr.tp=a->ptr.hp;
                else
                     m->ptr.hp=a->ptr.hp;
             free(p);
             printf("删除成功\n");
            }
            flag=1;
        }
        else{
            m=a;
            a=a->ptr.hp;
        }
    }
    q=q->ptr.hp;
}

else
{
    while(p!=NULL&&flag==0)
    {
        q=p->ptr.tp;
        m=q;
        while(q!=NULL&&flag==0)
        {
            if(!strcmp(q->name,Slen->name)&&strcmp(q->prof,Slen->prof))
            if(q->ptr.tp!=NULL)
            {
                printf("研究生下面有本科生,如果想删除,需先把本科生移动到其他的研究生组才可以!\n");
                flag=1;
            }
            else{
                printf("是否要删除这名研究生:\n");
                printf("研究生:%6s %6s,导师:%6s %6s\n",Slen->name,Slen->prof,p->name,p->prof);
                printf("y删除,n不删除\n");
                getchar();
                scanf("%c",&ch);
                if(ch=='y'||ch=='Y')
                {
                    if(p->ptr.tp==q)
                        p->ptr.tp=q->ptr.hp;
                    else
                    m->ptr.hp=q->ptr.hp;
                    free(q);
                    printf("删除成功!\n");
                }
                flag=1;
            }
            else{
                m=q;
                q=q->ptr.hp;
            }
        }
        p=p->ptr.hp;
    }
}
if(!flag)
    printf("查无此人\n");
printf("\n");
return head;
}
void enquire(glist *head)
{
    char slen[100];
    glist *p,*q,*m,*a;
    int flag=0;
    p=head;
    printf("\n请输入待查询人员信息,如:李刚\n");
    scanf("%s",slen);
    while(p!=NULL)
    {
        q=p->ptr.tp;
        if(!strcmp(p->name,slen))
        {
            flag=1;
            printf("\n本人信息:姓名:%s职称:%s类型:导师\n",p->name,p->prof);
        }
        if(q->type==2)
        {
            a=q;
            while(a!=NULL)
            {
                if(!strcmp(a->name,slen))
                {
                    printf("\n本人信息:姓名:%s班级:%s类型:本科生\n",p->name,p->prof);
                    printf("导师信息:姓名:%s职称:%s\n",p->name,p->prof);
                    flag=1;
                }
                m=a;
                a=a->ptr.hp;
            }   
        }
        else
        {
            while(q!=NULL)
            {
                m=q;
                a=a->ptr.tp;
                if(!strcmp(q->name,slen))
                {
                    printf("\n本人信息:姓名:%s班级:%s类型:研究生\n",p->name,p->prof);
                    printf("导师信息:姓名:%s职称:%s\n",p->name,p->prof);
                    flag=1;
                }
                while(a!=NULL)
                 {
                     if(!strcmp(a->name,slen))
                     {
                     printf("\n本人信息:姓名:%s班级:%s类型:本科生\n",p->name,p->prof);
                    printf("导师信息:姓名:%s职称:%s\n",p->name,p->prof);
                    printf("\n研究生信息:姓名:%s班级:%s\n",p->name,p->prof);
                    flag=1;
                     }
                     m=a;
                     a=a->ptr.hp;
                 }
                 q=q->ptr.hp;
            }
        }
        p=p->ptr.hp;
    }
    if(!flag)
        printf("查无此人\n");
    printf("\n");
}
void studentcount(glist *head)
{
    char teacher[100];
    glist *p,*q,*a;
    int gra=0,ugra=0;
    p=head;
    printf("请输入教师信息\n");
    scanf("%s",teacher);
    while(strcmp(p->name,teacher))
    {
        p=p->ptr.hp;
        if(p==NULL)
            break;
    }
    if(p==NULL)
        printf("不存在该导师\n");
    else
    {
        q=p->ptr.tp;
        while(q!=NULL)
        {
            gra++;
            a=q->ptr.tp;
            while(a!=NULL)
            {
                ugra++;
                a=a->ptr.hp;
            }
        q=q->ptr.hp;
        }
        if(p->ptr.tp->type==1)
        {
            printf("研究生人数:%d\n",gra);
            printf("本科生人数%d\n",ugra);
        }
        else
            printf("本科生人数%d\n",ugra);
    }
    printf("\n");
    system("pause");
}
搜索更多相关主题的帖子: include 研究生 本科生 课程 统计 
2014-06-19 20:12
haky
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2014-6-19
收藏
得分:0 
如果这个不对,给出其他代码也好
2014-06-19 20:13
快速回复:数据结构课程设计本科生导师制,求大神帮忙
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.048330 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved