| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 741 人关注过本帖
标题:急解呀 !!!帮帮忙呀
只看楼主 加入收藏
cxc363588
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-12-6
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
急解呀 !!!帮帮忙呀
一.    实验题目:有10个学生,每个学生的数据包括学号、姓名及3门课的
成绩、总分成绩和平均成绩,从键盘输入10个学生的数据(包括学号、姓名及3门课的成绩),要求打印出每位学生      的学号、姓名、三门课的成绩、总成绩和平均成绩,最后再打印出三门课的总成绩以及最高分的学生的数据(包括姓名和总成绩)。
二.目的:1.掌握结构体类型变量的定义和使用。
        2.掌握结构体类型数组的概念和使用。
        3.掌握联合体类型变量的定义和使用。
        4.掌握用指针访问结构体与联合体的方法。
        5.掌握利用结构体进行函数参数的传递。
三.要求:1.根据学生信息定义一个结构体类型,再说明一个该结构类型的数组。
       2.用input 函数从键盘上输入10个学生的数据:
         3.用average 函数求出每个学生总成绩、平均成绩和所有学生的总平均成绩。
         4.用maximum 函数找出最高分的学生数据;
         5.在主函数中输出每位学生的学号、姓名、三门课的成绩、总成绩和平均成绩以及总平均分和最高分学生的数据。
搜索更多相关主题的帖子: 姓名 三门 结构体 总成绩 
2011-12-06 13:10
pinglideyu
Rank: 3Rank: 3
来 自:武汉工程大学
等 级:论坛游侠
威 望:1
帖 子:735
专家分:140
注 册:2007-1-7
收藏
得分:10 
我给你写个程序,你参考下。
注:为了方便,我暂时只输入了2个学生信息。
程序代码:
#include "stdio.h"
#include "conio.h"
#include "malloc.h"
#include "string.h"
struct Node
{
    char Id[10];
    char Name[10];
    int Score1;
    int Score2;
    int Score3;
    int Score;
    float average;
    Node *next;
};

Node *Initstudentlist()
{
    Node *head;
    head=(Node *)malloc(sizeof(Node));
    head->next=NULL;
    return head;
}
Node *input(Node *head)
{
    Node *tail,*p;
    char a[10],b[10];
    tail=head;
    for (int i=0;i<2;i++)
    {
        p=(Node *)malloc(sizeof(Node));
        printf("请输入第%d学生的信息:\n",i+1);
        printf("学号 :");
        gets(a);
        strcpy(p->Id,a);
        printf("姓名 :");
        gets(b);
        strcpy(p->Name,b);
        printf("成绩1 :");
        scanf("%d",&p->Score1);
        printf("成绩2 :");
        scanf("%d",&p->Score2);
        printf("成绩3 :");
        scanf("%d",&p->Score3);
        p->next=NULL;
        tail->next=p;
        tail=p;
        printf("\n");
        fflush(stdin);
    }
    return head;
}
float average(Node *head)
{
    Node *p;
    int sum;
    int sum1=0;
    float aver;
    p=head->next;
    while(p)
    {
        sum=(p->Score1)+(p->Score2)+(p->Score3);
        sum1+=sum;
        p->Score=sum;
        aver=(float)sum/3;
        p->average=aver;
        p=p->next;
    }
    return (float)sum1;
}
void Printstudentlist(Node *head,float score)
{
    Node *p;
    p=head->next;
    printf("----------------------------------------------------------------\n");
    printf("学号\t姓名\t成绩1\t成绩2\t成绩3\t总分\t平均分\n");
    while (p)
    {
        printf("%s\t%s\t%d\t%d\t%d\t%d\t%.2f\n",p->Id,p->Name,p->Score1,p->Score2,p->Score3,p->Score,p->average);
        p=p->next;
    }
    printf("所有学生的总平均成绩为 :%.2f\n",score/2);
}
void Maximum(Node *head)
{
    Node *p,*q;
    int Maxscore;
    p=head->next;
    q=p->next;
    Maxscore=p->Score;
    while (q)
    {
        if (Maxscore<q->Score)
            Maxscore=q->Score;
        q=q->next;
    }
    while (p)
    {
        if (p->Score==Maxscore)
        {
            printf("---------------------------\n");
            printf("其中总分最高的同学信息如下:\n");
            printf("学号\t姓名\t成绩1\t成绩2\t成绩3\t总分\t平均分\n");
            printf("%s\t%s\t%d\t%d\t%d\t%d\t%.2f\n",p->Id,p->Name,p->Score1,p->Score2,p->Score3,p->Score,p->average);
        }
        p=p->next;
    }

}
int main()
{
    Node *head,*head1;
    float score;
    head=Initstudentlist();// 链表的初使化
    head1=input(head);
    score=average(head1);
    Printstudentlist(head1,score);
    Maximum(head1);
    getch();
    return 0;
}



~~我的明天我知道~~
2011-12-06 18:10
keaixiaou
Rank: 2
等 级:论坛游民
帖 子:9
专家分:21
注 册:2011-11-23
收藏
得分:10 
#include <stdio.h>
#include <malloc.h>
struct student
{
    char id[20];
    char name[10];
    float english;
    float math;
    float c;
    struct student *next;

};
struct student* create(void)
{
    struct student*p=(struct student*)malloc(sizeof(struct student));
    scanf("%s %s %f %f %f",p->id,p->name,&p->english,&p->math,&p->c);
    p->next=NULL;
    return p;
}
void input(struct student*head)
{
    int i;
    struct student*p=head;
    for (i=0;i<9;i++)
    {
        while (p->next!=NULL)
        {
            p=p->next;
        }
        p->next=create();
    }
}
void average(struct student*head)
{
    int i;
    float mo;
    struct student*p=head;
    for (mo=0,i=0;p!=NULL;p=p->next,i++)
    {
        printf("%f %f\n",p->english+p->math+p->c,(p->english+p->math+p->c)/3);
        mo+=(p->english+p->math+p->c);
    }
    printf("%f\n",mo/i);
}
void maximum(struct student*head)
{
    struct student*p=head;
    float most=p->english+p->math+p->c;
    int i=0,mostint=0;
    while (p!=NULL)
    {
        if(most<(p->english+p->math+p->c))
        {
            most=p->english+p->math+p->c;
            mostint=i;
        }
        i++;
        p=p->next;
    }
    for (p=head,i=0;i<mostint;i++,p=p->next)
    {
        ;
    }
    printf("%s %s %f %f %f\n",p->id,p->name,p->english,p->math,p->c);
}
int main()
{
    struct student stu,*head;
    printf("Input information!\n");
    scanf("%s %s %f %f %f",stu.id,stu.name,&stu.english,&stu.math,&stu.c);
    head=&stu;
    head->next=NULL;
    input(head);
    average(head);
    maximum(head);
    return 0;
}
2011-12-06 19:10
cxc363588
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-12-6
收藏
得分:0 
谢谢哈
2011-12-07 19:03
快速回复:急解呀 !!!帮帮忙呀
数据加载中...
 
   



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

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