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

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

题目内容:

某班有最多不超过30人(具体人数由键盘输入)参加某门课程的考试,参考前面章节的“学生成绩管理系统V1.0”,用一维数组和函数指针作函数参数编程实现如下菜单驱动的学生成绩管理系统:

(1)录入每个学生的学号和考试成绩;

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

(3)按成绩由高到低排出名次表;

(4)按成绩由低到高排出名次表;

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

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

(7)按优秀(90~100)、良好(80~89)、中等(70~79)、及格(60~69)、不及格(0~59)5个类别,统计每个类别的人数以及所占的百分比;

(8)输出每个学生的学号、考试成绩。

要求程序运行后显示的菜单如下:

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.Search by number

7.Statistic analysis

8.List record

0.Exit

Please enter your choice:

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


程序运行结果示例:

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.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

1↙

Input student's ID and score:

11003001↙

87↙

11003005↙

98↙

11003003↙

75↙

11003002

48

11003004↙

65↙

11003006↙

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.Search by number

7.Statistic analysis

8.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.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

3↙

Sort in descending order by score:

11003006        100

11003005        98

11003001        87

11003003        75

11003004        65

11003002        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.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

4↙

Sort in ascending order by score:

11003002        48

11003004        65

11003003        75

11003001        87

11003005        98

11003006        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.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

5↙

Sort in ascending order by number:

11003001        87

11003002        48

11003003        75

11003004        65

11003005        98

11003006        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.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

6↙

Input the number you want to search:

11003004↙

11003004        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.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

7↙

<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.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

8↙

11003001        87

11003002        48

11003003        75

11003004        65

11003005        98

11003006        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.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

9↙

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.Search by number

7.Statistic analysis

8.List record

0.Exit

Please Input your choice:

0↙

End of program!


输入格式:

( 1 ) 录入学生的人数:

                 **输入数据格式为:"%d"

                 **提示信息为:"Input student number(n<30):\n"

( 2 )录入每个学生的学号和考试成绩: 

               **输入数据格式为:"%ld%f"

               **提示信息为:"Input student's ID and score:\n"

( 3 )录入待查询学生的学号:

               **输入数据格式为:"%ld"

输出格式:

  • 计算课程的总分和平均分:

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

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

              **输出格式为:"%ld\t%.0f\n"

              **提示信息为:"Sort in descending order by score:\n"

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

              **输出格式为:"%ld\t%.0f\n"

              **提示信息为:"Sort in ascending order by score:\n"

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

              **输出格式为:"%ld\t%.0f\n"

              **提示信息为:"Sort in ascending order by number:\n"

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

               **查询学号输入的提示信息:"Input the number you want to search:\n"

               **如果未查到此学号的学生,提示信息为:"Not found!\n";

               **如果查询到该学生,要求输出格式为:"%ld\t%.0f\n"

  • 按优秀(90~100)、良好(80~89)、中等(70~79)、及格(60~69)、不及格(0~59)5个类别,统计每个类别的人数以及所占的百分比:

                **成绩<60的输出格式为:"<60\t%d\t%.2f%%\n";

                **成绩=100的输出格式为:"%d\t%d\t%.2f%%\n";

                **其他要求输出百分比格式为:"%d-%d\t%d\t%.2f%%\n" 

  • 用户输入的菜单项超出0-8的选择范围,输出错误提示信息:"Input error!\n"

为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。

时间限制:500ms内存限制:32000kb


#include<stdio.h>
typedef struct student
{
	long ID;
	float score;
	
} STU;

int main()
{
	int n; int k;float sum = 0;
	STU stu[30];
	printf("Input student number(n<30):\n");
	scanf("%d",&n);
	do {
		
		printf("Management for Students' scores\n");
		printf("1.Input record\n");
		printf("2.Caculate total and average score of course\n");
		printf("3.Sort in descending order by score\n");
		printf("4.Sort in ascending order by score\n");
		printf("5.Sort in ascending order by number\n");
		printf("6.Search by number\n");
		printf("7.Statistic analysis\n");
		printf("8.List record\n");
		printf("0.Exit\n");
		printf("Please Input your choice:\n");
		scanf("%d",&k);
		if (k == 1)
		{printf("Input student's ID and score:\n");
			for (int i = 0; i < n; i++)
			{
				
				scanf("%ld%f", &stu[i].ID, &stu[i].score);
				sum += stu[i].score;
			}

		}
		else if (k >= 9 || k < 0)
		{
			printf("Input error!\n");
		}
		else if(k == 0)
		{
			printf("End of program!");
			break;
		}
		else if (k == 2)
		{
			printf("sum=%.0f,aver=%.2f\n",sum,sum/n);
		}
		else if (k == 3)
		{
			printf("Sort in descending order by score:\n" );
			int q, w, e;float temp1; long temp2;
			for (q = 0; q < n - 1; q++)
			{
				e = q;
				for (w = q + 1; w < n; w++)
				{
					if (stu[w].score > stu[e].score)
					{
						e = w;
					}
				}
				if (e != q)
				{
					temp1 = stu[e].score; stu[e].score = stu[q].score; stu[q].score = temp1;
					temp2 = stu[e].ID; stu[e].ID = stu[q].ID; stu[q].ID = temp2;
				}
			}
			for (int i = 0; i < n; i++)
			{
				printf("%ld\t%.0f\n", stu[i].ID, stu[i].score);

			}
		}
		else if (k == 4) {
			printf("Sort in ascending order by score:\n");
			for (int ii = n - 1; ii >= 0; ii--)
			{
				printf("%ld\t%.0f\n", stu[ii].ID, stu[ii].score);

			}}
		else if(k == 5)
		{
			printf("Sort in ascending order by number:\n");
			int q1, w1, e1; float temp11; long temp21;
			for (q1 = 0; q1 < n - 1; q1++)
			{
				e1 = q1;
				for (w1= q1 + 1; w1 < n; w1++)
				{
					if (stu[w1].ID > stu[e1].ID)
					{
						e1 = w1;
					}
				}
				if (e1 != q1)
				{
					temp11 = stu[e1].score; stu[e1].score = stu[q1].score; stu[q1].score = temp11;
					temp21= stu[e1].ID; stu[e1].ID = stu[q1].ID; stu[q1].ID = temp21;
				}
			}
			for (int i = n-1; i>=0; i--)
			{
				printf("%ld\t%.0f\n", stu[i].ID, stu[i].score);

			}
			
		}
		else if (k == 6)
		{
			long num;
			int numx,count=0;
			printf("Input the number you want to search:\n");
			scanf("%ld",&num);
			for (int i = 0; i < n; i++)
			{
				if (stu[i].ID == num)
				{
					printf("%ld\t%.0f\n", stu[i].ID, stu[i].score);
					break;
				}
				count++;
			}
			if (count >= n)
			{
				printf("Not found!\n");
			}

		}
		else if (k == 7)
		{
			int i6=0,i7=0,i8=0,i9=0,i10=0,i11=0;
			for (int i = 0; i < n; i++)
			{
				
				if (stu[i].score < 60)
				{
					i6++;
				}
				else if (stu[i].score >= 60 && stu[i].score < 70)
				{
					i7++;
				}
				else if (stu[i].score >= 70 && stu[i].score < 80)
				{
					i8++;
				}
				else if (stu[i].score>=80&& stu[i].score<90){
					i9++;
				}
				else if(stu[i].score>=90&& stu[i].score<99)
				{
					i10++;
				}
				else if (stu[i].score == 100)
				{
					i11++;
				}
			}
			printf("<60\t%d\t%.2f%%\n", i6, (float)i6/ (float)n*100);
			printf("%d-%d\t%d\t%.2f%%\n",60,69, i7, (float)i7/ (float)n*100);
			printf("%d-%d\t%d\t%.2f%%\n",70,79, i8, (float)i8/ (float)n*100);
			printf("%d-%d\t%d\t%.2f%%\n",80,89, i9, (float)i9/ (float)n*100);
			printf("%d-%d\t%d\t%.2f%%\n",90,99,i10, (float)i10/ (float)n*100);
			printf("%d\t%d\t%.2f%%\n",100,i11,(float)i11/(float)n*100);
		}
		else if (k == 8)
		{
			int q11, w11, e11; float temp111; long temp211;
			for (q11 = 0; q11 < n - 1; q11++)
			{
				e11 = q11;
				for (w11 = q11 + 11; w11 < n; w11++)
				{
					if (stu[w11].ID > stu[e11].ID)
					{
						e11 = w11;
					}
				}
				if (e11 != q11)
				{
					temp111 = stu[e11].score; stu[e11].score = stu[q11].score; stu[q11].score = temp111;
					temp211 = stu[e11].ID; stu[e11].ID = stu[q11].ID; stu[q11].ID = temp211;
				}
			}
			for (int i = n - 1; i >= 0; i--)
			{
				printf("%ld\t%.0f\n", stu[i].ID, stu[i].score);

			}
		}
	} while (k != 0);
	






	return 0;
}


  • 6
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值