标题:求大佬救个命,万分感谢
只看楼主
Calvin22
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2019-1-13
结帖率:0
已结贴  问题点数:20 回复次数:2 
求大佬救个命,万分感谢
从键盘输入一个班(全班最多不超过30人)学生某门课的成绩,当输入成绩为负值时,输入结束,分别实现下列功能:
(1)统计不及格人数并打印不及格学生名单;
(2)统计成绩在全班平均分及平均分之上的学生人数,并打印这些学生的名单;
(3)按成绩由高到低排出名次;
(4)打印出名次表,表格内包括学生编号、成绩;
(5)任意输入一个学号,能够查找出该学生在班级中的排名及其考试分数。
搜索更多相关主题的帖子: 输入 学生 成绩 打印 平均分 
2019-01-13 00:09
了无此生
Rank: 3Rank: 3
来 自:粤地潮州
等 级:论坛游侠
威 望:3
帖 子:82
专家分:121
注 册:2018-11-14
得分:10 
个人能力有限
以下来自度娘
https://zhidao.baidu.com/question/345457690.html
正确与否概不负责你自己动动手指头会死啊

程序代码:
#include<stdio.h>
#define N 30
typedef struct student
{
char name[10];
int score;
}STU;
void main()
{ 
STU s[N];
int n=0;
int i;
int n1=0;
int n2=0;
int n3=0;
int n4=0;
int n5=0;
int n6=0;
int total=0;
float aver;
printf("请输入学生姓名与成绩:");
do
{
scanf("%s",&s[n].name);
scanf("%d",&s[n].score);
n++;
}while(s[n-1].score>=0);
n--;
for(i=0;i<n;i++)
{
total+=s[i].score;
if(s[i].score<60)
n1++;
else if(s[i].score<70)
n2++;
else if(s[i].score<80)
n3++;
else if(s[i].score<90)
n4++;
else
n5++;
}
printf("不及格人数为:%d,名单如下:\n",n1);
for(i=0;i<n;i++)
{
if(s[i].score<60)
printf("%s\t %d\n",s[i].name,s[i].score);
}
aver=(float)total/n;
for(i=0;i<n;i++)
{
if(s[i].score>aver)
n6++;
}
printf("平均分为:%.1f,分数在平均分以上的人数为:%d,名单如下:\n",aver,n6);
for(i=0;i<n;i++)
{
if(s[i].score>aver)
printf("%s\t %d\n",s[i].name,s[i].score);
}
printf("分数段\t学生人数\t图形\n");
printf("<60\t%d(%.1f%%)\t",n1,(float)n1*100/n);
for(i=0;i<n1;i++)
printf("*");
printf("\n");
printf("60~69\t%d(%.1f%%)\t",n2,(float)n2*100/n);
for(i=0;i<n2;i++)
printf("*");
printf("\n");
printf("70~79\t%d(%.1f%%)\t",n3,(float)n3*100/n);
for(i=0;i<n3;i++)
printf("*");
printf("\n");
printf("80~89\t%d(%.1f%%)\t",n4,(float)n4*100/n);
for(i=0;i<n4;i++)
printf("*");
printf("\n");
printf(">=90\t%d(%.1f%%)\t",n5,(float)n5*100/n);
for(i=0;i<n5;i++)
printf("*");
printf("\n");
} 

睡不醒的学渣(^・ω・^ )
2019-01-13 01:46
ZJYTY
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:4
帖 子:92
专家分:700
注 册:2018-12-20
得分:10 
程序代码:
#include <stdio.h>
#include <stdlib.h>

#define MENU_STU \
    "1 get_mes\n" \
    "2 not_pass\n" \
    "3 up_ave\n" \
    "4 rank_by_score\n" \
    "5 find_by_id\n"

typedef struct student
{
    int id;
    char name[32];
    float score;
    int rankNo;
}STU;
STU stus[30];

void get_mes(int *stuNum)
{
    int wkCount = 0;
    printf("学生成绩录入:\n");
    do
    {
        printf("num %d id : ", wkCount + 1);
        scanf("%d", &(stus[wkCount].id));
        while (!getchar());
        printf("num %d name : ", wkCount + 1);
        scanf("%s", stus[wkCount].name);
        while (!getchar());
        printf("num %d score : ", wkCount + 1);
        scanf("%f", &(stus[wkCount].score));
        while (!getchar());
        if (stus[wkCount].score > 100.0)
        {
            printf("请输入有效成绩(0-100)\n");
            continue;
        }
        else if (stus[wkCount].score < 0.0)
        {
            *stuNum = wkCount;
            printf("共计录入%d人\t", wkCount);
            break;
        }
        else
        {
            ++wkCount;
        }
    } while (1);
}

void up_ave(int stuNum)
{
    float totalscore = 0;
    float avescore = 0;
    int notPassCount = 0;
    for (int i = 0; i < stuNum;++i)
    {
        totalscore += stus[i].score;
    }
    avescore = totalscore / stuNum;
    printf("班级平均分为%.2f,高于平均分的学生有:\n",avescore);
    for (int i = 0; i < stuNum; ++i)
    {
        if (stus[i].score > avescore)
        {
            notPassCount++;
            printf("%d\t%s\n",notPassCount,stus[i].name);
        }
    }
    if (0 == notPassCount)
        printf("班级所有同学成绩一致\n");
}

void not_pass(int stuNum)
{
    float passScore = 60;
    int notPassCount = 0;
    //printf("Input the pass score:");
    //scanf("%f", &passScore);
    for (int i = 0; i < stuNum; ++i)
    {
        if (stus[i].score < passScore)
        {
            notPassCount++;
            if (1 == notPassCount)
                printf("不及格人员名单:\n");
            printf("%d\t%s\n", notPassCount, stus[i].name);
        }
    }
    if (0 == notPassCount)
        printf("无不及格人员\n");
}

void rank_by_score(int stuNum)
{
    STU stuTemp;
    for (int i = 0; i < stuNum - 1; ++i)
    {
        for (int j = 0; j < stuNum - i; ++j)
        {
            if (stus[j].score < stus[j + 1].score)
            {
                stuTemp = stus[j];
                stus[j] = stus[j + 1];
                stus[j + 1] = stuTemp;
            }
        }
    }
    for (int i = 0; i < stuNum; ++i)
    {
        stus[i].rankNo = i + 1;
    }
    printf("班级成绩名次单:\n");
    for (int i = 0; i < stuNum; ++i)
    {
        printf("%d\t%s\t%.2f\t%d\n", stus[i].id, stus[i].name, stus[i].score, stus[i].rankNo);
    }
}

void find_by_id(int stuNum)
{
    bool ret = false;
    int findId = 0;
    printf("Input the id what you want to find : ");
    scanf("%d",&findId);
    while (!getchar());
    for (int i = 0; i < stuNum; ++i)
    {
        if (findId == stus[i].id)
        {
            ret = true;
            printf("id\tname\tscore\trankNo\n");
            printf("%d\t%s\t%.2f\t%d\n", stus[i].id, stus[i].name, stus[i].score, stus[i].rankNo);
            break;
        }
    }
    if (!ret)
        printf("There is no this id\n");
}

int main()
{
    int stuNum = 0;
    int sel;
    do 
    {
        system("cls");
        printf(MENU_STU);
        printf("Input your choice : ");
        scanf("%d", &sel);
        while (!getchar());
        switch (sel)
        {
        case 1:
            get_mes(&stuNum);
            getchar();
            break;
        case 2:
            not_pass(stuNum);
            getchar();
            break;
        case 3:
            up_ave(stuNum);
            getchar();
            break;
        case 4:
            rank_by_score(stuNum);
            getchar();
            break;
        case 5:
            find_by_id(stuNum);
            getchar();
            break;
        default:
            printf("There is no this choice\n");
            getchar();
            break;
        }
    } while (1);

}






某些细节可以再做改动

-------------------------------若有不当之处,敬请谅解-------------------------------
2019-01-14 16:27



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-492656-1-1.html




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

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