| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 721 人关注过本帖
标题:求大神帮小弟解决!!
只看楼主 加入收藏
imlyi
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-6-2
结帖率:0
收藏
已结贴  问题点数:20 回复次数:10 
求大神帮小弟解决!!
设学生信息中包括学号、姓名、性别及三门课成绩。编写程序或函数完成下列功能:
①输入若干学生的数据,并且保存在数组中,直到学号为0为止。
②输出学生信息(包括学生学号,姓名,性别,三门课成绩及总分)。
③试找出总分最高者的姓名及总分,并统计出全体学生的总人数。
④设一个班的学生信息分别放在两个结构体数组中,试写一函数,将这两个班学生信息合并到一个数组中(按学号顺序合并)
⑤设一个班的学生信息已经按照学号排好序,并且存放在一个结构体数组中,试写一函数,将某个同学插入到适当位置。
⑥设一个班的学生信息已经按照学号排好序,并且存放在一个结构体数组中试写一函数,将某个退学的同学删除。
按照题目要求写就可以,最后两个小题用链表。
  

要用C语言写!
小弟刚学这东西,不会!希望哪个大哥大姐帮点忙,教一下小弟!
谢谢啊!!!!
搜索更多相关主题的帖子: 结构体 姓名 同学 三门 
2011-06-02 18:01
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:3 
这个要别人写不太现实,还是自己来吧!

   唯实惟新 至诚致志
2011-06-02 20:09
夜叶
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:104
专家分:189
注 册:2011-5-7
收藏
得分:3 
应该独立完成
2011-06-02 20:24
oszc
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:111
专家分:154
注 册:2011-4-15
收藏
得分:3 
小弟,期末了,加油
2011-06-02 20:29
tudou2xigua
Rank: 2
等 级:论坛游民
帖 子:87
专家分:54
注 册:2011-3-20
收藏
得分:3 
自己写才能提高!一个个函数写
2011-06-02 22:40
waterstar
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:5
帖 子:984
专家分:2810
注 册:2010-2-12
收藏
得分:3 
仔细想想,这种题不难,就是有点烦而已,楼主不要被题目唬住了。


冰冻三尺,非一日之寒;士别三日,不足刮目相看!
2011-06-02 23:21
imlyi
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-6-2
收藏
得分:0 
回复 2楼 qq1023569223
搞定了,但是不知道哪错了,能帮我看看吗?
# include <stdio.h>
# include <malloc.h>
# define NULLL 0
# define LEN sizeof(struct student)

struct sco
{
float A;
float B;
float C;
}score;
struct student
{
    long num;
    char name[20];
    char sex;
    struct sco score;
    struct student * next;
};
int n;                                 /*n为全局变量,本文件模块中各函数均可使用它*/


struct student *creat(void)            /*定义函数,此函数带回一个指向链表头的指针*/
{
    struct student * head;
    struct student *p1,*p2;
    n=0;
    p1=p2=(struct student *) malloc(LEN);/*开辟一个新单元*/
    scanf("%ld,%s,%c,%f,%f,%f",&p1->num,&p1->name,&p1->sex,&(*p1).score.A,&(*p1).score.B,&(*p1).score.C);
    head=NULLL;
    while(p1->num!=0)
    {
        n=n+1;
        if(n==1) head=p1;
        else p2=p1;
        p1=(struct student *) malloc(LEN);
  scanf("%ld,%s,%c,%f,%f,%f",&p1->num,&p1->name,&p1->sex,&(*p1).score.A,&(*p1).score.B,&(*p1).score.C);
    }
    p2->next=NULLL;
    return(head);
}
void print(struct student *head)  /*输出链表的函数*/
{
    float z;
    struct student *p;
    printf("\n学生总人数是:%d\n",n);
    printf("NO.         Name           sex    A    B    C   Z\n");
    p=head;
    if(head!=NULLL)
        do
        {  z=(*p).score.A+(*p).score.B+(*p).score.C;
            printf("%ld%s%c%4.1f%4.1f%.1f%4.1f\n",p->num,p->name,p->sex,(*p).score.A,(*p).score.B,(*p).score.C,z);
        p=p->next;
        }while(p!=NULLL);
}

void highest(struct student *head)     /*找出总分最高的学生和学生总人数的函数*/
{
    float z1,z2;
    struct student *p;
    p=head;
    for(;head->num!=0;)
    {
    z1=(*p).score.A+(*p).score.B+(*p).score.C;
    z2=(*head).score.A+(*head).score.B+(*head).score.C;
    if(z1<=z2)  p=head;
    head=head->next;
    }
    printf("\n总分最高的学生叫:%s\n总分为:%4.1f\n学生总人数为:\n",p->name,z1,n);
}

struct student *hebing(struct student *m1,struct student *m2)    /*合并学生的函数*/
{  
    struct student * head,*p1,*p2;
    head=m1;
    for(;m2->num!=0;)
     {
        p2=m2->next;
        m1=head;
        for(;m1->num!=0;)
        {
            p1=m1->next;
            if(m2->num<=m1->num)
              {     m2->next=head;
                 head=m2;
               }
            if(m1->num<m2->num&&m2->num<=p1->num)
               {
                m1->next=m2; m2->next=p1;
               }
            if(m1->num<m2->num&&p1->num==0)
               {
                m1->next=m2;
                m2->next=NULLL;
               }
            m1++;
        }  
m2=p2;
        }
    return(head);
}
   
struct student *del(struct student *head,long num)   /*删除学生的函数*/
{
    struct student *p1,*p2;
    if(head==NULLL)  { printf("\n链表是空的!!\n");return head;}
    p1=head;
    while(num!=p1->num&&p1->next!=NULLL)
    {p2=p1;p1=p1->next;}
    if(num==p1->num)
    {if(p1==head) head=p1->next;     /*找到的是首节点,把第二个节点地址赋给head*/
    else p2->next=p1->next;
    printf("删除;%ld\n",num);
    n=n-1;;
    }
    else printf("%ld 没有找到!\n",num); /*找不到该结点*/
    return(head);
}


struct student * insert(struct student * head,struct student *stu)  /*插入学生的函数*/
{struct student *p0,*p1,*p2;
p1=head;
p0=stu;
if(head==NULLL)
{head=p0;p0->next=NULLL;}
else
{
    while((p0->num>p1->num)&&(p1->next!=NULLL))
    {p2=p1;
    p1=p1->next;}
    if(p0->num<=p1->num)
    {if(head==p1) head=p0;
    else p2->next=p0;
    p0->next=p1;}
    else
    {p1->next=p0;p0->next=NULLL;}
}
n=n+1;
return(head);
}




void main()
{
    char a;
    struct student * head_1,*head_2,stu;
    long del_num;
    printf("请输入学生信息:\n");
    head_1=creat();
    printf("\n输入完成,是否输出学生信息? Y or N? ");
    scanf("%c",&a);
    if(a=='Y'||a=='y')  print(head_1);
    printf("是否找出总分最高的学生信息? Y or N ? ");
    scanf("%c",&a);
    if(a=='Y'||a=='y')  highest(head_1);
    printf("\n是否输入另一组学生信息,并与前一组合并? Y or N ?  ");
    scanf("%c",&a);
    if(a=='Y'||a=='y')
      { printf("\n请输入学生信息:\n");
        head_2=creat();
        head_1=hebing(head_1,head_2);
        printf("\n合并完成,是否输出合并后信息? Y or N?");
        scanf("%c",&a);
        if(a=='Y'||a=='y')  print(head_1);
       }
    printf("\n输入退学同学的学号");
    scanf("%ld",&del_num);
    head_1=del(head_1,del_num);
    printf("操作完成,是否输出学生信息? Y or N ");
    scanf("%c",&a);
    if(a=='Y'||a=='y')  print(head_1);
    printf("\n输入要插入学生的信息:");
    scanf("%ld,%s,%c,%f,%f,%f",&stu.num,&stu.name,&stu.sex,&stu.score.A,&stu.score.B,&stu.score.C);
    head_1=insert(head_1,&stu);
    printf("\n是否输入插入学生后所有学生的情况? Y or N ");
    scanf("%c",&a);
    if(a=='Y'||a=='y')  print(head_1);
}
      
2011-06-03 18:08
imlyi
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-6-2
收藏
得分:0 
回复 3楼 夜叶
搞定了,但是不知道哪错了,能帮我看看吗?
# include <stdio.h>
# include <malloc.h>
# define NULLL 0
# define LEN sizeof(struct student)

struct sco
{
float A;
float B;
float C;
}score;
struct student
{
    long num;
    char name[20];
    char sex;
    struct sco score;
    struct student * next;
};
int n;                                 /*n为全局变量,本文件模块中各函数均可使用它*/


struct student *creat(void)            /*定义函数,此函数带回一个指向链表头的指针*/
{
    struct student * head;
    struct student *p1,*p2;
    n=0;
    p1=p2=(struct student *) malloc(LEN);/*开辟一个新单元*/
    scanf("%ld,%s,%c,%f,%f,%f",&p1->num,&p1->name,&p1->sex,&(*p1).score.A,&(*p1).score.B,&(*p1).score.C);
    head=NULLL;
    while(p1->num!=0)
    {
        n=n+1;
        if(n==1) head=p1;
        else p2=p1;
        p1=(struct student *) malloc(LEN);
  scanf("%ld,%s,%c,%f,%f,%f",&p1->num,&p1->name,&p1->sex,&(*p1).score.A,&(*p1).score.B,&(*p1).score.C);
    }
    p2->next=NULLL;
    return(head);
}
void print(struct student *head)  /*输出链表的函数*/
{
    float z;
    struct student *p;
    printf("\n学生总人数是:%d\n",n);
    printf("NO.         Name           sex    A    B    C   Z\n");
    p=head;
    if(head!=NULLL)
        do
        {  z=(*p).score.A+(*p).score.B+(*p).score.C;
            printf("%ld%s%c%4.1f%4.1f%.1f%4.1f\n",p->num,p->name,p->sex,(*p).score.A,(*p).score.B,(*p).score.C,z);
        p=p->next;
        }while(p!=NULLL);
}

void highest(struct student *head)     /*找出总分最高的学生和学生总人数的函数*/
{
    float z1,z2;
    struct student *p;
    p=head;
    for(;head->num!=0;)
    {
    z1=(*p).score.A+(*p).score.B+(*p).score.C;
    z2=(*head).score.A+(*head).score.B+(*head).score.C;
    if(z1<=z2)  p=head;
    head=head->next;
    }
    printf("\n总分最高的学生叫:%s\n总分为:%4.1f\n学生总人数为:\n",p->name,z1,n);
}

struct student *hebing(struct student *m1,struct student *m2)    /*合并学生的函数*/
{  
    struct student * head,*p1,*p2;
    head=m1;
    for(;m2->num!=0;)
     {
        p2=m2->next;
        m1=head;
        for(;m1->num!=0;)
        {
            p1=m1->next;
            if(m2->num<=m1->num)
              {     m2->next=head;
                 head=m2;
               }
            if(m1->num<m2->num&&m2->num<=p1->num)
               {
                m1->next=m2; m2->next=p1;
               }
            if(m1->num<m2->num&&p1->num==0)
               {
                m1->next=m2;
                m2->next=NULLL;
               }
            m1++;
        }  
m2=p2;
        }
    return(head);
}
   
struct student *del(struct student *head,long num)   /*删除学生的函数*/
{
    struct student *p1,*p2;
    if(head==NULLL)  { printf("\n链表是空的!!\n");return head;}
    p1=head;
    while(num!=p1->num&&p1->next!=NULLL)
    {p2=p1;p1=p1->next;}
    if(num==p1->num)
    {if(p1==head) head=p1->next;     /*找到的是首节点,把第二个节点地址赋给head*/
    else p2->next=p1->next;
    printf("删除;%ld\n",num);
    n=n-1;;
    }
    else printf("%ld 没有找到!\n",num); /*找不到该结点*/
    return(head);
}


struct student * insert(struct student * head,struct student *stu)  /*插入学生的函数*/
{struct student *p0,*p1,*p2;
p1=head;
p0=stu;
if(head==NULLL)
{head=p0;p0->next=NULLL;}
else
{
    while((p0->num>p1->num)&&(p1->next!=NULLL))
    {p2=p1;
    p1=p1->next;}
    if(p0->num<=p1->num)
    {if(head==p1) head=p0;
    else p2->next=p0;
    p0->next=p1;}
    else
    {p1->next=p0;p0->next=NULLL;}
}
n=n+1;
return(head);
}




void main()
{
    char a;
    struct student * head_1,*head_2,stu;
    long del_num;
    printf("请输入学生信息:\n");
    head_1=creat();
    printf("\n输入完成,是否输出学生信息? Y or N? ");
    scanf("%c",&a);
    if(a=='Y'||a=='y')  print(head_1);
    printf("是否找出总分最高的学生信息? Y or N ? ");
    scanf("%c",&a);
    if(a=='Y'||a=='y')  highest(head_1);
    printf("\n是否输入另一组学生信息,并与前一组合并? Y or N ?  ");
    scanf("%c",&a);
    if(a=='Y'||a=='y')
      { printf("\n请输入学生信息:\n");
        head_2=creat();
        head_1=hebing(head_1,head_2);
        printf("\n合并完成,是否输出合并后信息? Y or N?");
        scanf("%c",&a);
        if(a=='Y'||a=='y')  print(head_1);
       }
    printf("\n输入退学同学的学号");
    scanf("%ld",&del_num);
    head_1=del(head_1,del_num);
    printf("操作完成,是否输出学生信息? Y or N ");
    scanf("%c",&a);
    if(a=='Y'||a=='y')  print(head_1);
    printf("\n输入要插入学生的信息:");
    scanf("%ld,%s,%c,%f,%f,%f",&stu.num,&stu.name,&stu.sex,&stu.score.A,&stu.score.B,&stu.score.C);
    head_1=insert(head_1,&stu);
    printf("\n是否输入插入学生后所有学生的情况? Y or N ");
    scanf("%c",&a);
    if(a=='Y'||a=='y')  print(head_1);
}
2011-06-03 18:10
imlyi
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-6-2
收藏
得分:0 
回复 6楼 waterstar
搞定了,但是不知道哪错了,能帮我看看吗?
实在不能解决了,希望你能指点下小弟!!
总是有这种情况发生呢,是不是哪个概念错了???

# include <stdio.h>
# include <malloc.h>
# define NULLL 0
# define LEN sizeof(struct student)

struct sco
{
float A;
float B;
float C;
}score;
struct student
{
    long num;
    char name[20];
    char sex;
    struct sco score;
    struct student * next;
};
int n;                                 /*n为全局变量,本文件模块中各函数均可使用它*/


struct student *creat(void)            /*定义函数,此函数带回一个指向链表头的指针*/
{
    struct student * head;
    struct student *p1,*p2;
    n=0;
    p1=p2=(struct student *) malloc(LEN);/*开辟一个新单元*/
    scanf("%ld,%s,%c,%f,%f,%f",&p1->num,&p1->name,&p1->sex,&(*p1).score.A,&(*p1).score.B,&(*p1).score.C);
    head=NULLL;
    while(p1->num!=0)
    {
        n=n+1;
        if(n==1) head=p1;
        else p2=p1;
        p1=(struct student *) malloc(LEN);
  scanf("%ld,%s,%c,%f,%f,%f",&p1->num,&p1->name,&p1->sex,&(*p1).score.A,&(*p1).score.B,&(*p1).score.C);
    }
    p2->next=NULLL;
    return(head);
}
void print(struct student *head)  /*输出链表的函数*/
{
    float z;
    struct student *p;
    printf("\n学生总人数是:%d\n",n);
    printf("NO.         Name           sex    A    B    C   Z\n");
    p=head;
    if(head!=NULLL)
        do
        {  z=(*p).score.A+(*p).score.B+(*p).score.C;
            printf("%ld%s%c%4.1f%4.1f%.1f%4.1f\n",p->num,p->name,p->sex,(*p).score.A,(*p).score.B,(*p).score.C,z);
        p=p->next;
        }while(p!=NULLL);
}

void highest(struct student *head)     /*找出总分最高的学生和学生总人数的函数*/
{
    float z1,z2;
    struct student *p;
    p=head;
    for(;head->num!=0;)
    {
    z1=(*p).score.A+(*p).score.B+(*p).score.C;
    z2=(*head).score.A+(*head).score.B+(*head).score.C;
    if(z1<=z2)  p=head;
    head=head->next;
    }
    printf("\n总分最高的学生叫:%s\n总分为:%4.1f\n学生总人数为:\n",p->name,z1,n);
}

struct student *hebing(struct student *m1,struct student *m2)    /*合并学生的函数*/
{  
    struct student * head,*p1,*p2;
    head=m1;
    for(;m2->num!=0;)
     {
        p2=m2->next;
        m1=head;
        for(;m1->num!=0;)
        {
            p1=m1->next;
            if(m2->num<=m1->num)
              {     m2->next=head;
                 head=m2;
               }
            if(m1->num<m2->num&&m2->num<=p1->num)
               {
                m1->next=m2; m2->next=p1;
               }
            if(m1->num<m2->num&&p1->num==0)
               {
                m1->next=m2;
                m2->next=NULLL;
               }
            m1++;
        }  
m2=p2;
        }
    return(head);
}
   
struct student *del(struct student *head,long num)   /*删除学生的函数*/
{
    struct student *p1,*p2;
    if(head==NULLL)  { printf("\n链表是空的!!\n");return head;}
    p1=head;
    while(num!=p1->num&&p1->next!=NULLL)
    {p2=p1;p1=p1->next;}
    if(num==p1->num)
    {if(p1==head) head=p1->next;     /*找到的是首节点,把第二个节点地址赋给head*/
    else p2->next=p1->next;
    printf("删除;%ld\n",num);
    n=n-1;;
    }
    else printf("%ld 没有找到!\n",num); /*找不到该结点*/
    return(head);
}


struct student * insert(struct student * head,struct student *stu)  /*插入学生的函数*/
{struct student *p0,*p1,*p2;
p1=head;
p0=stu;
if(head==NULLL)
{head=p0;p0->next=NULLL;}
else
{
    while((p0->num>p1->num)&&(p1->next!=NULLL))
    {p2=p1;
    p1=p1->next;}
    if(p0->num<=p1->num)
    {if(head==p1) head=p0;
    else p2->next=p0;
    p0->next=p1;}
    else
    {p1->next=p0;p0->next=NULLL;}
}
n=n+1;
return(head);
}




void main()
{
    char a;
    struct student * head_1,*head_2,stu;
    long del_num;
    printf("请输入学生信息:\n");
    head_1=creat();
    printf("\n输入完成,是否输出学生信息? Y or N? ");
    scanf("%c",&a);
    if(a=='Y'||a=='y')  print(head_1);
    printf("是否找出总分最高的学生信息? Y or N ? ");
    scanf("%c",&a);
    if(a=='Y'||a=='y')  highest(head_1);
    printf("\n是否输入另一组学生信息,并与前一组合并? Y or N ?  ");
    scanf("%c",&a);
    if(a=='Y'||a=='y')
      { printf("\n请输入学生信息:\n");
        head_2=creat();
        head_1=hebing(head_1,head_2);
        printf("\n合并完成,是否输出合并后信息? Y or N?");
        scanf("%c",&a);
        if(a=='Y'||a=='y')  print(head_1);
       }
    printf("\n输入退学同学的学号");
    scanf("%ld",&del_num);
    head_1=del(head_1,del_num);
    printf("操作完成,是否输出学生信息? Y or N ");
    scanf("%c",&a);
    if(a=='Y'||a=='y')  print(head_1);
    printf("\n输入要插入学生的信息:");
    scanf("%ld,%s,%c,%f,%f,%f",&stu.num,&stu.name,&stu.sex,&stu.score.A,&stu.score.B,&stu.score.C);
    head_1=insert(head_1,&stu);
    printf("\n是否输入插入学生后所有学生的情况? Y or N ");
    scanf("%c",&a);
    if(a=='Y'||a=='y')  print(head_1);
}
2011-06-03 18:14
wangnengchao
Rank: 2
等 级:论坛游民
帖 子:90
专家分:55
注 册:2011-5-2
收藏
得分:3 
呵呵,路过的
2011-06-03 18:54
快速回复:求大神帮小弟解决!!
数据加载中...
 
   



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

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