C语言之学生成绩管理系统

本人软工学生一枚,学艺不精。有不足之处请谅解 ^ _ ^
有什么问题还希望您能多批评指正,不吝指教。
蟹蟹你来看鸭~~

1.问题描述

某班有最多不超过30人(具体人数由键盘输入)参加数学、语文、英语考试,编程实现如下菜单驱动的学生成绩管理系统:
1)录入学生信息,包括学号、姓名、数学分数、语文分数、英语分数;
2)计算3门课程的总分以及平均分;
3)按学生成绩排序(需要2级子菜单:按什么成绩排升序还是降序);
4)按学号升序排列;
5)按姓名字典序排列;
6)按学号查询学生信息;
7)按姓名查询学生信息;
8)按优秀(90-100)、良好(80-89)、中等(70-79)、及格(60-69)、不及格(0-59)5个类别,统计每个类别的人数以及所占的百分比(需要子菜单:按什么成绩统计);
9)输出所有学生的学号、姓名、数学分数、语文分数、英语分数、总分、平均分。

涉及到的知识

计数控制的循环、条件控制的循环以及循环嵌套。
一维数组、二维数组作为函数参数。
字符串处理函数、字符串处理操作。

2.上代码

#include "string.h"
#include "stdio.h"
void rank(long long STU_ID[], char name[][10], float score[][4], int n)
{
	int i, j, k;
	float temp1;
	long long temp2;
	char temp[10];
	for (i = 0; i < n - 1; i++)
	{
		k = i;
		for (j = i + 1; j < n; j++)
		{
			if (score[j][3] > score[k][3])
				k = j;
		}
		if (k != i)
		{
			for (int t = 0; t <= 3; t++)
			{
				temp1 = score[k][t];
				score[k][t] = score[i][t];
				score[i][t] = temp1;

			}
			temp2 = STU_ID[k];
			STU_ID[k] = STU_ID[i];
			STU_ID[i] = temp2;
			strcpy(temp, name[k]);
			strcpy(name[k], name[i]);
			strcpy(name[i], temp);
		}
	}
}
void fun1(long long STU_ID[], char name[][10], float score[][4], int n)
{
	float a;
	printf("Input student's ID and name ,math,chinese,english score:\n");
	for (int i = 0; i < n; i++)
	{
		score[i][3] = 0;
		scanf("%lld", &STU_ID[i]);
		scanf("%s", name[i]);
		for (int j = 0; j < 3; j++)
		{
			scanf("%f", &a);
			while (a < 0 || a>100)
			{
				printf("输入错误!请输入正确的分数0-100\n");
				scanf("%f", &a);
			}
			score[i][j] = a;
			score[i][3] = score[i][3] + score[i][j];
		}
	}
}
void fun2(float score[][4], float sum[], float aver[], int n)
{
	for (int j = 0; j < 3; j++)
	{
		sum[j] = 0;
		for (int i = 0; i < n; i++)
		{
			sum[j] = sum[j] + score[i][j];
		}
		aver[j] = sum[j] / n;
		printf("course%d:sum=%.0f,aver=%.0f\n", j + 1, sum[j], aver[j]);
	}

}
void fun3(long long STU_ID[], char name[][10], float score[][4], int n)
{
	int i, j, k;
	float temp1;
	long long temp2;
	char temp[10];
	for (i = 0; i < n - 1; i++)
	{
		k = i;
		for (j = i + 1; j < n; j++)
		{
			if (score[j][3] > score[k][3])
				k = j;
		}
		if (k != i)
		{
			for (int t = 0; t <= 3; t++)
			{
				temp1 = score[k][t];
				score[k][t] = score[i][t];
				score[i][t] = temp1;

			}
			temp2 = STU_ID[k];
			STU_ID[k] = STU_ID[i];
			STU_ID[i] = temp2;
			strcpy(temp, name[k]);
			strcpy(name[k], name[i]);
			strcpy(name[i], temp);
		}
	}
	printf("总分排名\n\n");
	printf("学号      \t姓名\t数学\t语文\t英语\t总分\t平均分\t排名\n");
	for (i = 0; i < n; i++)
	{
		printf("%lld\t", STU_ID[i]);
		printf("%s\t", name[i]);
		for (int t = 0; t <= 3; t++)
		{
			printf("%.0f\t", score[i][t]);
		}
		printf("%.0f\t", score[i][3] / 3);
		printf("%d\n", i + 1);
	}

}
void fun_3(long long STU_ID[], char name[][10], float score[][4], int n)
{

	int i, j, k;
	float temp1;
	long long temp2;
	char temp[10];
	for (i = 0; i < n - 1; i++)
	{
		k = i;
		for (j = i + 1; j < n; j++)
		{
			if (score[j][3] < score[k][3])
				k = j;
		}
		if (k != i)
		{
			for (int t = 0; t <= 3; t++)
			{
				temp1 = score[k][t];
				score[k][t] = score[i][t];
				score[i][t] = temp1;

			}
			temp2 = STU_ID[k];
			STU_ID[k] = STU_ID[i];
			STU_ID[i] = temp2;
			strcpy(temp, name[k]);
			strcpy(name[k], name[i]);
			strcpy(name[i], temp);
		}
	}
	printf("总分逆向排名\n\n");
	printf("学号      \t姓名\t数学\t语文\t英语\t总分\t平均分\t排名\n");
	for (i = 0; i < n; i++)
	{
		printf("%lld\t", STU_ID[i]);
		printf("%s\t", name[i]);
		for (int t = 0; t <= 3; t++)
		{
			printf("%.0f\t", score[i][t]);
		}
		printf("%.0f\t", score[i][3] / 3);
		printf("%d\n",n-i);
	}

}
void fun4(long long STU_ID[], char name[][10], float score[][4], int n)
{
	int i, j, k;
	float temp1;
	long long temp2;
	char temp[10];
	for (i = 0; i < n - 1; i++)
	{
		k = i;
		for (j = i + 1; j < n; j++)
		{
			if (STU_ID[j] < STU_ID[k])
				k = j;
		}
		if (k != i)
		{
			for (int t = 0; t <= 3; t++)
			{
				temp1 = score[k][t];
				score[k][t] = score[i][t];
				score[i][t] = temp1;

			}
			temp2 = STU_ID[k];
			STU_ID[k] = STU_ID[i];
			STU_ID[i] = temp2;
			strcpy(temp, name[k]);
			strcpy(name[k], name[i]);
			strcpy(name[i], temp);
		}
	}
	printf("学号排名\n\n");
	printf("学号      \t姓名\t数学\t语文\t英语\t总分\t平均分\n");
	for (i = 0; i < n; i++)
	{
		printf("%lld\t", STU_ID[i]);
		printf("%s\t", name[i]);
		for (int t = 0; t <= 3; t++)
		{
			printf("%.0f\t", score[i][t]);
		}
		printf("%.0f\t", score[i][3] / 3);
		printf("\n");
	}

}
void fun_4(long long STU_ID[], char name[][10], float score[][4], int n)
{
	int i, j;
	float temp1;
	long long temp2;
	char temp[10];
	for (i = 0; i < n - 1; i++)
	{
		for (j = i + 1; j < n; j++)
		{
			if (strcmp(name[j], name[i]) < 0)
			{
				for (int t = 0; t <= 3; t++)
				{
					temp1 = score[j][t];
					score[j][t] = score[i][t];
					score[i][t] = temp1;

				}
				temp2 = STU_ID[j];
				STU_ID[j] = STU_ID[i];
				STU_ID[i] = temp2;
				strcpy(temp, name[j]);
				strcpy(name[j], name[i]);
				strcpy(name[i], temp);
			}

		}

	}
	printf("姓名排名\n\n");
	printf("学号      \t姓名\t数学\t语文\t英语\t总分\t平均分\n");
	for (i = 0; i < n; i++)
	{
		printf("%lld\t", STU_ID[i]);
		printf("%s\t", name[i]);
		for (int t = 0; t <= 3; t++)
		{
			printf("%.0f\t", score[i][t]);
		}
		printf("%.0f\t", score[i][3] / 3);
		printf("\n");
	}
}
void fun5(long long STU_ID[], char name[][10], float score[][4], int n)
{
	long long number;
	rank(STU_ID, name, score, n);
	printf("Input the number you want to scarch:");
	scanf("%lld", &number);
	int flag = 0;
	for (int i = 0; i < n; i++)
	{
		if (STU_ID[i] == number)
		{
			printf("学号      \t姓名\t数学\t语文\t英语\t总分\t平均分\t排名\n");
			printf("%lld\t", STU_ID[i]);
			printf("%s\t", name[i]);
			for (int t = 0; t <= 3; t++)
			{
				printf("%.0f\t", score[i][t]);
			}
			printf("%.0f\t", score[i][3] / 3);
			printf("%d\n", i + 1);
			flag = 1;
		}
	}
	if (flag == 0)
		printf("\nNot found!\n");

}
void fun_5(long long STU_ID[], char name[][10], float score[][4], int n)
{
	char temp[10];
	int i;
	rank(STU_ID, name, score, n);
	printf("Input the name you want to scarch:");
	scanf("%s", temp);
	int flag = 0;
	for (i = 0; i < n; i++)
	{
		if (strcmp(name[i], temp) == 0)
		{
			printf("学号      \t姓名\t数学\t语文\t英语\t总分\t平均分\t排名\n");
			printf("%lld\t", STU_ID[i]);
			printf("%s\t", name[i]);
			for (int t = 0; t <= 3; t++)
			{
				printf("%.0f\t", score[i][t]);
			}
			printf("%.0f\t", score[i][3] / 3);
			printf("%d\n", i + 1);
			flag = 1;
		}
	}
	if (flag == 0)
		printf("\nNot found!\n");

}
void fun6(float score[][4], int n)
{
	int t[5];
	int i, j, total;
	for (j = 0; j < 3; j++)
	{
		printf("course:%d\n", j + 1);
		for (int k = 0; k < 5; k++)
		{
			t[k] = 0;
		}
		for (i = 0; i < n; i++)
		{
			if (score[i][j] >= 0 && score[i][j] < 60) t[0]++;
			else if (score[i][j] < 70) t[1]++;
			else if (score[i][j] < 80) t[2]++;
			else if (score[i][j] < 90) t[3]++;
			else if (score[i][j] < 100) t[4]++;
		}
		printf("<60\t%d\t%.2f%%\n", t[0], (float)t[0] / n * 100);
		printf("60-69\t%d\t%.2f%%\n", t[1], (float)t[1] / n * 100);
		printf("70-79\t%d\t%.2f%%\n", t[2], (float)t[2] / n * 100);
		printf("80-89\t%d\t%.2f%%\n", t[3], (float)t[3] / n * 100);
		printf("90-100\t%d\t%.2f%%\n", t[4], (float)t[4] / n * 100);

	}
}
void fun7(long long STU_ID[], char name[][10], float score[][4], int n)
{
	int i, j, k;
	float temp1;
	long long temp2;
	char temp[10];
	for (i = 0; i < n - 1; i++)
	{
		k = i;
		for (j = i + 1; j < n; j++)
		{
			if (STU_ID[j] > STU_ID[k])
				k = j;
		}
		if (k != i)
		{
			for (int t = 0; t <= 3; t++)
			{
				temp1 = score[k][t];
				score[k][t] = score[i][t];
				score[i][t] = temp1;

			}
			temp2 = STU_ID[k];
			STU_ID[k] = STU_ID[i];
			STU_ID[i] = temp2;
			strcpy(temp, name[k]);
			strcpy(name[k], name[i]);
			strcpy(name[i], temp);
		}
	}
	printf("成绩单\n\n");
	printf("学号      \t姓名\t数学\t语文\t英语\t总分\t平均分\n");
	for (i = 0; i < n; i++)
	{
		printf("%lld\t", STU_ID[i]);
		printf("%s\t", name[i]);
		for (int t = 0; t <= 3; t++)
		{
			printf("%.0f\t", score[i][t]);
		}
		printf("%.0f\t", score[i][3] / 3);
		printf("\n");
	}

}
int main()
{
	long long STU_ID[30];
	char name[30][10];
	float score[30][4];
	float sum[4];
	float aver[4];
	int n = 0;
	int a = -1;
	int ha;
	printf("Please input student number.\n\n");
	scanf("%d", &n);
	while (a != 0)
	{
		printf("\n*************************\n");
		printf("1.Input record\n");
		printf("2.Caculate total and average score of course\n");
		printf("3.Sort in  order by score\n");
		printf("4.Sort in ascending order by unmber\n");
		printf("5.Sort in dictionary order by name\n");
		printf("6.search by number\n");
		printf("7.search by name\n");
		printf("8.Statistic analysis\n");
		printf("9.List record\n");
		printf("0.Exit\n");
		printf("*************************\n");
		printf("请输入功能号0-9:");
		scanf("%d", &a);
		while (a < 0 || a>9)
		{
			printf("\n输入错误!请输入正确的功能号0-9:");
			scanf("%d", &a);
		}

		if (a == 1)
			fun1(STU_ID, name, score, n);
		else if (a == 2)
			fun2(score, sum, aver, n);
		else if (a == 3)
		{
		
			ha = -1;
			while (ha != 0)
			{
				printf("1.Sort in descending order by score\n");
				printf("2.Sort in ascending order by score\n");
				printf("请输入功能号1,2:");
				scanf("%d", &ha);
				while (ha < 0 || ha>2)
				{
					printf("\n输入错误!请输入正确的功能号1,2:");
					scanf("%d", &ha);
				}
				if (ha == 1)
				{
					fun3(STU_ID, name, score, n);
					break;
				}
				else if (ha == 2)
				{
					fun_3(STU_ID, name, score, n);
					break;
				}
			}
		}
		else if (a == 4)
			fun4(STU_ID, name, score, n);
		else if (a == 5)
			fun_4(STU_ID, name, score, n);
		else if (a == 6)
			fun5(STU_ID, name, score, n);
		else if (a == 7)
			fun_5(STU_ID, name, score, n);
		else if (a == 8)
			fun6(score, n);
		else if (a == 9)
			fun7(STU_ID, name, score, n);
		
	}

	return 0;
}

3.运行结果部分截图

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
简要的需求分析: 已经提供的数据:   <1> 班级学生名单:学生的学号和姓名已经分别存储在以学生所在班级命名的文本文件中,每行存储一个学生的学号和姓名,中间用一个空格分隔。例如:2010级网络工程1班.txt文件中存放该班学生名单。内容为:   201030720102 陈纯   201030720103 陈娟娟   201030720104 陈伟健   201030720105 陈伊纯   ……   <2> 开设课程保存在名为:course.txt的文本文件中,每行存放一门课程的名称,如:   面向对象程序设计   操作系统   数据库系统      实现以下功能,所有功能以图形用户界面完成。   <1> 新建课程考试成绩单,功能描述如下: 程序界面显示已经开设的课程(从course.txt中读取),用户选择本次输入的课程。 用户选择为哪个班输入成绩(即选择相应班的名单文件)。如果该班的成绩已经输入(已经存在对应成绩单文件),则提示无需输入。 程序提供界面为该班的每个学生输入考试成绩。 输入的成绩单以对象文件格式存储到文件中,文件命名为:班级-课程名.dat。例如:2010级网络工程1班-面向对象程序设计.dat。   <2> 打开课程考试成绩单,功能描述如下: 用户选择打开的成绩单文件,程序打开并读取成绩单文件内容,并显示在界面中。   <3> 修改课程考试成绩单,功能描述如下: 打开某班某课程的成绩单后,可以选择修改其中某个或某几个考试成绩,并保存。   <4> 课程考试成绩分析,功能描述如下: 即打开某班某课程的成绩单后,点击成绩分析按钮或菜单,显示如下分析内容: 最高分:XX分,最低分:XX分,平均分:XX分 不及格(分数<60):XX人,占XX.XX% 及格(60<=分数<70):XX人,占XX.XX% 中等(70<=分数<80):XX人,占XX.XX% 良好(80<=分数<90):XX人,占XX.XX% 优秀(90<=分数<100):XX人,占XX.XX%   <5> 成绩图形分析,功能描述如下:    显示考试成绩分布的饼图和柱形图。 想用上饼状图和柱状图请看: http://www.open-open.com/lib/view/open1365997415828.html
学生成绩管理系统是一个用于记录和管理学生成绩系统。下面是两个C语言实现学生成绩管理系统的例子: 1. 使用结构体数组实现学生成绩管理系统: ```c #include <stdio.h> #include <string.h> struct student { int num; char name[20]; float pingshi; float shiyan; float kaoshi; float total; }; int main() { struct student stu[100]; int count = 0; char end[] = "end"; printf("请输入学生信息(输入end结束):\n"); while (1) { printf("学号:"); scanf("%d", &stu[count].num); if (strcmp(stu[count].num, end) == 0) { break; } printf("姓名:"); scanf("%s", stu[count].name); printf("平时成绩:"); scanf("%f", &stu[count].pingshi); printf("实验成绩:"); scanf("%f", &stu[count].shiyan); printf("考试成绩:"); scanf("%f", &stu[count].kaoshi); stu[count].total = stu[count].pingshi + stu[count].shiyan + stu[count].kaoshi; count++; } printf("\n学生成绩如下:\n"); printf("学号\t姓名\t平时成绩\t实验成绩\t考试成绩\t总成绩\n"); for (int i = 0; i < count; i++) { printf("%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n", stu[i].num, stu[i].name, stu[i].pingshi, stu[i].shiyan, stu[i].kaoshi, stu[i].total); } return 0; } ``` 2. 使用函数实现学生成绩管理系统: ```c #include <stdio.h> #include <string.h> struct student { int num; char name[20]; float pingshi; float shiyan; float kaoshi; float total; }; void input(struct student *stu) { printf("学号:"); scanf("%d", &stu->num); printf("姓名:"); scanf("%s", stu->name); printf("平时成绩:"); scanf("%f", &stu->pingshi); printf("实验成绩:"); scanf("%f", &stu->shiyan); printf("考试成绩:"); scanf("%f", &stu->kaoshi); stu->total = stu->pingshi + stu->shiyan + stu->kaoshi; } void output(struct student *stu) { printf("%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n", stu->num, stu->name, stu->pingshi, stu->shiyan, stu->kaoshi, stu->total); } int main() { struct student stu[100]; int count = 0; char end[] = "end"; printf("请输入学生信息(输入end结束):\n"); while (1) { input(&stu[count]); if (strcmp(stu[count].name, end) == 0) { break; } count++; } printf("\n学生成绩如下:\n"); printf("学号\t姓名\t平时成绩\t实验成绩\t考试成绩\t总成绩\n"); for (int i = 0; i < count; i++) { output(&stu[i]); } return 0; } ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值