1学生成绩管理系统V4.0(4分)

某班有最多不超过30人(具体人数由键盘输入)参加期末考试,最多不超过6门(具体门数由键盘输入)。参考学生成绩管理系统V3.0,用二维数组作函数参数编程实现如下菜单驱动的学生成绩管理系统:

(1)录入每个学生的学号、姓名和各科考试成绩;

(2)计算每门课程的总分和平均分;

(3)计算每个学生的总分和平均分;

(4)按每个学生的总分由高到低排出名次表;

(5)按每个学生的总分由低到高排出名次表;

(6)按学号由小到大排出成绩表;

(7)按姓名的字典顺序排出成绩表;

(8)按学号查询学生排名及其各科考试成绩;

(9)按姓名查询学生排名及其各科考试成绩;

(10)按优秀(90100)、良好(8089)、中等(7079)、及格(6069)、不及格(0~59)5个类别,对每门课程分别统计每个类别的人数以及所占的百分比;

(11)输出每个学生的学号、姓名、各科考试成绩、总分、平均分,以及每门课程的总分和平均分。

要求程序运行后先显示如下菜单,并提示用户输入选项:

Management for Students’ scores

1.Input record

2.Caculate total and average score of every course

3.Caculate total and average score of every student

4.Sort in descending order by score

5.Sort in ascending order by score

6.Sort in ascending order by number

7.Sort in dictionary order by name

8.Search by number

9.Search by name

10.Statistic analysis

11.List record

0.Exit

Please Input your choice:

然后,根据用户输入的选项执行相应的操作。

请按照下面的定义及函数原型编程

#define MAX_LEN 10 /* 字符串最大长度 */

#define STU_NUM 30 /* 最多的学生人数 */

#define COURSE_NUM 6 /* 最多的考试科目数 */

int Menu(void);

void ReadScore(long num[], char name[][MAX_LEN],

float score[][COURSE_NUM], int n, int m);

void AverSumofEveryStudent(float score[][COURSE_NUM], int n, int m,

float sum[STU_NUM], float aver[STU_NUM]);

void AverSumofEveryCourse(float score[][COURSE_NUM], int n, int m);

void SortbyScore(long num[], char name[][MAX_LEN],

float score[][COURSE_NUM], float sum[], float aver[],

int n, int m, 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[][COURSE_NUM], float sum[], float aver[],

int n, int m);

void SortbyName(long num[], char name[][MAX_LEN],

float score[][COURSE_NUM], float sum[], float aver[],

int n, int m);

void SearchbyNum(long num[], char name[][MAX_LEN],

float score[][COURSE_NUM], float sum[], float aver[],

int n, int m);

void SearchbyName(long num[], char name[][MAX_LEN],

float score[][COURSE_NUM], float sum[], float aver[],

int n, int m);

void StatisticAnalysis(float score[][COURSE_NUM], int n, int m);

void PrintScore(long num[], char name[][MAX_LEN],

float score[][COURSE_NUM], float sum[], float aver[],int n, int m) ;

下面是程序运行示例:

Input student number(n<30):

6↙

Management for Students’ scores

1.Input record

2.Caculate total and average score of every course

3.Caculate total and average score of every student

4.Sort in descending order by score

5.Sort in ascending order by score

6.Sort in ascending order by number

7.Sort in dictionary order by name

8.Search by number

9.Search by name

10.Statistic analysis

11.List record

0.Exit

Please Input your choice:

1↙

Input course number(m<=6):

3↙

Input student’s ID, name and score:

11003001↙

lisi↙

87↙

82↙

89↙

11003005↙

heli↙

98↙

92↙

90↙

11003003↙

ludi↙

75↙

78↙

80↙

11003002↙

dumo↙

48↙

50↙

67↙

11003004↙

zuma↙

65↙

69↙

72↙

11003006↙

suyu↙

100↙

95↙

94↙

Management for Students’ scores

1.Input record

2.Caculate total and average score of every course

3.Caculate total and average score of every student

4.Sort in descending order by score

5.Sort in ascending order by score

6.Sort in ascending order by number

7.Sort in dictionary order by name

8.Search by number

9.Search by name

10.Statistic analysis

11.List record

0.Exit

Please Input your choice:

2↙

course 1:sum=473,aver=79

course 2:sum=466,aver=78

course 3:sum=492,aver=82

Management for Students’ scores

1.Input record

2.Caculate total and average score of every course

3.Caculate total and average score of every student

4.Sort in descending order by score

5.Sort in ascending order by score

6.Sort in ascending order by number

7.Sort in dictionary order by name

8.Search by number

9.Search by name

10.Statistic analysis

11.List record

0.Exit

Please Input your choice:

3↙

student 1:sum=258,aver=86

student 2:sum=280,aver=93

student 3:sum=233,aver=78

student 4:sum=165,aver=55

student 5:sum=206,aver=69

student 6:sum=289,aver=96

Management for Students’ scores

1.Input record

2.Caculate total and average score of every course

3.Caculate total and average score of every student

4.Sort in descending order by score

5.Sort in ascending order by score

6.Sort in ascending order by number

7.Sort in dictionary order by name

8.Search by number

9.Search by name

10.Statistic analysis

11.List record

0.Exit

Please Input your choice:

4↙

Sort in descending order by score:

11003006 suyu 100 95 94 289 96

11003005 heli 98 92 90 280 93

11003001 lisi 87 82 89 258 86

11003003 ludi 75 78 80 233 78

11003004 zuma 65 69 72 206 69

11003002 dumo 48 50 67 165 55

Management for Students’ scores

1.Input record

2.Caculate total and average score of every course

3.Caculate total and average score of every student

4.Sort in descending order by score

5.Sort in ascending order by score

6.Sort in ascending order by number

7.Sort in dictionary order by name

8.Search by number

9.Search by name

10.Statistic analysis

11.List record

0.Exit

Please Input your choice:

5↙

Sort in ascending order by score:

11003002 dumo 48 50 67 165 55

11003004 zuma 65 69 72 206 69

11003003 ludi 75 78 80 233 78

11003001 lisi 87 82 89 258 86

11003005 heli 98 92 90 280 93

11003006 suyu 100 95 94 289 96

Management for Students’ scores

1.Input record

2.Caculate total and average score of every course

3.Caculate total and average score of every student

4.Sort in descending order by score

5.Sort in ascending order by score

6.Sort in ascending order by number

7.Sort in dictionary order by name

8.Search by number

9.Search by name

10.Statistic analysis

11.List record

0.Exit

Please Input your choice:

6↙

Sort in ascending order by number:

11003001 lisi 87 82 89 258 86

11003002 dumo 48 50 67 165 55

11003003 ludi 75 78 80 233 78

11003004 zuma 65 69 72 206 69

11003005 heli 98 92 90 280 93

11003006 suyu 100 95 94 289 96

Management for Students’ scores

1.Input record

2.Caculate total and average score of every course

3.Caculate total and average score of every student

4.Sort in descending order by score

5.Sort in ascending order by score

6.Sort in ascending order by number

7.Sort in dictionary order by name

8.Search by number

9.Search by name

10.Statistic analysis

11.List record

0.Exit

Please Input your choice:

7↙

Sort in dictionary order by name:

11003002 dumo 48 50 67 165 55

11003005 heli 98 92 90 280 93

11003001 lisi 87 82 89 258 86

11003003 ludi 75 78 80 233 78

11003006 suyu 100 95 94 289 96

11003004 zuma 65 69 72 206 69

Management for Students’ scores

1.Input record

2.Caculate total and average score of every course

3.Caculate total and average score of every student

4.Sort in descending order by score

5.Sort in ascending order by score

6.Sort in ascending order by number

7.Sort in dictionary order by name

8.Search by number

9.Search by name

10.Statistic analysis

11.List record

0.Exit

Please Input your choice:

8↙

Input the number you want to search:

11003007↙

Not found!

Management for Students’ scores

1.Input record

2.Caculate total and average score of every course

3.Caculate total and average score of every student

4.Sort in descending order by score

5.Sort in ascending order by score

6.Sort in ascending order by number

7.Sort in dictionary order by name

8.Search by number

9.Search by name

10.Statistic analysis

11.List record

0.Exit

Please Input your choice:

8↙

Input the number you want to search:

11003004↙

11003004 zuma 65 69 72 206 69

Management for Students’ scores

1.Input record

2.Caculate total and average score of every course

3.Caculate total and average score of every student

4.Sort in descending order by score

5.Sort in ascending order by score

6.Sort in ascending order by number

7.Sort in dictionary order by name

8.Search by number

9.Search by name

10.Statistic analysis

11.List record

0.Exit

Please Input your choice:

9↙

Input the name you want to search:

lili↙

Not found!

Management for Students’ scores

1.Input record

2.Caculate total and average score of every course

3.Caculate total and average score of every student

4.Sort in descending order by score

5.Sort in ascending order by score

6.Sort in ascending order by number

7.Sort in dictionary order by name

8.Search by number

9.Search by name

10.Statistic analysis

11.List record

0.Exit

Please Input your choice:

9↙

Input the name you want to search:

lisi↙

11003001 lisi 87 82 89 258 86

Management for Students’ scores

1.Input record

2.Caculate total and average score of every course

3.Caculate total and average score of every student

4.Sort in descending order by score

5.Sort in ascending order by score

6.Sort in ascending order by number

7.Sort in dictionary order by name

8.Search by number

9.Search by name

10.Statistic analysis

11.List record

0.Exit

Please Input your choice:

10↙

For course 1:

<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%

For course 2:

<60 1 16.67%

60-69 1 16.67%

70-79 1 16.67%

80-89 1 16.67%

90-99 2 33.33%

100 0 0.00%

For course 3:

<60 0 0.00%

60-69 1 16.67%

70-79 1 16.67%

80-89 2 33.33%

90-99 2 33.33%

100 0 0.00%

Management for Students’ scores

1.Input record

2.Caculate total and average score of every course

3.Caculate total and average score of every student

4.Sort in descending order by score

5.Sort in ascending order by score

6.Sort in ascending order by number

7.Sort in dictionary order by name

8.Search by number

9.Search by name

10.Statistic analysis

11.List record

0.Exit

Please Input your choice:

11↙

11003002 dumo 48 50 67 165 55

11003005 heli 98 92 90 280 93

11003001 lisi 87 82 89 258 86

11003003 ludi 75 78 80 233 78

11003006 suyu 100 95 94 289 96

11003004 zuma 65 69 72 206 69

Management for Students’ scores

1.Input record

2.Caculate total and average score of every course

3.Caculate total and average score of every student

4.Sort in descending order by score

5.Sort in ascending order by score

6.Sort in ascending order by number

7.Sort in dictionary order by name

8.Search by number

9.Search by name

10.Statistic analysis

11.List record

0.Exit

Please Input your choice:

12↙

Input error!

Management for Students’ scores

1.Input record

2.Caculate total and average score of every course

3.Caculate total and average score of every student

4.Sort in descending order by score

5.Sort in ascending order by score

6.Sort in ascending order by number

7.Sort in dictionary order by name

8.Search by number

9.Search by name

10.Statistic analysis

11.List record

0.Exit

Please Input your choice:

0↙

End of program!

输入格式:

( 1 ) 录入学生的人数:

             **要求输入数据格式为:"%d"**提示信息为:"Input student number(n<30):\n"

( 2 )录入课程数:

           **要求输入数据格式为:"%d"**提示信息为:"Input course number(m<=%d):\n"

( 3 )录入每个学生的学号、姓名和考试成绩:

           **要求学号、姓名的输入数据格式为:"%ld%s"**要求考试成绩的输入数据格式为:"%f"**提示信息为:"Input student's ID, name and score:\n"

输出格式:

计算每门课程的总分和平均分:

          **要求输出总分与平均分格式为:"course %d:sum=%.0f,aver=%.0f\n"

计算每个学生的总分和平均分:

          **要求输出总分与平均分格式为:"student %d:sum=%.0f,aver=%.0f\n"

按成绩由高到低排出名次表:

          **要求学号、姓名的输出格式为:"%ld\t%s\t"**要求成绩的输出格式为:"%.0f\t"**要求总分及平均分的输出格式为:"%.0f\t%.0f\n"**提示信息为:"Sort in descending order by score:\n"

按成绩由低到高排出名次表:

          **要求学号、姓名的输出格式为:"%ld\t%s\t"**要求成绩的输出格式为:"%.0f\t"**要求总分及平均分的输出格式为:"%.0f\t%.0f\n"**提示信息为:"Sort in ascending order by score:\n"

按学号由小到大排出成绩表:

          **要求学号、姓名的输出格式为:"%ld\t%s\t"**要求成绩的输出格式为:"%.0f\t"**要求总分及平均分的输出格式为:"%.0f\t%.0f\n"**提示信息为:"Sort in ascending order by number:\n"

按姓名的字典顺序排出成绩表

          **要求学号、姓名的输出格式为:"%ld\t%s\t"**要求成绩的输出格式为:"%.0f\t"**要求总分及平均分的输出格式为:"%.0f\t%.0f\n"**提示信息为:"Sort in dictionary order by name:\n"

按学号查询学生排名及其考试成绩:

           **如果未查到此学号的学生,提示信息为:"Not found!\n";**如果查询到该学生# 要求学号、姓名的输出格式为:"%ld\t%s\t"# 要求成绩的输出格式为:"%.0f\t"# 要求总分及平均分的输出格式为:"%.0f\t%.0f\n"**提示信息为:"Input the number you want to search:\n"

按姓名查询学生排名及其考试成绩;

           **如果未查到此学号的学生,提示信息为:"Not found!\n";**如果查询到该学生# 要求学号、姓名的输出格式为:"%ld\t%s\t"# 要求成绩的输出格式为:"%.0f\t"# 要求总分及平均分的输出格式为:"%.0f\t%.0f\n"**提示信息为:"Input the name you want to search:\n"

按优秀(90100)、良好(8089)、中等(7079)、及格(6069)、不及格(0~59)5个类别,统计每个类别的人数以及所占的百分比:

            **成绩<60输出提示格式为:"<60\t%d\t%.2f%%\n";**成绩=100输出格式为:"%d\t%d\t%.2f%%\n";**其他要求输出百分比格式为:"%d-%d\t%d\t%.2f%%\n"**提示信息为: "For course %d:\n"

输出每个学生的学号、姓名、考试成绩,以及课程总分和平均分

          **要求学号、姓名的输出格式为:"%ld\t%s\t"**要求成绩的输出格式为:"%.0f\t"**要求总分及平均分的输出格式为:"%.0f\t%.0f\n"

选择退出(菜单项0)

            **提示信息:"End of program!"

菜单项选择错误(不在0-11之间)

            **提示信息:"Input error!\n"
#include <stdio.h>
#include <string.h>
#define   MAX_LEN  10                       /* 字符串最大长度 */
#define   STU_NUM 30                       /* 最多的学生人数 */
#define   COURSE_NUM 6                     /* 最多的考试科目数 */
int   Menu(void);
void  ReadScore(long num[], char name[][MAX_LEN],float score[][COURSE_NUM], int n, int m);
void AverSumofEveryCourse(float score[][COURSE_NUM], int n, int m);
void AverSumofEveryStudent(float score[][COURSE_NUM], int n, int m,float  sum[STU_NUM], float aver[STU_NUM]);
int   Descending(float a, float b);
int   Ascending(float a, float b);
void  SwapFloat(float *x, float *y);
void  SwapLong(long *x, long *y);
void  SwapChar(char x[], char y[]);
void  SortbyScore(long num[], char name[][MAX_LEN],float score[][COURSE_NUM], float  sum[], float aver[],int n, int m, int (*compare)(float a, float b));
void  AsSortbyNum(long num[], char name[][MAX_LEN],float score[][COURSE_NUM], float  sum[], float aver[],int n, int m);
void  SortbyName(long num[], char name[][MAX_LEN],float score[][COURSE_NUM], float  sum[], float aver[],int n, int m);
void  SearchbyNum(long num[], char name[][MAX_LEN],float score[][COURSE_NUM], float  sum[], float aver[],int n, int m);
void  SearchbyName(long num[], char name[][MAX_LEN],float score[][COURSE_NUM], float  sum[], float aver[],int n, int m);
void  StatisticAnalysis(float score[][COURSE_NUM], int n, int m);
void  PrintScore(long num[], char name[][MAX_LEN],float score[][COURSE_NUM], float  sum[], float aver[],int n, int m) ;
int main()
{int n, p, m;long num[STU_NUM];char name[STU_NUM][MAX_LEN];float score[STU_NUM][COURSE_NUM], sum[STU_NUM], aver[STU_NUM];printf("Input student number(n<30):\n");scanf("%d", &n);Menu();while(scanf("%d", &p)!=EOF && p!=0){switch(p){case 1:printf("Input course number(m<=%d):\n", n);scanf("%d", &m);printf("Input student's ID, name and score:\n");ReadScore(num, name, score, n, m);break;case 2:AverSumofEveryCourse(score, n, m);break;case 3:AverSumofEveryStudent(score, n, m, sum, aver);break;case 4:printf("Sort in descending order by score:\n");SortbyScore(num, name, score, sum, aver, n, m, Descending);break;case 5:printf("Sort in ascending order by score:\n");SortbyScore(num, name, score, sum, aver, n, m, Ascending);break;case 6:printf("Sort in ascending order by number:\n");AsSortbyNum(num, name, score, sum, aver, n, m);break;case 7:printf("Sort in dictionary order by name:\n");SortbyName(num, name, score, sum, aver, n, m);break;case 8:printf("Input the number you want to search:\n");SearchbyNum(num, name, score, sum, aver, n, m);break;case 9:printf("Input the name you want to search:\n");SearchbyName(num, name, score, sum, aver, n, m);break;case 10:StatisticAnalysis(score, n, m);break;case 11:PrintScore(num, name, score, sum, aver, n, m);break;default:printf("Input error!\n");}Menu();}printf("End of program!");return 0;
}
int   Menu(void)
{printf("Management for Students' scores\n""1.Input record\n""2.Caculate total and average score of every course\n""3.Caculate total and average score of every student\n""4.Sort in descending order by score\n""5.Sort in ascending order by score\n""6.Sort in ascending order by number\n""7.Sort in dictionary order by name\n""8.Search by number\n""9.Search by name\n""10.Statistic analysis\n""11.List record\n""0.Exit\n""Please Input your choice:\n");return 0;
}
void  ReadScore(long num[], char name[][MAX_LEN],float score[][COURSE_NUM], int n, int m)
{int i, r;for(i=0;i<n;i++){scanf("%ld%s", &num[i], name[i]);for(r=0;r<m;r++){scanf("%f", &score[i][r]);}}return ;
}
void AverSumofEveryCourse(float score[][COURSE_NUM], int n, int m)
{int i, r;float sum=0;for(i=0;i<m;i++){sum = 0;for(r=0;r<n;r++){sum = sum + score[r][i];}printf("course %d:sum=%.0f,aver=%.0f\n", i+1, sum, sum/(float)n);}return ;
}
void AverSumofEveryStudent(float score[][COURSE_NUM], int n, int m,float  sum[STU_NUM], float aver[STU_NUM])
{int i, r;memset(sum, 0, sizeof(float)*STU_NUM);for(i=0;i<n;i++){for(r=0;r<m;r++){sum[i] = sum[i] + score[i][r];}aver[i] = sum[i] / (float)m;}for(i=0;i<n;i++){printf("student %d:sum=%.0f,aver=%.0f\n", i+1, sum[i], aver[i]);}return ;
}
void  SwapFloat(float *x, float *y)
{float term;term = *x;*x = *y;*y = term;return ;
}
void  SwapLong(long *x, long *y)
{long term;term = *x;*x = *y;*y = term;return ;
}
void  SwapChar(char x[], char y[])
{char c[MAX_LEN];strcpy(c, x);strcpy(x, y);strcpy(y, c);return ;
}
int   Descending(float a, float b)
{if(a < b)return 1;return 0;
}
int   Ascending(float a, float b)
{if(a > b)return 1;return 0;
}
void  SortbyScore(long num[], char name[][MAX_LEN],float score[][COURSE_NUM], float  sum[], float aver[],int n, int m, int (*compare)(float a, float b))
{int i, r, t;for(i=0;i<n;i++){for(r=0;r<n-1;r++){if((*compare)(sum[r], sum[r+1])){SwapLong(&num[r], &num[r+1]);SwapChar(name[r], name[r+1]);for(t=0;t<m;t++){SwapFloat(&score[r][t], &score[r+1][t]);}SwapFloat(&sum[r], &sum[r+1]);SwapFloat(&aver[r], &aver[r+1]);}}}for(i=0;i<n;i++){printf("%ld\t%s\t", num[i], name[i]);for(r=0;r<m;r++){printf("%.0f\t", score[i][r]);}printf("%.0f\t%.0f\n", sum[i], aver[i]);}return ;
}
void  AsSortbyNum(long num[], char name[][MAX_LEN],float score[][COURSE_NUM], float  sum[], float aver[],int n, int m)
{int i, r, t;for(i=0;i<n;i++){for(r=0;r<n-1;r++){if(num[r] > num[r+1]){SwapLong(&num[r], &num[r+1]);SwapChar(name[r], name[r+1]);for(t=0;t<m;t++){SwapFloat(&score[r][t], &score[r+1][t]);}SwapFloat(&sum[r], &sum[r+1]);SwapFloat(&aver[r], &aver[r+1]);}}}for(i=0;i<n;i++){printf("%ld\t%s\t", num[i], name[i]);for(r=0;r<m;r++){printf("%.0f\t", score[i][r]);}printf("%.0f\t%.0f\n", sum[i], aver[i]);}return ;
}
void  SortbyName(long num[], char name[][MAX_LEN],float score[][COURSE_NUM], float  sum[], float aver[],int n, int m)
{int i, r, t;for(i=0;i<n;i++){for(r=0;r<n-1;r++){if(strcmp(name[r], name[r+1]) > 0){SwapLong(&num[r], &num[r+1]);SwapChar(name[r], name[r+1]);for(t=0;t<m;t++){SwapFloat(&score[r][t], &score[r+1][t]);}SwapFloat(&sum[r], &sum[r+1]);SwapFloat(&aver[r], &aver[r+1]);}}}for(i=0;i<n;i++){printf("%ld\t%s\t", num[i], name[i]);for(r=0;r<m;r++){printf("%.0f\t", score[i][r]);}printf("%.0f\t%.0f\n", sum[i], aver[i]);}return ;
}
void  SearchbyNum(long num[], char name[][MAX_LEN],float score[][COURSE_NUM], float  sum[], float aver[],int n, int m)
{int i, r;long number;scanf("%ld", &number);for(i=0;i<n;i++){if(number%1000 == num[i]%1000){printf("%ld\t%s\t", num[i], name[i]);for(r=0;r<m;r++){printf("%.0f\t", score[i][r]);}printf("%.0f\t%.0f\n", sum[i], aver[i]);return ;}}printf("Not found!\n");return ;
}
void  SearchbyName(long num[], char name[][MAX_LEN],float score[][COURSE_NUM], float  sum[], float aver[],int n, int m)
{int i, r;char ch[MAX_LEN];scanf("%s", ch);for(i=0;i<n;i++){if(strcmp(ch, name[i]) == 0){printf("%ld\t%s\t", num[i], name[i]);for(r=0;r<m;r++){printf("%.0f\t", score[i][r]);}printf("%.0f\t%.0f\n", sum[i], aver[i]);return ;}}printf("Not found!\n");return ;
}
void  StatisticAnalysis(float score[][COURSE_NUM], int n, int m)
{int i, r;int x[COURSE_NUM][6];memset(x, 0, sizeof(x));for(i=0;i<n;i++){for(r=0;r<m;r++){if(score[i][r] < 60){x[r][0]++;}else if(score[i][r] < 70){x[r][1]++;}else if(score[i][r] < 80){x[r][2]++;}else if(score[i][r] < 90){x[r][3]++;}else if(score[i][r] < 100){x[r][4]++;}else {x[r][5]++;}}}for(r=0;r<m;r++){printf("For course %d:\n", r+1);printf("<60\t%d\t%.2f%%\n", x[r][0], (float)x[r][0]*100/(float)n);printf("%d-%d\t%d\t%.2f%%\n", 60, 69, x[r][1], (float)x[r][1]*100/(float)n);printf("%d-%d\t%d\t%.2f%%\n", 70, 79, x[r][2], (float)x[r][2]*100/(float)n);printf("%d-%d\t%d\t%.2f%%\n", 80, 89, x[r][3], (float)x[r][3]*100/(float)n);printf("%d-%d\t%d\t%.2f%%\n", 90, 99, x[r][4], (float)x[r][4]*100/(float)n);printf("%d\t%d\t%.2f%%\n", 100, x[r][5], (float)x[r][5]*100/(float)n);}return ;
}
void  PrintScore(long num[], char name[][MAX_LEN],float score[][COURSE_NUM], float  sum[], float aver[],int n, int m)
{int i, r, t;for(i=0;i<n;i++){for(r=0;r<n-1;r++){if(strcmp(name[r], name[r+1]) > 0){SwapLong(&num[r], &num[r+1]);SwapChar(name[r], name[r+1]);for(t=0;t<m;t++){SwapFloat(&score[r][t], &score[r+1][t]);}SwapFloat(&sum[r], &sum[r+1]);SwapFloat(&aver[r], &aver[r+1]);}}}for(i=0;i<n;i++){printf("%ld\t%s\t", num[i], name[i]);for(r=0;r<m;r++){printf("%.0f\t", score[i][r]);}printf("%.0f\t%.0f\n", sum[i], aver[i]);}return ;
}

2寻找最高分成绩的学生(4分)

下面程序的功能是用动态数组编程输入任意m个班学生(每班n个学生)的某门课的成绩,计算最高分,并指出具有该最高分成绩的学生是第几个班的第几个学生。其中,m和n的值由用户从键盘任意输入(不限定m和n的上限值)。程序的运行结果如下所示:

Input array size m,n:

3,4↙

Input 3*4 array:

80 82 63 74↙

60 81 75 68↙

87 91 78 92↙

maxScore = 92, class = 3, number = 4

按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。

#include  <stdio.h>
#include  <stdlib.h>
void InputScore(int *p, int m, int n);
int  FindMax(int *p, int m, int n, int *pRow, int *pCol);
int main()
{ int  *pScore, m, n, maxScore, row, col;printf("Input array size m,n:\n");scanf("%d,%d", &m, &n);  ___________________; /* 申请动态内存 */if (pScore == NULL) {printf("No enough memory!\n");exit(0); }InputScore(pScore, m, n);maxScore = FindMax(________________);printf("maxScore = %d, class = %d, number = %d\n", maxScore, row+1, col+1);                              free(pScore);                                      /* 释放动态内存 */return 0;
}/* 函数功能:输入m行n列二维数组的值 */
void InputScore(_______, int m, int n)
{int i, j;printf("Input %d*%d array:\n", m, n);for (i=0; i<m; i++){for (j=0; j<n; j++){scanf("%d", _________); }}
}
/*  函数功能:计算任意m行n列二维数组中元素的最大值,并指出其所在行列下标值 */
int  FindMax(int *p, int m, int n, int *pRow, int *pCol)
{int  i, j, max = p[0];__________; __________;                   for (i=0; i<m; i++){for (j=0; j<n; j++){if (___________)        {max = p[i*n+j];*pRow = i;       /*记录行下标*/*pCol = j;             /*记录列下标*/} }  }  return max;
}

输入格式:

输入数组大小格式:"%d,%d"

输入数组元素格式:"%d"

输出格式:

输入数组大小的提示信息:“Input array size m,n:\n”

输入数组元素的提示信息:“Input %d*%d array:\n”

输出数据格式:“maxScore = %d, class = %d, number = %d\n”

#include  <stdio.h>
#include  <stdlib.h>
void InputScore(int *p, int m, int n);
int  FindMax(int *p, int m, int n, int *pRow, int *pCol);
int main()
{ int  *pScore, m, n, maxScore, row, col;printf("Input array size m,n:\n");scanf("%d,%d", &m, &n);  pScore = (int*)calloc(m, n*(sizeof(int))); /* 申请动态内存 */if (pScore == NULL) {printf("No enough memory!\n");exit(0); }InputScore(pScore, m, n);maxScore = FindMax(pScore, m, n, &row, &col);printf("maxScore = %d, class = %d, number = %d\n", maxScore, row+1, col+1);                              free(pScore);                                      /* 释放动态内存 */return 0;
}/* 函数功能:输入m行n列二维数组的值 */
void InputScore(int *p, int m, int n)
{int i, j;printf("Input %d*%d array:\n", m, n);for (i=0; i<m; i++){for (j=0; j<n; j++){scanf("%d", &p[i*n+j]);}}
}
/*  函数功能:计算任意m行n列二维数组中元素的最大值,并指出其所在行列下标值 */
int  FindMax(int *p, int m, int n, int *pRow, int *pCol)
{int  i, j, max = p[0];*pRow = 0; *pCol = 0;                   for (i=0; i<m; i++){for (j=0; j<n; j++){if (max < p[i*n+j])      {max = p[i*n+j];*pRow = i;       /*记录行下标*/*pCol = j;             /*记录列下标*/} }  }  return max;
}

3程序改错(4分)

下面程序的功能是输入m个学生(最多为30人)n门课程(最多为5门)的成绩,然后计算并打印每个学生各门课的总分和平均分。其中,m和n的值由用户从键盘输入。希望的运行结果为:

程序运行结果如下:

How many students?

4↙

How many courses?

3↙

Input scores:

60 60 60↙

70 70 70↙

80 80 80↙

90 90 90↙

Result:

60 60 60 180 60.0

70 70 70 210 70.0

80 80 80 240 80.0

90 90 90 270 90.0

目前程序存在错误,请找出错误所在并加以改正。

#include  <stdio.h>
#define STUD   30      /* 最多可能的学生人数 */
#define COURSE 5       /* 最多可能的考试科目数 */
void  Total(int *pScore, int sum[], float aver[], int m, int n);
void  Print(int *pScore, int sum[], float aver[], int m, int n);
int main()
{int     i, j, m, n, score[STUD][COURSE], sum[STUD];float   aver[STUD];printf("How many students?");scanf("%d", &m);printf("How many courses?");scanf("%d", &n);printf("Input scores:\n");for (i=0; i<m; i++){for (j=0; j<n; j++){scanf("%d", &score[i][j]);}}Total(*score, sum, aver, m, n);Print(*score, sum, aver, m, n);return 0;
}
void  Total(int *pScore, int sum[], float aver[], int m, int n)
{int  i, j;for (i=0; i<m; i++){sum[i] = 0;for (j=0; j<n; j++){sum[i] = sum[i] + pScore[i*n+j];}aver[i] = (float) sum[i] / n;}
}
void  Print(int *pScore, int sum[], float aver[], int m, int n)
{int  i, j;printf("Result:\n");for (i=0; i<m; i++){for (j=0; j<n; j++){printf("%4d\t", pScore[i*n+j]);}printf("%5d\t%6.1f\n", sum[i], aver[i]);}
}

输入格式:

学生人数、课程数、成绩的输入格式都是: “%d”

输出格式:

输入学生人数提示信息:“How many students?\n”

输入课程数提示信息:“How many courses?\n”

输入成绩的提示信息:“Input scores:\n”

输出结果的提示信息: “Result:\n”

每个学生每门课成绩的输出格式: “%4d”

总分和平均分的输出格式: “%5d%6.1f\n”

#include  <stdio.h>
#define STUD   30      /* 最多可能的学生人数 */
#define COURSE 5       /* 最多可能的考试科目数 */
void  Total(int *pScore, int sum[], float aver[], int m, int n);
void  Print(int *pScore, int sum[], float aver[], int m, int n);
int main()
{int     i, j, m, n, score[STUD][COURSE], sum[STUD];float   aver[STUD];printf("How many students?\n");scanf("%d", &m);printf("How many courses?\n");scanf("%d", &n);printf("Input scores:\n");for (i=0; i<m; i++){for (j=0; j<n; j++){scanf("%d", &score[i][j]);}}Total(*score, sum, aver, m, n);Print(*score, sum, aver, m, n);return 0;
}
void  Total(int *pScore, int sum[], float aver[], int m, int n)
{int  i, j;for (i=0; i<m; i++){sum[i] = 0;for (j=0; j<n; j++){sum[i] = sum[i] + pScore[i*COURSE+j];}aver[i] = (float) sum[i] / n;}
}
void  Print(int *pScore, int sum[], float aver[], int m, int n)
{int  i, j;printf("Result:\n");for (i=0; i<m; i++){for (j=0; j<n; j++){printf("%4d", pScore[i*COURSE+j]);}printf("%5d%6.1f\n", sum[i], aver[i]);}
}

4矩阵转置(4分)

下面程序的功能是用二维数组的列指针作为函数实参,计算并输出m×n阶矩阵的转置矩阵。其中,m和n的值由用户从键盘输入。已知m和n的值都不超过10。程序的运行结果如下所示:

Input m, n:

4,5↙

Input 4*5 matrix:

45 89 90 26 65↙

21 34 56 77 99↙

31 25 62 50 46↙

78 69 84 73 15↙

The transposed matrix is:

45 21 31 78

89 34 25 69

90 56 62 84

26 77 50 73

65 99 46 15

按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。

#include <stdio.h>
#define M 10
#define N 10
void Transpose(int *a, int *at, int m, int n);
void InputMatrix(int *a, int m, int n);
void PrintMatrix(int *at, int n, int m);
int main()
{int s[M][N], st[N][M], m, n;printf("Input m, n:");scanf("%d,%d", &m, &n);InputMatrix(____, m, n);Transpose(______________);printf("The transposed matrix is:\n");PrintMatrix(*st, n,  m); return 0;
}
/* 函数功能:计算m*n矩阵a的转置矩阵at */
void Transpose(int *a, int *at, int m, int n)
{ int i, j;for (i=0; i<m; i++){for (j=0; j<n; j++){_____________;}}
}
/* 函数功能:输入m*n矩阵a的值 */
void InputMatrix(int *a, int m, int n)
{int i, j;printf("Input %d*%d matrix:\n", m, n);for (i=0; i<m; i++){for (j=0; j<n; j++){scanf("%d", ____________); }}
}
/* 函数功能:输出n*m矩阵at的值 */
void PrintMatrix(int *at, int n, int m)
{int i, j;for (i=0; i<n; i++){for (j=0; j<m; j++){printf("%-5d", ____________);}printf("\n");}
}

输入格式:

矩阵大小的输入格式:"%d,%d"

矩阵元素的输入格式:"%d"

输出格式:

输入矩阵大小的提示信息:“Input m, n:\n”

输入矩阵元素的提示信息:“Input %d*%d matrix:\n”

输出转置矩阵的提示信息:“The transposed matrix is:\n”

转置后矩阵元素的输出格式:"%-5d"

#include <stdio.h>
#define M 10
#define N 10
void Transpose(int *a, int *at, int m, int n);
void InputMatrix(int *a, int m, int n);
void PrintMatrix(int *at, int n, int m);
int main()
{int s[M][N], st[N][M], m, n;printf("Input m, n:\n");scanf("%d,%d", &m, &n);InputMatrix(*s, m, n);Transpose(*s, *st, m, n);printf("The transposed matrix is:\n");PrintMatrix(*st, n,  m); return 0;
}
/* 函数功能:计算m*n矩阵a的转置矩阵at */
void Transpose(int *a, int *at, int m, int n)
{ int i, j;for (i=0; i<m; i++){for (j=0; j<n; j++){at[j*N+i] = a[i*N+j];}}
}
/* 函数功能:输入m*n矩阵a的值 */
void InputMatrix(int *a, int m, int n)
{int i, j;printf("Input %d*%d matrix:\n", m, n);for (i=0; i<m; i++){for (j=0; j<n; j++){scanf("%d", &a[i*N+j]);}}
}
/* 函数功能:输出n*m矩阵at的值 */
void PrintMatrix(int *at, int n, int m)
{int i, j;for (i=0; i<n; i++){for (j=0; j<m; j++){printf("%-5d", at[i*N+j]);}printf("\n");}
}

5在升序排序的数组中插入一个元素(4分)

题目内容:

用函数编程实现在一个按升序排序的数组中查找x应插入的位置,将x插入数组中,使数组元素仍按升序排列。

提示:插入(Insertion)是数组的基本操作之一。插入法排序算法的关键在于要找到正确的插入位置,然后依次移动插入位置及其后的所有元素,腾出这个位置放入待插入的元素。插入排序的原理如图所示:

程序运行结果示例:

Input array size:

5↙

Input array:

1 3 5 7 9↙

Input x:

4↙

After insert 4:

1 3 4 5 7 9

输入格式:

插入前数组元素个数、数组元素、待插入的元素x的输入格式都是:"%d"

输出格式:

输入插入前数组元素个数提示信息:“Input array size:\n”

输入插入前已按升序排序的数组元素提示信息:“Input array:\n”

输入待插入的元素x提示信息:“Input x:\n”

输出插入x后的数组元素提示信息:“After insert %d:\n”

数组元素输出格式:"%4d"

#include <stdio.h>
#define N 20
void Y(int a[N], int x, int n);
int main()
{int a[N], n, i, x;printf("Input array size:\n");scanf("%d", &n);printf("Input array:\n");for(i=0;i<n;i++){scanf("%d", &a[i]);}printf("Input x:\n");scanf("%d", &x);Y(a, x, n);printf("After insert %d:\n");for(i=0;i<n+1;i++){printf("%4d", a[i]);}return 0;
}
void Y(int a[N], int x, int n)
{int i, count=0;for(i=0;i<n;i++){if(a[i] < x) count++;}for(i=n;i>count;i--){a[i] = a[i-1];}a[count] = x;
}

6计算平均数、中位数和众数(4分)

在调查数据分析(Survey data analysis)中经常需要计算平均数、中位数和众数。用函数编程计算40个输入数据(是取值1—10之间的任意整数)的平均数(Mean)、中位数(Median)和众数(Mode)。中位数指的是排列在数组中间的数。众数是数组中出现次数最多的那个数(不考虑两个或两个以上的输入数据出现次数相同的情况)。

提示:计算中位数时,首先要调用排序函数对数组按升序进行排序,然后取出排序后数组中间位置的元素answer[n/2] ,就得到了中位数。如果数组元素的个数是偶数,那么中位数就等于数组中间那两个元素的算术平均值。众数就是40个输入数据中出现次数最多的那个数。计算众数时,首先要统计不同取值的输入数据出现的次数,然后找出出现次数最多的那个数据,这个数据就是众数(这里没有考虑两个或者两个以上的输入数据出现次数相同的情况)。

程序运行结果示例:

Input the feedbacks of 40 students:

10 9 10 8 7 6 5 10 9 8↙

8 9 7 6 10 9 8 8 7 7↙

6 6 8 8 9 9 10 8 7 7↙

9 8 7 9 7 6 5 9 8 7↙

Mean value=7

Median value=8

Mode value=8

输入格式: “%d”

输出格式:

输入数据的提示信息:“Input the feedbacks of 40 students:\n”

平均数输出:“Mean value=%d\n”

中位数输出:“Median value=%d\n”

众数输出: “Mode value=%d\n”

#include <stdio.h>
#include <string.h>
#define N 100
int Mean(int a[N]);
int Median(int a[N]);
int Mode(int a[N]);
int main()
{int i, a[N], x1, x2, x3;printf("Input the feedbacks of 40 students:\n");for(i=0;i<40;i++){scanf("%d", &a[i]);}x1 = Mean(a);x2 = Median(a);x3 = Mode(a);printf("Mean value=%d\n", x1);printf("Median value=%d\n", x2);printf("Mode value=%d\n", x3);return 0;
}
int Mean(int a[N])
{int i, sum=0;for(i=0;i<40;i++){sum = sum + a[i];}return (sum / 40);
}
int Median(int a[N])
{int i, r, term;for(i=0;i<40;i++){for(r=0;r<39;r++){if(a[r] > a[r+1]){term = a[r];a[r] = a[r+1];a[r+1] = term;}}}return ((a[19]+a[20])/2);
}
int Mode(int a[N])
{int max, pmax, i, x[10];memset(x, 0, sizeof(x));for(i=0;i<40;i++){x[a[i]]++;}max = x[0];pmax = 0;for(i=0;i<10;i++){if(max < x[i]){max = x[i];pmax = i;}}return pmax;
}

第十三周练兵区——编程题——不计入总分相关推荐

  1. 第十二周练兵区——编程题——不计入总分

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

  2. 第十四周练兵区——编程题——不计入总分

    1学生成绩管理系统V5.0(4分) 某班有最多不超过30人(具体人数由键盘输入)参加期末考试,最多不超过6门(具体门数由键盘输入).参考学生成绩管理系统V4.0,定义结构体类型,用结构体数组作函数参数 ...

  3. C语言程序设计精髓 第14周——结构设计的艺术 练兵区——编程题

    1学生成绩管理系统V5.0(4分) 题目内容: 某班有最多不超过30人(具体人数由键盘输入)参加期末考试,最多不超过6门(具体门数由键盘输入).参考学生成绩管理系统V4.0,定义结构体类型,用结构体数 ...

  4. C语言程序设计精髓 第13周——原来内存也可以这么玩,我是指针我怕谁 练兵区——编程题

    1学生成绩管理系统V4.0(4分) 题目内容: 某班有最多不超过30人(具体人数由键盘输入)参加期末考试,最多不超过6门(具体门数由键盘输入).参考学生成绩管理系统V3.0,用二维数组作函数参数编程实 ...

  5. C语言程序设计精髓 第2周——数字间的那些事儿,做点计算哈 练兵区——编程题

    1输出逆序数(3分) 题目内容: 从键盘任意输入一个3位整数,编程计算并输出它的逆序数(忽略整数前的正负号).例如,输入-123,则忽略负号,由123分离出其百位1.十位2.个位3,然后计算3100+ ...

  6. MOOC哈工大2020C语言程序设计精髓练兵区编程题第九周

    1 二分法求根(4分) 题目内容: 用二分法求下面的一元三次方程在区间[-10, 10]上误差不大于的根. 用二分法求方程的根的基本原理是:若函数有实根,则函数曲线应当在根x*这一点上与x轴有一个交点 ...

  7. 哈工大C语言Mooc 第九周 指针 测验编程题

    哈工大C语言Mooc 第九周 指针 练兵区–编程题 1二分法求根(4分) 题目内容: 用二分法求下面的一元三次方程在区间[-10, 10]上误差不大于的根. #include<stdio.h&g ...

  8. XJTU第十三周大计基编程作业

    1. 字符线性表 ________________________________________ 创建一个字符线性表(顺序表),并实现其基本操作(如插入,查找,删除,输出等).应用该线性表,将键盘输 ...

  9. 哈工大C语言程序设计精髓MOOC 第十三周编程题

    第13周--原来内存也可以这么玩,我是指针我怕谁 练兵区--编程题--不计入总分 2寻找最高分成绩的学生(4分) 题目内容: 下面程序的功能是用动态数组编程输入任意m个班学生(每班n个学生)的某门课的 ...

最新文章

  1. 服务器托管租用商考虑什么
  2. python语言特点有哪些-Python是什么?Python有什么特点?
  3. Vue.js 组件 处理边界情况
  4. vb链接mysql登录界面_求大神!有谁会用VB设计用户登陆界面连接到数据库
  5. glibc的头文件 linux_求助,编译glibc头文件时出错
  6. 6位数密码C++破解程序,并附上时间
  7. TCGA三个在线可视化网站
  8. sa密码不满足强密码要求_恢复丢失的SA密码
  9. .net与java之争
  10. 使用Python和Numpy进行波士顿房价预测任务(一)【深度学习入门_学习笔记】
  11. jQuery实现锚点滑动定位
  12. Google code android开源项目(一)
  13. Web网页设计作业html
  14. for循环 批处理 查找文件 详细信息 文件名
  15. excel柱状图自定x轴y轴_《excel柱状图自定x轴y轴》 如何更改EXCEL 图表中X轴的名称...
  16. 自动打卡php,使用腾讯云实现网易云自动打卡签到 | 小七呀w
  17. 网络管理员学习笔记_第三章 局域网技术与综合布线_003_局域网基础03
  18. selenium-java 实现QQ音乐自动登录获取cookie数据,爬取qq音乐会员资源和网易云音乐会员资源。实现任意网站的会员资源爬取
  19. 【无代码爬虫】web scraper 之 安装
  20. 软件变异体测试(mutation test)

热门文章

  1. 2018级《程序设计基础(B)II》期末上机考试 重现--SDUT
  2. 病毒性感冒和细菌性感冒怎样区分
  3. Java Day24
  4. 我的偶像Micheal.Jackson (MTV全集):本来是有一套Micheal的经典VCD的,但被朋友拿走再没还回来……...
  5. 超详细dns劫持解决办法分享
  6. [HDU 5755] Gambler Bo (高斯消元)
  7. 弘辽科技:淘宝四月份有满减活动吗?淘宝每个月都会有满减活动吗
  8. 关于电瓶车管理的思考
  9. 微创电生理通过注册:年营收1.9亿 微创批量生产上市企业
  10. 全球及中国燃气轮机行业产量规模预测及发展态势研究报告2021-2027年版