学生成绩管理系统(大一C语言课程设计)分享

#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>		//支持清屏、光标移动等功能
#include<conio.h>		//_getch()等函数
#include<string.h>		//strcmp()等函数
#define stuSIZE 50		//支持储存的学生成绩信息数目
#define admSIZE 10		//支持储存的管理员账户数目
#define siteX 41		//学生成绩信息显示位置横坐标
char code[20] = "123";	//管理员注册授权码

HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);	//载入光标信息

//定义坐标
COORD coord_zh = { 17,4 };				//账号输入处坐标
COORD coord_mm = { 17,5 };				//密码输入处坐标
COORD coord_qrmm = { 17,6 };			//确认密码输入处坐标
COORD coord_sqm = { 17,7 };				//授权码输入处坐标
COORD coord_rel = { 0,6 };				//登录提示坐标
COORD coord_rer = { 0,8 };				//注册提示坐标
COORD coord_menu = { 0,14 };			//主菜单输入处坐标
COORD coord_stuOUT1 = { siteX,14 };		//学生成绩信息显示坐标1
COORD coord_stuOUT2 = { siteX,15 };		//学生成绩信息显示坐标2
COORD coord_stuOUT3 = { siteX,16 };		//学生成绩信息显示坐标2

//建立管理员账户结构体
struct administrator
{
	char zh[20];		//账号
	char mm[20];		//密码
}adm[admSIZE];
//建立学生成绩信息结构体
struct student
{
	int num;			//学号
	char name[20];		//姓名
	double cls0;		//平均分
	double clsA;		//科目A
	double clsB;		//科目B
	double clsC;		//科目C
	double clsD;		//科目D
	double clsE;		//科目E
	char level[20];		//成绩等级
} stu[stuSIZE];

//排序
void sort(int a)
{
	student t;
	switch (a)
	{
	case 1:												//按学号排序
		for (int j = stuSIZE - 1; j > 0; j--)
		{
			for (int i = 0; i < j; i++)
			{
				if (stu[i].num > stu[i + 1].num)
				{
					t = stu[i + 1];
					stu[i + 1] = stu[i];
					stu[i] = t;
				}
			}
		}
		break;
	case 2:												//按成绩排序
		for (int j = stuSIZE - 1; j > 0; j--)
		{
			for (int i = 0; i < j; i++)
			{
				if (stu[i].cls0 < stu[i + 1].cls0)
				{
					t = stu[i + 1];
					stu[i + 1] = stu[i];
					stu[i] = t;
				}
			}
		}
		break;
	default:
		break;
	}
}

//读取管理员账户文件
void read_adm()
{
	FILE* fp;
	if (fopen_s(&fp, "administrators.dat", "rb"))
		fopen_s(&fp, "administrators.dat", "wb");
	for (int i = 0; i < admSIZE; i++)
		fread(&adm[i], sizeof(administrator), 1, fp);
	fclose(fp);
}
//读取学生成绩信息文件
void read_stu()
{
	FILE* fp;
	if (fopen_s(&fp, "students.dat", "rb"))
		fopen_s(&fp, "students.dat", "wb");
	for (int i = 0; i < stuSIZE; i++)
		fread(&stu[i], sizeof(student), 1, fp);
	fclose(fp);
	sort (1);		//第一次读取将默认按学号排序
}
//保存管理员账户文件
void save_adm()
{
	FILE* fp;
	fopen_s(&fp, "administrators.dat", "rb+");
	for (int i = 0; i < admSIZE; i++)
		fwrite(&adm[i], sizeof(administrator), 1, fp);
	fclose(fp);
}
//保存学生成绩信息文件
void save_stu()
{
	FILE* fp;
	fopen_s(&fp, "students.dat", "rb+");
	for (int i = 0; i < stuSIZE; i++)
		fwrite(&stu[i], sizeof(student), 1, fp);
	fclose(fp);
}


//绘制首页
void firstUI()
{
	printf("|***欢迎使用学生成绩管理系统***|\n");
	printf("|                  |\n");
	printf("|      (1)登录       |\n");
	printf("|      (2)注册       |\n");
	printf("|      (3)退出       |\n");
	printf("|                  |\n");
	printf("|   按下对应数字键选择功能    |\n");
	printf("|                  |\n");
	printf("|******************|\n");
}
//绘制登录界面图形
void loginUI()
{
	printf("|*******欢迎使用学生成绩管理系统*******|\n");
	printf("|                          |\n");
	printf("|           *登录*           |\n");
	printf("|                          |\n");
	printf("|     账号:                  |\n");
	printf("|     密码:                  |\n");
	printf("|                          |\n");
	printf("|                          |\n");
	printf("|                          |\n");
	printf("|**************************|\n");
}
//绘制注册界面图形
void registerUI()
{
	printf("|*******欢迎使用学生成绩管理系统*******|\n");
	printf("|                          |\n");
	printf("|           *注册*           |\n");
	printf("|     (账号处输入数字0可直接退出注册)    |\n");
	printf("|     账号:                  |\n");
	printf("|     密码:                  |\n");
	printf("|   确认密码:                  |\n");
	printf("|    授权码:                  |\n");
	printf("|                          |\n");
	printf("|                          |\n");
	printf("|                          |\n");
	printf("|**************************|\n");
}
//绘制主菜单界面图形
void menuUI()
{
	printf("|*******欢迎使用学生成绩管理系统*******|\n");
	printf("|                          |\n");
	printf("|        (1)添加信息           |\n");
	printf("|        (2)删除信息           |\n");
	printf("|        (3)修改信息           |\n");
	printf("|        (4)查找学生           |\n");
	printf("|        (5)按学号排序          |\n");
	printf("|        (6)按成绩排序          |\n");
	printf("|                          |\n");
	printf("|        (0)退出系统           |\n");
	printf("|                          |\n");
	printf("|   注意,请勿直接关闭程序,否则数据将不会保存  |\n");
	printf("|                          |\n");
	printf("|**************************|\n");
}
//绘制学生成绩信息栏图形
void informationUI()
{
	int i, j = 0;
	int a, b, c, d, e;
	a = b = c = d = e = 0;
	for (i = 0; i < stuSIZE; i++)							//判断学生成绩信息是否为空
	{
		if (stu[i].num == 0)
			j++;
	}
	SetConsoleCursorPosition(handle, coord_stuOUT1);		//将光标移动至合适位置打印信息
	if (j == 50)
		printf("|当前学生成绩信息为空\n");
	else
	{
		for (i = 0; i < stuSIZE; i++)						//统计各层次学生人数
		{
			if (stu[i].num)
			{
				if (stu[i].cls0 > 90)
					a++;
				else if (stu[i].cls0 > 80)
					b++;
				else if (stu[i].cls0 > 70)
					c++;
				else if (stu[i].cls0 > 60)
					d++;
				else
					e++;
			}
		}
		printf("|优:%d人;    良:%d人;    中:%d人;    及格:%d人;    不及格:%d人",a,b,c,d,e);
		SetConsoleCursorPosition(handle, coord_stuOUT2);
		printf("|");
		SetConsoleCursorPosition(handle, coord_stuOUT3);
		printf("|学号\t姓名\t平均分\t科目A\t科目B\t科目C\t科目D\t科目E\t等级");
		int m = 17;
		for (i = 0; i < stuSIZE; i++)
		{
			if (stu[i].num)
			{
				COORD coord_outinf = { siteX,m };
				SetConsoleCursorPosition(handle, coord_outinf);
				printf("|%d\t%s\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%s",
					stu[i].num, stu[i].name, stu[i].cls0, stu[i].clsA, stu[i].clsB, stu[i].clsC, stu[i].clsD, stu[i].clsE, stu[i].level);
				m++;
			}
		}
	}
}

//隐藏式输入密码
void hide_password(char mm[20])
{
	int i = 0;
	while ((mm[i] = _getch()) != '\r')
	{
		if (mm[i] == '\b')
		{
			printf("\b \b");
			i--;
		}
		else
		{
			printf("*");
			i++;
		}
	}
	mm[i] = '\0';
}
//登陆
void login()
{
	int i, j;
	char zh[20];
	char mm[20];
	system("cls");
	loginUI();
	for (j = 0; j < 3; j++)
	{
		SetConsoleCursorPosition(handle, coord_zh);
		scanf_s("%s", zh, 20);
		SetConsoleCursorPosition(handle, coord_mm);
		hide_password(mm);
		for (i = 0; i < admSIZE; i++)
		{
			if (strcmp(zh, adm[i].zh) == 0 && strcmp(mm, adm[i].mm) == 0)
			{
				system("cls");
				loginUI();
				SetConsoleCursorPosition(handle, coord_rel);
				printf("\t 登陆成功!\n\t ");
				system("pause");
				return;
			}
		}
		if (i == 10)
		{
			system("cls");
			loginUI();
			SetConsoleCursorPosition(handle, coord_rel);
			printf("\t 账号或密码输入错误,请重新输入\n\t 输入错误3次将退出程序!已错误%d次\n", j + 1);
		}
	}
	exit(0);
}
//注册
void register_s()
{
	char zh[20] = "1";
	char mm[20] = "1";
	char qrmm[20] = "1";
	char sqm[20];
	int i;
	strcpy_s(sqm, code);
	while (1)
	{
		system("cls");
		registerUI();
		SetConsoleCursorPosition(handle, coord_rer);
		if (strcmp(sqm, code) != 0)
			printf("\t\t\b授权码不正确!\n");
		if (strcmp(mm, qrmm) != 0)
			printf("\t\t\b两次输入的密码不一致!\n");
		SetConsoleCursorPosition(handle, coord_zh);
		scanf_s("%s", zh, 20);
		if (strcmp(zh, "0") == 0)
			return;
		SetConsoleCursorPosition(handle, coord_mm);
		scanf_s("%s", mm, 20);
		SetConsoleCursorPosition(handle, coord_qrmm);
		scanf_s("%s", qrmm, 20);
		SetConsoleCursorPosition(handle, coord_sqm);
		scanf_s("%s", sqm, 20);
		if (strcmp(sqm, code) == 0 && strcmp(mm, qrmm) == 0)
		{
			for (i = 0; i < admSIZE; i++)
			{
				if (strcmp(adm[i].zh, "\0") == 0)
					break;
			}
			strcpy_s(adm[i].zh, zh);
			strcpy_s(adm[i].mm, mm);
			system("cls");
			registerUI();
			SetConsoleCursorPosition(handle, coord_rer);
			printf("\t 注册成功!\n\t 按任意键回到首页");
			_getch();
			return;
		}
	}
}
//首页
void first()
{
	while (1)
	{
		system("cls");
		firstUI();
		switch (_getch())
		{
		case '1':
			read_adm();
			login();
			return;
		case '2':
			read_adm();
			register_s();
			save_adm();
			break;
		case '3':
			exit(0);
		default:
			break;
		}
	}
}
//主菜单
int menu()
{
	int a;
	system("cls");
	menuUI();
	informationUI();
	SetConsoleCursorPosition(handle, coord_menu);
	printf("输入对应数字以选择功能:");
	scanf_s("%d", &a);
	return a;
}

//(1)添加信息
void add()
{
	int i;
	while (1)
	{
		for (i = 0; stu[i].num; i++);		//遍历每个结构体,直至信息为空的结构体
		printf("添加学号(输入0退出):");
		scanf_s("%d", &stu[i].num);
		if (stu[i].num == 0)
			return;
		printf("姓名:");
		scanf_s("%s", stu[i].name, 20);
		printf("科目A(0~100):");
		scanf_s("%lf", &stu[i].clsA);
		printf("科目B(0~100):");
		scanf_s("%lf", &stu[i].clsB);
		printf("科目C(0~100):");
		scanf_s("%lf", &stu[i].clsC);
		printf("科目D(0~100):");
		scanf_s("%lf", &stu[i].clsD);
		printf("科目E(0~100):");
		scanf_s("%lf", &stu[i].clsE);
		stu[i].cls0 = stu[i].clsA + stu[i].clsB + stu[i].clsC + stu[i].clsD + stu[i].clsE;
		stu[i].cls0 = stu[i].cls0 / 5;
		if (stu[i].cls0 > 90)
			strcpy_s(stu[i].level, "优");
		else if (stu[i].cls0 > 80)
			strcpy_s(stu[i].level, "良");
		else if (stu[i].cls0 > 70)
			strcpy_s(stu[i].level, "中");
		else if (stu[i].cls0 > 60)
			strcpy_s(stu[i].level, "及格");
		else
			strcpy_s(stu[i].level, "不及格");
		system("cls");
		menuUI();
		informationUI();
		SetConsoleCursorPosition(handle, coord_menu);
		printf("提示:添加成功!\n\n");
	}
}
//(2)删除信息
void dlt()
{
	int S, i = 0;
	while (1)
	{
		if (i == 50)
			printf("(输入0回到主菜单)\n该学号不存在!请重新输入:");
		else
			printf("(输入0回到主菜单)\n请输出要删除的成绩信息的学号:");
		scanf_s("%d", &S);
		if (S == 0)
			return;
		for (i = 0; i < stuSIZE; i++)
		{
			if (stu[i].num == S)
			{
				stu[i].num = 0;
				system("cls");
				menuUI();
				informationUI();
				SetConsoleCursorPosition(handle, coord_menu);
				printf("提示:删除成功!\n\n");
				break;
			}
		}
	}
}
//(3)修改信息
void modify()
{
	int S, i = 0;
	while (1)
	{
		if (i == 50)
			printf("(输入0回到主菜单)\n该学号不存在!请重新输入:");
		else
			printf("(输入0回到主菜单)\n请输出要修改的成绩信息的学号:");
		scanf_s("%d", &S);
		if (S == 0)
			return;
		for (i = 0; i < stuSIZE; i++)
		{
			if (stu[i].num == S)
			{
				printf("您需要修改这条信息的哪一项?\n(1)学号 (2)姓名\n(a)科目A(b)科目B(c)科目C(d)科目D(e)科目E\n【按下对应按键以选择】\n");
				switch (_getch())
				{
				case '1':
					while (1)
					{
						printf("将学号更改为:");
						scanf_s("%d", &S);
						if
							(S == 0) printf("学号不能为0!请重新输入\n");
						else
						{
							stu[i].num = S;
							system("cls");
							menuUI();
							informationUI();
							SetConsoleCursorPosition(handle, coord_menu);
							printf("提示:修改成功!\n\n");
							break;
						}
					}
					break;
				case '2':
					printf("将姓名更改为:");
					scanf_s("%s", stu[i].name, 20);
					system("cls");
					menuUI();
					informationUI();
					SetConsoleCursorPosition(handle, coord_menu);
					printf("提示:修改成功!\n\n");
					break;
				case 'a':
					printf("将科目A成绩更改为(0~100):");
					scanf_s("%lf", &stu[i].clsA);
					stu[i].cls0 = stu[i].clsA + stu[i].clsB + stu[i].clsC + stu[i].clsD + stu[i].clsE;
					stu[i].cls0 = stu[i].cls0 / 5;
					if (stu[i].cls0 > 90)
						strcpy_s(stu[i].level, "优");
					else if (stu[i].cls0 > 80)
						strcpy_s(stu[i].level, "良");
					else if (stu[i].cls0 > 70)
						strcpy_s(stu[i].level, "中");
					else if (stu[i].cls0 > 60)
						strcpy_s(stu[i].level, "及格");
					else
						strcpy_s(stu[i].level, "不及格");
					system("cls");
					menuUI();
					informationUI();
					SetConsoleCursorPosition(handle, coord_menu);
					printf("提示:修改成功!\n\n");
					break;
				case 'b':
					printf("将科目B成绩更改为(0~100):");
					scanf_s("%lf", &stu[i].clsB);
					stu[i].cls0 = stu[i].clsA + stu[i].clsB + stu[i].clsC + stu[i].clsD + stu[i].clsE;
					stu[i].cls0 = stu[i].cls0 / 5;
					if (stu[i].cls0 > 90)
						strcpy_s(stu[i].level, "优");
					else if (stu[i].cls0 > 80)
						strcpy_s(stu[i].level, "良");
					else if (stu[i].cls0 > 70)
						strcpy_s(stu[i].level, "中");
					else if (stu[i].cls0 > 60)
						strcpy_s(stu[i].level, "及格");
					else
						strcpy_s(stu[i].level, "不及格");
					system("cls");
					menuUI();
					informationUI();
					SetConsoleCursorPosition(handle, coord_menu);
					printf("提示:修改成功!\n\n");
					break;
				case 'c':
					printf("将科目C成绩更改为(0~100):");
					scanf_s("%lf", &stu[i].clsC);
					stu[i].cls0 = stu[i].clsA + stu[i].clsB + stu[i].clsC + stu[i].clsD + stu[i].clsE;
					stu[i].cls0 = stu[i].cls0 / 5;
					if (stu[i].cls0 > 90)
						strcpy_s(stu[i].level, "优");
					else if (stu[i].cls0 > 80)
						strcpy_s(stu[i].level, "良");
					else if (stu[i].cls0 > 70)
						strcpy_s(stu[i].level, "中");
					else if (stu[i].cls0 > 60)
						strcpy_s(stu[i].level, "及格");
					else
						strcpy_s(stu[i].level, "不及格");
					system("cls");
					menuUI();
					informationUI();
					SetConsoleCursorPosition(handle, coord_menu);
					printf("提示:修改成功!\n\n");
					break;
				case 'd':
					printf("将科目D成绩更改为(0~100):");
					scanf_s("%lf", &stu[i].clsD);
					stu[i].cls0 = stu[i].clsA + stu[i].clsB + stu[i].clsC + stu[i].clsD + stu[i].clsE;
					stu[i].cls0 = stu[i].cls0 / 5;
					if (stu[i].cls0 > 90)
						strcpy_s(stu[i].level, "优");
					else if (stu[i].cls0 > 80)
						strcpy_s(stu[i].level, "良");
					else if (stu[i].cls0 > 70)
						strcpy_s(stu[i].level, "中");
					else if (stu[i].cls0 > 60)
						strcpy_s(stu[i].level, "及格");
					else
						strcpy_s(stu[i].level, "不及格");
					system("cls");
					menuUI();
					informationUI();
					SetConsoleCursorPosition(handle, coord_menu);
					printf("提示:修改成功!\n\n");
					break;
				case 'e':
					printf("将科目E成绩更改为(0~100):");
					scanf_s("%lf", &stu[i].clsE);
					stu[i].cls0 = stu[i].clsA + stu[i].clsB + stu[i].clsC + stu[i].clsD + stu[i].clsE;
					stu[i].cls0 = stu[i].cls0 / 5;
					if (stu[i].cls0 > 90)
						strcpy_s(stu[i].level, "优");
					else if (stu[i].cls0 > 80)
						strcpy_s(stu[i].level, "良");
					else if (stu[i].cls0 > 70)
						strcpy_s(stu[i].level, "中");
					else if (stu[i].cls0 > 60)
						strcpy_s(stu[i].level, "及格");
					else
						strcpy_s(stu[i].level, "不及格");
					system("cls");
					menuUI();
					informationUI();
					SetConsoleCursorPosition(handle, coord_menu);
					printf("提示:修改成功!\n\n");
					break;
				default:
					system("cls");
					menuUI();
					informationUI();
					SetConsoleCursorPosition(handle, coord_menu);
					printf("错误!非法输入!\n\n");
					break;
				}
				break;
			}
		}
	}
}
//(4)查找学生
void search()
{
	int S, i = 0;
	while (1)
	{
		if (i == 50)
			printf("(输入0回到主菜单)\n该学号不存在!请重新输入:");
		else
			printf("(输入0回到主菜单)\n请输出学号:");
		scanf_s("%d", &S);
		if (S == 0)
			return;
		for (i = 0; i < stuSIZE; i++)
		{
			if (stu[i].num == S)
			{
				system("cls");
				menuUI();
				informationUI();
				SetConsoleCursorPosition(handle, coord_menu);
				printf("搜索结果:\n");
				printf("学号:%d\n姓名:%s\n平均分:%.1lf分\n科目A:%.1lf分\n科目B:%.1lf分\n科目C:%.1lf分\n科目D:%.1lf分\n科目E:%.1lf分\n等级:%s\n\n",
					stu[i].num, stu[i].name, stu[i].cls0, stu[i].clsA, stu[i].clsB, stu[i].clsC, stu[i].clsD, stu[i].clsE,stu[i].level);
				break;
			}
		}
	}
}

int main()
{
	first();
	read_stu();
	while (1)
	{
		switch (menu())
		{
		case 1: add(); break;
		case 2: dlt(); break;
		case 3: modify(); break;
		case 4: search(); break;
		case 5: sort(1); break;
		case 6: sort(2); break;
		case 0: save_stu(); exit(0);
		default: break;
		}
	}
}

  • 7
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
学生成绩管理系统的详细设计包括以下几个方面: 1. 系统模块划分 学生成绩管理系统可以划分为以下几个模块: - 学生信息管理模块:负责学生信息的添加、删除、修改和查询。 - 课程信息管理模块:负责课程信息的添加、删除、修改和查询。 - 成绩信息管理模块:负责成绩信息的录入、修改和查询。 - 统计报表模块:负责生成各种统计报表。 2. 数据结构设计 为了方便数据的管理和统计,可以设计以下数据结构: - 学生信息结构体:包括学生学号、姓名、性别、年龄等信息。 - 课程信息结构体:包括课程编号、名称、学分、授课教师等信息。 - 成绩信息结构体:包括学生学号、课程编号、成绩等信息。 - 报表结构体:包括学生平均成绩、课程平均成绩、班级排名等信息。 3. 界面设计 学生成绩管理系统的界面应该简洁明了,易于操作。可以设计以下几个界面: - 登录界面:用户输入用户名和密码登录系统。 - 主界面:显示各个模块的功能按钮。 - 学生信息管理界面:显示学生信息列表,提供添加、删除、修改和查询功能。 - 课程信息管理界面:显示课程信息列表,提供添加、删除、修改和查询功能。 - 成绩信息管理界面:显示成绩信息列表,提供录入、修改和查询功能。 - 统计报表界面:显示各种统计报表。 4. 功能实现 学生成绩管理系统需要实现以下功能: - 用户登录验证:用户输入用户名和密码,系统验证后允许登录。 - 学生信息管理:包括添加、删除、修改和查询学生信息。 - 课程信息管理:包括添加、删除、修改和查询课程信息。 - 成绩信息管理:包括录入、修改和查询成绩信息。 - 统计报表生成:包括生成学生平均成绩、课程平均成绩、班级排名等统计报表。 以上就是学生成绩管理系统的详细设计。在实现时需要根据具体需求进行修改和完善。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值