C语言程序设计精髓第十二周编程题

练兵区

1. 大奖赛现场统分(4分)

题目内容:

已知某大奖赛有n个选手参赛,m(m>2)个评委为参赛选手评分(最高10分,最低0分)。统分规则为:在每个选手的m个得分中,去掉一个最高分和一个最低分后,取平均分作为该选手的最后得分。要求编程实现:

(1)根据n个选手的最后得分,从高到低输出选手的得分名次表,以确定获奖名单;

(2)根据各选手的最后得分与各评委给该选手所评分数的差距,对每个评委评分的准确性和评分水准给出一个定量的评价,从高到低输出各评委得分的名次表。

提示:首先设计如下5个数组:

(1)sh[i],存放第i个选手的编号;

(2)sf[i],存放第i个选手的最后得分,即去掉一个最高分和一个最低分以后的平均分;

(3)ph[j],存放第j个评委的编号;

(4)f[i][j],存放第j个评委给第i个选手的评分;

(5)pf[j],存放代表第j个评委评分水准的得分。

解决本问题的关键在于计算选手的最后得分和评委的得分。

先计算选手的最后得分。外层循环控制参赛选手的编号i从1变化到n,当第i个选手上场时,输入该选手的编号sh[i]。内层循环控制给选手评分的评委的编号j从1变化到m,依次输入第j个评委给第i个选手的评分f[i][j],并将其累加到sf[i]中,同时求出最高分max和最低分min。当第i个选手的m个得分全部输入并累加完毕后,去掉一个最高分max,去掉一个最低分min,于是第i个选手的最后得分为:

sf[i] = (sf[i] – max – min)/(m-2);

当n个参赛选手的最后得分sf[0],sf[1],…,sf[n]全部计算完毕后,再将其从高到低排序,打印参赛选手的名次表。

下面计算评委的得分。评委给选手评分存在误差,即f[i][j]≠sf[i]是正常的,也是允许的。但如果某个评委给每个选手的评分与各选手的最后得分都相差太大,则说明该评委的评分有失水准。可用下面的公式来对各个评委的评分水平进行定量评价:
在这里插入图片描述

#include <stdio.h>
#include<math.h>
#define N 20
int MaxPos(float f[][N], int x, int judge);
int MinPos(float f[][N], int x, int judge);
void Arrange(float score[], int n, int number[])
{
   
    int i, j;
    float temp;
    for(i=0;i<n-1;i++)
    {
   
        for(j=i+1;j<n;j++)
        {
   
            if(score[i]<score[j])
            {
   
                temp = score[i];
                score[i]=score[j];
                score[j]=temp;
                temp = number[i];
                number[i]=number[j];
                number[j]=temp;
            }
        }
    }
}
int main()
{
   
    int athlete, judge, sh[N];//存放选手编号
    int ph[N]; //评委编号
    float f[N][N]; //评委给选手的评分
    float sf[N]; //存放最后得分
    float pf[N]; //评委评分水准分数
    float sum;
    float x; //计算评委分数时用到的变量
    int maxpos, minpos;
    int i, j;
    printf("How many Athletes?\n");
    scanf("%d", &athlete);
    printf("How many judges?\n");
    scanf("%d", &judge);
    printf("Scores of Athletes:\n");
    for(i=0;i<athlete;i++)
    {
   
        printf("Athlete %d is playing.\n", i+1);
        printf("Please enter his number code:\n");
        scanf("%d", &sh[i]);
        for(j=0;j<judge;j++)
        {
   
            printf("Judge %d gives score:\n", j+1);
            scanf("%f", &f[i][j]);
        }
        maxpos =MaxPos(f, i, judge);
        minpos=MinPos(f, i, judge);
        printf("Delete a maximum score:%.1f\n", f[i][maxpos]);
        printf("Delete a minimum score:%.1f\n", f[i][minpos]);
        sum = 0;
        for(j=0;j<judge;j++)
        {
   
            sum += f[i][j];
        }
        sum = sum - f[i][minpos] - f[i][maxpos];
        sf[i] = sum/(judge-2);
        printf("The final score of Athlete %d is %.3f\n", sh[i], sf[i]);
    }
    for (j = 0; j < judge; j++) //计算评委分数,由于Arrange会交换sf位置,这一步一定要在Arrange前
    {
   
        x = 0;
        for (i = 0; i < athlete; i++)
        {
   
            x = x + pow(f[i][j] - sf[i], 2);
        }
        x = x / athlete;
        pf[j] = 10 - sqrt(x);
    }
    printf("Order of Athletes:\n");
    Arrange(sf, athlete, sh);
    printf("order\tfinal score\tnumber code\n");
    for(i=0;i<athlete;i++)
        printf("%5d\t%11.3f\t%6d\n", i+1, sf[i], sh[i]);
    printf("Order of judges:\n");
    for(i=0;i<judge;i++)
        ph[i]=i+1;
    Arrange(pf, judge, ph);
    printf("order\tfinal score\tnumber code\n");
    for(i=0;i<judge;i++)
        printf("%5d\t%11.3f\t%6d\n", i+1, pf[i], ph[i]);
    printf("Over!Thank you!\n");
    return 0;
    
}

int MaxPos(float f[][N], int x, int judge)
{
   
    int maxpos = 0, i;
    for(i=0;i<judge;i++)
    {
   
        if(f[x][i]>f[x][maxpos])
            maxpos=i;
    }
    return maxpos;
}

int MinPos(float f[][N], int x, int judge)
{
   
    int minpos = 0, i;
    for(i=0;i<judge;i++)
    {
   
        if(f[x][i]<f[x][minpos])
            minpos=i;
    }
    return minpos;
}

2. 学生成绩管理系统V3.0(4分)

题目内容:

某班有最多不超过30人(具体人数由键盘输入)参加某门课程的考试,参考第11周在线测验中“学生成绩管理系统V2.0”,用二维字符数组作函数参数编程实现如下菜单驱动的学生成绩管理系统:

(1)录入每个学生的学号、姓名和考试成绩;
(2)计算课程的总分和平均分;
(3)按成绩由高到低排出名次表;
(4)按成绩由低到高排出名次表;
(5)按学号由小到大排出成绩表;
(6)按姓名的字典顺序排出成绩表;
(7)按学号查询学生排名及其考试成绩;
(8)按姓名查询学生排名及其考试成绩;
(9)按优秀(90100)、良好(8089)、中等(7079)、及格(6069)、不及格(0~59)5个类别,统计每个类别的人数以及所占的百分比;
(10)输出每个学生的学号、姓名、考试成绩。

要求程序运行后先显示如下菜单,并提示用户输入选项:
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Sort in dictionary order by name
7.Search by number
8.Search by name
9.Statistic analysis
10.List record
0.Exit
Please enter your choice:
然后,根据用户输入的选项执行相应的操作。
请按照下面的定义及函数原型编程
#define MAX_LEN 10 /* 字符串最大长度 /
#define STU_NUM 30 /
最多的学生人数 */
int Menu(void);
void ReadScore(long num[], char name[][MAX_LEN], float score[], int n);
void AverSumofScore(float score[], int n);
void SortbyScore(long num[], char name[][MAX_LEN], float score[], int n,
int (*compare)(float a, float b));
int Ascending(float a, float b);
int Descending(float a, float b);
void SwapFloat(float *x, float *y);
void SwapLong(long *x, long *y);
void SwapChar(char x[], char y[]);
void AsSortbyNum(long num[], char name[][MAX_LEN], float score[], int n);
void SortbyName(long num[], char name[][MAX_LEN], float score[], int n);
void SearchbyNum(long num[], char name[][MAX_LEN], float score[], int n);
void SearchbyName(long num[], char name[][MAX_LEN], float score[], int n);
void StatisticAnalysis(float score[], int n);
void PrintScore(long num[], char name[][MAX_LEN], float score[], int n) ;

程序运行结果示例:
Input student number(n<30):
6↙
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Sort in dictionary order by name
7.Search by number
8.Search by name
9.Statistic analysis
10.List record
0.Exit

Please Input your choice:
1↙
Input student’s ID, name and score:
11003001↙
lisi↙
87↙
11003005↙
heli↙
98↙
11003003↙
ludi↙
75↙
11003002↙
dumo↙
48↙
11003004↙
zuma↙
65↙
11003006↙
suyu↙
100↙

Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Sort in dictionary order by name
7.Search by number
8.Search by name
9.Statistic analysis
10.List record
0.Exit

Please Input your choice:
2↙
sum=473,aver=78.83

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

3↙

Sort in descending order by score:

11003006 suyu 100

11003005 heli 98

11003001 lisi 87

11003003 ludi 75

11003004 zuma 65

11003002 dumo 48

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

4↙

Sort in ascending order by score:

11003002 dumo 48

11003004 zuma 65

11003003 ludi 75

11003001 lisi 87

11003005 heli 98

11003006 suyu 100

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

5↙

Sort in ascending order by number:

11003001 lisi 87

11003002 dumo 48

11003003 ludi 75

11003004 zuma 65

11003005 heli 98

11003006 suyu 100

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

6↙

Sort in dictionary order by name:

11003002 dumo 48

11003005 heli 98

11003001 lisi 87

11003003 ludi 75

11003006 suyu 100

11003004 zuma 65

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

7↙

Input the number you want to search:

11003004↙

11003004 zuma 65

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

8↙

Input the name you want to search:

heli↙

11003005 heli 98

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

9↙

<60 1 16.67%

60-69 1 16.67%

70-79 1 16.67%

80-89 1 16.67%

90-99 1 16.67%

100 1 16.67%

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

10↙

11003002 dumo 48

11003005 heli 98

11003001 lisi 87

11003003 ludi 75

11003006 suyu 100

11003004 zuma 65

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

11↙

Input error!

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

0↙

End of program!

#include <stdio.h>
#include<math.h>
#include<string.h>
#define   MAX_LEN  10            /* 字符串最大长度 */
#define   STU_NUM 30         /* 最多的学生人数 */
int   Menu(void);
void  ReadScore(long num[], char name
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值