| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 819 人关注过本帖
标题:新手写的作业,请帮忙指点下。
只看楼主 加入收藏
yuanbin0525
Rank: 1
来 自:上海
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-11-25
收藏
 问题点数:0 回复次数:3 
新手写的作业,请帮忙指点下。
学习编程一个月了,写了个小项目,错误太多了,实在是自己解决不了。。。请高手们帮忙下。

题目:用C语言编写一个程序实现学员成绩管理,每个学员包括3门成绩。从键盘输入学员信息,包括学号、姓名、三门课成绩,计算出学员的平均成绩,按照学员平均成绩由大到小排列。另外需要增加下面的管理功能。
1.插入功能:在排序后的学员成绩表中插入一个学员的信息,要求插入后仍然保持成绩表原有排序。
2.删除功能:要求输入指定的学号,从学员信息表中删除该学员,删除后的成绩表保持原有排序。

推荐实现步骤:
1.包含一个头文件,用于导入输入输出函数。
2.定义一个结构,保存每个学员的信息,包括学号,姓名,三门课的成绩,平均成绩。
3.定义并实现单个学员信息录用函数。
4.定义和实现main函数,调用单个学员信息录用函数,完成所有学员的录用。
5.由于要多次显示学员信息,所以建议定义一个display函数,用来随时显示所有学员的信息。
6.定义并实现排序函数。
7.扩充main函数,测试排序后的学员信息是否正确,输出排序前后的学员信息。
8.定义并实现插入函数。
9.扩充mian函数,测试插入后的学员信息是否正确。
10.定义并实现删除函数。
11.扩充mian函数,测试删除后的学员信息是否正确。



本人自己写的程序,错误太多,实在是没有头绪了,请高手指教。。。
#include <stdio.h>

struct student
{
    int xuehao;
    char name[10];
    double score1;
    double score2;
    double score3;
    double pingjun;
}stu[50];

void display(struct student stu[], int x);

void jieshou(struct student stu[], int i)    //接受学员信息的子函数
{

    char ans;
    ans = 'y';
    struct student stu[];
    printf("请输入学员信息。\n\n");
    do {
        
    
        printf("学号:");
        scanf("%d", &stu[i].xuehao);
        fflush(stdin);
        printf("\n姓名:");
        gets(stu[].name);
        printf("\n三门成绩:");
        printf("\n成绩1:");
        scanf("%.2lf", &stu[i].score1);
        printf("\n成绩2:");
        scanf("%.2lf", &stu[i].score2);
        printf("\n成绩3:");
        scanf("%.2lf", &stu[i].score3);
        stu[i].pingjun = (stu[i].score1 + stu[i].score2 + stu[i].score3) / 3;
        i++;
        printf("是否继续输入:(y/n)");
        fflush(stdin);
        scanf("%c", &ans);
    } while(ans == 'y' && ans == 'Y');
    return stu[];
}

void paixu(struct student stu[], int x)        //实现排序的子函数
{
    int i, j;
    struct student temp;
    for (i = 0; i < x; i++)
    {
        for (j = 0; j < x - i - 1; j++)
        {
            if (stu[j].pingjun < stu[j + 1].pingjun)
            {
                temp = stu[j];
                stu[j] = stu[j + 1];
                stu[j + 1] = temp;
            }
        }
    }
}

void charu(struct student stu[], int x)         //实现插入的子函数
{
    char ans;
    struct student stu[];
    printf ("\n是否要插入新学员?(y/n)");
    fflush (stdin);
    ans = getchar();
    if (ans == 'y' || ans == 'Y')
    {
        printf("学号:");
        scanf("%d", &stu[].xuehao);
        fflush(stdin);
        printf("\n姓名:");
        gets(stu[].name);
        printf("\n三门成绩:");
        printf("\n成绩1:");
        scanf("%.2lf", &stu[].score1);
        printf("\n成绩2:");
        scanf("%.2lf", &stu[].score2);
        printf("\n成绩3:");
        scanf("%.2lf", &stu[].score3);
        stu[].pingjun = (stu[].score1 + stu[].score2 + stu[].score3) / 3;
        x++;
    }
    paixu(stu, x);
    printf ("\n插入新学员后的学员信息如下:\n");
    display(stu, x);
    return x;
}

void shanchu(struct student stu[], int x)       //实现删除的子函数
{
    int i, j, k;
    char ans;
    ans = 'y';
    printf("是否要删除学员信息:(y/n)");
    fflush(stdin);
    scanf("%c", &ans);
    if (ans == 'y' && ans == 'Y')
    {
        printf("请输入需要删除学员的学号:");
        scanf("%d", &i);
        for (j = 0; j < x; j++)
        {
            if (stu[j].xuehao == i)
            {
                break;
            }
        }
        for (k = j; k < (x - 1); k++)
        {
            stu[k] = stu[k + 1];
        }
        x--;
        paixu(stu, x);
        printf ("\n删除后学员的信息如下:");
        display(stu, x);
    }
    return x;
}

void main()                                     //main函数
{
    int y;
    struct student x[];
    do {
        printf("学员信息表\n");
        printf("1.输入学员信息。");
        printf("2.插入学员信息。");
        printf("3.显示学员信息。");
        printf("4.删除学员信息。");
        printf("5.退出。");
        scanf("%d", &y);
    } while(y == 5);
    switch (y)
    {
    case 1:
        x = jieshou(struct student stu[]);
    case 2:
        x = charu(struct student stu[]);
    case 3:
        x = paixu(struct student stu[]);
    case 4:
        x = shanchu(struct student stu[]);
    }
}
搜索更多相关主题的帖子: 学员 作业 学号 
2007-12-24 20:31
wind_lu
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-12-8
收藏
得分:0 
你错的好多都是很基础的语法,比如函数的传参数等等,帮你改的七七八八了,还有错的话你按照我的思路继续改正吧,我不能全帮你改了,毕竟你自己也要知道如何去做,全帮你改了就没意义了,反正大的错应该没了,还有基础方面的东西你还要弄弄,不要上来就做复杂的题目,没好处的.
#include "stdio.h"
#include "stdafx.h"
#include "string.h"
#include "stdlib.h"
#define Cls system("cls")     //定义清屏
#define Flush fflush(stdin)   //定义输入缓冲区
  
#define N 10                //定义一个全局变量
struct student
{
    int xuehao;
    char name[10];
    float score1;
    float score2;
    float score3;
    float pingjun;
}stu[N];
int jieshou(struct student stu[], int  n)    //接受学员信息的子函数
{
    char ans;
    int i=n;


    Cls;
        //struct student stu[];
    printf("请输入学员信息。\n\n");
    while(1/*ans == 'y' && ans == 'Y'*/){  

        printf("学号:");
        scanf("%d", &stu[i].xuehao);
        Flush;
        printf("\n姓名:");
        scanf("%s",stu[i].name);
        printf("三门成绩:\n");
        scanf("%f%f%f", &stu[i].score1, &stu[i].score2, &stu[i].score3);
        //stu[i].pingjun = (stu[i].score1 + stu[i].score2 + stu[i].score3) / 3;
        i++;
        
    printf("是否继续输入:(y/n)");
        scanf("\n%c", &ans);
        if(ans=='n'||ans=='N')
            break;
        
    }
    //return stu[];
    return i;
}
void display(struct student stu[], int m)
{
    int i;
    Cls;
    Flush;
    for(i=0;i<m;i++)
    {
        printf("学号:%d\t姓名:%s\n",stu[i].xuehao,stu[i].name);
        printf("三门成绩:\n");
        printf("成绩1:%.2f\n成绩2:%.2f\n成绩3:%.2f",stu[i].score1,stu[i].score2,stu[i].score3);
      }
    getchar();
}


void paixu(struct student stu[], int x)        //实现排序的子函数
{
    int i, j;
    struct student temp;
    for (i = 0; i < x; i++)
    {
        for (j = 0; j < x - i - 1; j++)
        {
            if (stu[j].pingjun < stu[j + 1].pingjun)
            {
                temp = stu[j];
                stu[j] = stu[j + 1];
                stu[j + 1] = temp;
            }
        }
    }
}

void charu(struct student stu[], int x)         //实现插入的子函数
{
    char ans;
    //struct student stu[];
    Cls;
    printf ("\n是否要插入新学员?(y/n)");
    fflush (stdin);
    ans = getchar();
    if (ans == 'y' || ans == 'Y')
    {
        printf("学号:");
        scanf("%d", &stu[x].xuehao);
        fflush(stdin);
        printf("\n姓名:");
        gets(stu[x].name);
        printf("\n三门成绩:");
        printf("\n成绩1:");
        scanf("%.2lf", &stu[x].score1);
        printf("\n成绩2:");
        scanf("%.2lf", &stu[x].score2);
        printf("\n成绩3:");
        scanf("%.2lf", &stu[x].score3);
        stu[x].pingjun = (stu[x].score1 + stu[x].score2 + stu[x].score3) / 3;
        x++;
    }
   
   
}

void shanchu(struct student stu[], int x)       //实现删除的子函数
{
    int i, j, k;
    char ans;
    ans = 'y';
    Cls;
    printf("是否要删除学员信息:(y/n)");
    fflush(stdin);
    scanf("%c", &ans);
    if (ans == 'y' && ans == 'Y')
    {
        printf("请输入需要删除学员的学号:");
        scanf("%d", &i);
        
        for (j = 0; j < x; j++)
        {
            if (stu[j].xuehao == i)
            {
                break;
            }
        }
        for (k = j; k < (x - 1); k++)
        {
            stu[k] = stu[k + 1];
        }
        x--;
        paixu(stu, x);
        printf ("\n删除后学员的信息如下:");
        display(stu, x);
    }
    /*return x;*/
}

void main()                                     //main函数
{
    int y,x=0;
    struct student stu[N];
    do
    {
    system("cls");
        printf("学员信息表\n");
        printf("1.输入学员信息。\n");
        printf("2.插入学员信息。\n");
        printf("3.对学员信息进行排序:\n");
        printf("4.显示学员信息。\n");
        printf("5.删除学员信息。\n");
                printf("6.退出。\n");
      
        printf("请输入选择项:");
        scanf("%d",&y);
    switch (y)
    {
    case 1:
        x = jieshou(/*struct student*/stu,x);
        break;
    case 2:
          charu(/*struct student */stu,x);
          break;
    case 3:
         paixu(/*struct student*/ stu,x);
        break;
    case 4:
        display(/*struct student */stu,x);

        break;
    case 5:shanchu(stu,x);
        break;
    case 6:
        exit(0);
        break;

    }
}
    while(1/*y == 5*/);
}
2007-12-24 22:32
yuanbin0525
Rank: 1
来 自:上海
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-11-25
收藏
得分:0 
感谢楼上的,非常感谢

刚学习编程,连菜鸟都不算。。。
2007-12-24 22:42
wind_lu
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-12-8
收藏
得分:0 
加油~~我也刚开始学编程,以后一起多交流
2007-12-24 22:43
快速回复:新手写的作业,请帮忙指点下。
数据加载中...
 
   



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

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