数据结构与算法 课程设计报告——学生信息管理系统

一、概述

1.开发背景

        使用计算机对学生信息进行管理,拥有手工管理所无法比拟的优点。例如:检索迅速、查找方便、可靠性高、存储量大、成本低等。这些优点能够极大地提高学生信息的效率,也是管理科学化、正规化的重要支撑。

学生信息管理系统能够方便地查询和变更学生的基本数据(包括学籍数据和成绩数据),节省大量工作时间,有效地提高学生信息管理的效率。而查询信息的直观显示将有助于系统的用户一目了然地掌握学生的情况。

2.开发工具

开发语言:C++

开发工具:Visual Studio 2019

二、系统分析

1.需求分析

1.1用户需求

对学校而言,学生成绩管理是管理工作中重要的一环,但是高校学生的成绩管理工作量大、繁杂,人工处理非常困难。因此,借助于强大计算机的处理能力,能够把人从繁重的成绩管理工作中解脱出来,并且更加准确、安全、清晰的管理环境。

1.2 功能需求

能够进行的数据定义、数据操纵、数据控制等处理功能。具体功能应包括:可提供课程成绩数据的添加、插入、删除、更新、查询,学生基本信息查询的功能。

1.3 安全性与完整性要求

对于学生成绩管理系统来讲,由于其主要数据是学生成绩,只能由本人以及所教老师及教务处知道,因此做好数据安全性是重中之重。

2.功能分析

程序采用图形界面下进行交互的工作方式,完成如下功能:

1.多种方式建立学生信息

每个学生信息由学号、姓名、课程名称(多门课程,如高等数学、英语、政治等)组成;

可以通过手工录入每个学生信息,并在程序所在目录下以score.txt保存;也可以导入某个路径下存放学生信息的文本文件。

2.浏览所有学生信息。

3.按照学号和成绩对所有学生信息进行升序、降序排列,并输出。可将结果输出屏幕显示,也可将输出结果存放学生信息的文件中。

4.按姓名、学号方式,实现对学生信息查询,并输出屏幕显示。

5.学生信息的插入、删除、修改。

通过插入、删除和修改后,保持所有学生信息的有序性;插入、删除和修改后,对存放所有学生信息的文件及时更新。

6.数据的统计功能。

统计每个学生的平均分和总分;

统计每个科目的平均分和最高分、最低分;可将上述统计结果输出屏幕显示。

三、系统设计

1.总体设计

数据结构与算法 课程设计报告——学生信息管理系统_第1张图片

2.数据结构的设计

class Student {

private:

    int num;          //学号
    char name[8];     //姓名
    char class_0[20]; //班级
    float elec;       //电子成绩
    float c_program;  //C++成绩
    float english;    //英语成绩
    float math;       //数学成绩
    float media;      //多媒体成绩
    float sport;      //体育成绩
    float polity;     //政治成绩
    float average;    //平均分
    float total;      //总分
    int order;        //学生基地址(受升序降序影响)
}stu[100];           //最大容纳100个学生

3.函数功能设计

数据结构与算法 课程设计报告——学生信息管理系统_第2张图片

四、实现与测试

1.关键技术实现

#include 
#include 
#include 
#include 
#include 
//codeblocks编译后不显示乱码的方法 https://blog.csdn.net/qq_41139830/article/details/80507000
//https://blog.csdn.net/gulang03/article/details/81771343

using namespace std;

class Student {
public:
	friend void Input(Student stu[]);			//输入成绩(会清空原始数据)
	friend void Statistic(Student stu[]);		//输出学生统计数据
	friend void LookupName(Student stu[]);		//查询姓名输出学生信息
	friend void LookupNum(Student stu[]);		//查询学号输出学生信息
	friend void Modify(Student stu[]);			//修改学生成绩
	friend void Delete(Student stu[]);			//删除学生信息
	friend void Output(Student stu[]);			//显示全部学生成绩
	friend void Insert(Student stu[]);			//增加学生成绩
	friend void Descend(Student stu[]);			//按学生平均分降序排列
	friend void Ascend(Student stu[]);			//按学生平均分升序排列
	friend void Write(Student stu[], int n);	//写入文件
	friend void getMax(Student stu[]);			//得到所有学生中最高分科目
	friend void getMin(Student stu[]);			//得到所有学生中最低分科目
	friend void getAvg(Student stu[]);			//得到所有学生中科目平均分
	friend int Read(Student stu[]);				//读取文件
private:
	int num;			//学号
	char name[8];		//姓名
	char class_0[20];	//班级
	float elec;			//电子成绩
	float c_program;	//C++成绩
	float english;		//英语成绩
	float math;			//数学成绩
	float media;		//多媒体成绩
	float sport;		//体育成绩
	float polity;		//政治成绩
	float average;		//平均分
	float total;		//总分
	int order;			//学生排位(受升序降序影响)
}stu[100];

//最高最低平均分
float maxElec = -1;
float maxC_program = -1;
float maxEnglish = -1;
float maxMath = -1;
float maxMedia = -1;
float maxSport = -1;
float maxPolity = -1;
float maxAverage = -1;

float minElec = 101;
float minC_program = 101;
float minEnglish = 101;
float minMath = 101;
float minMedia = 101;
float minSport = 101;
float minPolity = 101;
float minAverage = 101;

float avgElec = 0;
float avgC_program = 0;
float avgEnglish = 0;
float avgMath = 0;
float avgMedia = 0;
float avgSport = 0;
float avgPolity = 0;
float avgAverage = 0;

//账号和密码
typedef struct manage//管理员
{
	char ID[10];//账号
	char password[10];//密码
}mag;

//BF算法匹配字符串
int BF(char S[], char T[])
{
	int i, j;
	i = j = 0;
	while (S[i] != '\0' && T[j] != '\0') {
		if (S[i] == T[i]) {
			i++;
			j++;
		}
		else {
			j = 0;
			i = i - j + 1;
		}
	}
	if (T[j] == '\0')
		return i - j + 1;
	else
		return 0;
}

//写入文件
void Write(Student stu[], int n) {
	fstream myFile;
	myFile.open("score.txt", ios::out | ios::binary);
	if (!myFile) {
		cout << "score.txt can't open!" << endl;
		abort();
	}
	int count = n;
	myFile << count << endl << endl;
	for (int i = 0; i < count; i++) {
		myFile << stu[i].class_0 << "\t"
			<< stu[i].num << "\t"
			<< stu[i].name << "\t"
			<< stu[i].elec << "\t"
			<< stu[i].c_program << "\t"
			<< stu[i].media << "\t"
			<< stu[i].english << "\t"
			<< stu[i].math << "\t"
			<< stu[i].sport << "\t"
			<< stu[i].polity << "\t"
			<< stu[i].average << "\t"
			<< stu[i].total << endl;
	}
	myFile.close();
}

//读取文件
int Read(Student stu[]) {
	fstream myFile;
	myFile.open("score.txt", ios::in | ios::binary);
	if (!myFile) {
		cout << "score.txt can't open!" << endl;
		abort();
	}
	int count;
	myFile.seekg(0);
	myFile >> count;
	for (int i = 0; i <= count; i++) {
		myFile >> stu[i].class_0 >> stu[i].num >> stu[i].name
			>> stu[i].elec >> stu[i].c_program >> stu[i].media
			>> stu[i].english >> stu[i].math >> stu[i].sport
			>> stu[i].polity >> stu[i].average >> stu[i].total;
	}
	myFile.close();
	return count;
}

//得到所有学生中最高分科目
void getMax(Student stu[]) {
	int n = Read(stu);
	for (int i = 0; i < n; i++)
	{
		if (stu[i].elec > maxElec)
			maxElec = stu[i].elec;
		if (stu[i].c_program > maxC_program)
			maxC_program = stu[i].c_program;
		if (stu[i].media > maxMedia)
			maxMedia = stu[i].media;
		if (stu[i].english > maxEnglish)
			maxEnglish = stu[i].english;
		if (stu[i].math > maxMath)
			maxMath = stu[i].math;
		if (stu[i].sport > maxSport)
			maxSport = stu[i].sport;
		if (stu[i].polity > maxPolity)
			maxPolity = stu[i].polity;
		if (stu[i].average > maxAverage)
			maxAverage = stu[i].average;
	}
	cout << "最高分" << "\t" << "电子" << "\t" << "C++" << "\t" << "多媒体" << "\t"
		<< "英语" << "\t" << "数学" << "\t" << "体育" << "\t"
		<< "政治" << "\t" << "平均分" << "\t" << endl;
	cout << "--------------------------------------------------------------------------------" << endl;
	cout << "\t" << maxElec << "\t" << maxC_program << "\t" << maxMedia << "\t"
		<< maxEnglish << "\t" << maxMath << "\t" << maxSport << "\t"
		<< maxPolity << "\t" << maxAverage << endl;
	cout << "================================================================================" << endl;
	maxElec = -1; maxC_program = -1; maxEnglish = -1; maxMath = -1; maxMedia = -1; maxSport = -1; maxPolity = -1; maxAverage = -1;
}

//得到所有学生中最低分科目
void getMin(Student stu[]) {
	int n = Read(stu);
	for (int i = 0; i < n; i++)
	{
		if (stu[i].elec < minElec)
			minElec = stu[i].elec;
		if (stu[i].c_program < minC_program)
			minC_program = stu[i].c_program;
		if (stu[i].media < minMedia)
			minMedia = stu[i].media;
		if (stu[i].english < minEnglish)
			minEnglish = stu[i].english;
		if (stu[i].math < minMath)
			minMath = stu[i].math;
		if (stu[i].sport < minSport)
			minSport = stu[i].sport;
		if (stu[i].polity < minPolity)
			minPolity = stu[i].polity;
		if (stu[i].average < minAverage)
			minAverage = stu[i].average;
	}
	cout << "最低分" << "\t" << "电子" << "\t" << "C++" << "\t" << "多媒体" << "\t"
		<< "英语" << "\t" << "数学" << "\t" << "体育" << "\t"
		<< "政治" << "\t" << "平均分" << "\t" << endl;
	cout << "--------------------------------------------------------------------------------" << endl;
	cout << "\t" << minElec << "\t" << minC_program << "\t" << minMedia << "\t"
		<< minEnglish << "\t" << minMath << "\t" << minSport << "\t"
		<< minPolity << "\t" << minAverage << endl;
	cout << "================================================================================" << endl;
	minElec = 101; minC_program = 101; minEnglish = 101; minMath = 101; minMedia = 101; minSport = 101; minPolity = 101; minAverage = 101;
}

//得到所有学生中科目平均分
void getAvg(Student stu[]) {
	int n = Read(stu);
	for (int i = 0; i < n; i++)
	{
		avgElec += stu[i].elec;
		avgC_program += stu[i].c_program;
		avgMedia += stu[i].media;
		avgEnglish += stu[i].english;
		avgMath += stu[i].math;
		avgSport += stu[i].sport;
		avgPolity += stu[i].polity;
		avgAverage += stu[i].average;
	}
	avgElec = avgElec / n;
	avgC_program = avgC_program / n;
	avgMedia = avgMedia / n;
	avgEnglish = avgEnglish / n;
	avgMath = avgMath / n;
	avgSport = avgSport / n;
	avgPolity = avgPolity / n;
	avgAverage = avgAverage / n;

	cout << "均分" << "\t" << "电子" << "\t" << "C++" << "\t" << "多媒体" << "\t"
		<< "英语" << "\t" << "数学" << "\t" << "体育" << "\t"
		<< "政治" << "\t" << "平均分" << "\t" << endl;
	cout << "--------------------------------------------------------------------------------" << endl;
	cout << "\t" << avgElec << "\t" << avgC_program << "\t" << avgMedia << "\t"
		<< avgEnglish << "\t" << avgMath << "\t" << avgSport << "\t"
		<< avgPolity << "\t" << avgAverage << endl;
	cout << "================================================================================" << endl;
	avgElec = 0; avgC_program = 0; avgEnglish = 0; avgMath = 0; avgMedia = 0; avgSport = 0; avgPolity = 0; avgAverage = 0;
}

//输入成绩(会清空原始数据)
void Input(Student stu[]) {
	system("cls");
	int i = 0;
	int flag;
	char sign = '0';
	cout << endl << "======>>    请输入学生成绩    <<======" << endl;
	while (sign != 'n' && sign != 'N') {
		cout << "班级:";
		cin >> stu[i].class_0;
	loop:
		cout << "学号:";
		cin >> stu[i].num;
		int c = 0;
		while (c < i) {
			c++;
			if (stu[i].num == stu[i - c].num) {
				cout << "您输入的学号已存在!请重新输入。" << endl;
				goto loop;
			}
		}
		cout << "姓名:";
		cin >> stu[i].name;
		do {
			flag = 0;
			cout << "电子技术成绩:";
			cin >> stu[i].elec;
			if (stu[i].elec > 100 || stu[i].elec < 1) {
				cout << " 对不起,请输入1-100之间的数字!!\n";
			}
			else {
				flag = 1;
			}
		} while (flag == 0);
		do {
			flag = 0;
			cout << "C++程序设计成绩:";
			cin >> stu[i].c_program;
			if (stu[i].c_program > 100 || stu[i].c_program < 1) {
				cout << " 对不起,请输入1-100之间的数字!!\n";
			}
			else {
				flag = 1;
			}
		} while (flag == 0);
		do {
			flag = 0;
			cout << "多媒体技术成绩:";
			cin >> stu[i].media;
			if (stu[i].media > 100 || stu[i].media < 1) {
				cout << " 对不起,请输入1-100之间的数字!!\n";
			}
			else {
				flag = 1;
			}
		} while (flag == 0);
		do {
			flag = 0;
			cout << "大学英语成绩:";
			cin >> stu[i].english;
			if (stu[i].english > 100 || stu[i].english < 1) {
				cout << " 对不起,请输入1-100之间的数字!!\n";
			}
			else {
				flag = 1;
			}
		} while (flag == 0);
		do {
			flag = 0;
			cout << "高等数学成绩:";
			cin >> stu[i].math;
			if (stu[i].math > 100 || stu[i].math < 1) {
				cout << " 对不起,请输入1-100之间的数字!!\n";
			}
			else {
				flag = 1;
			}
		} while (flag == 0);
		do {
			flag = 0;
			cout << "大学体育成绩:";
			cin >> stu[i].sport;
			if (stu[i].sport > 100 || stu[i].sport < 1) {
				cout << " 对不起,请输入1-100之间的数字!!\n";
			}
			else {
				flag = 1;
			}
		} while (flag == 0);
		do {
			flag = 0;
			cout << "马克思主义基本原理成绩:";
			cin >> stu[i].polity;
			if (stu[i].polity > 100 || stu[i].polity < 1) {
				cout << " 对不起,请输入1-100之间的数字!!\n";
			}
			else {
				flag = 1;
			}
		} while (flag == 0);
		stu[i].average = (stu[i].elec + stu[i].c_program + stu[i].media + stu[i].english + stu[i].math +
			stu[i].sport + stu[i].polity) / 7;
		stu[i].total = (stu[i].elec + stu[i].c_program + stu[i].media + stu[i].english + stu[i].math +
			stu[i].sport + stu[i].polity);
		cout << " 平均分为:" << stu[i].average << endl;
		cout << " 总分为:" << stu[i].total << endl;
		cout << "======>>    提示:是否继续写入学生成绩 ?(y/n)";
		cin >> sign;
		i++;
	}
	Write(stu, i);
}

//输出学生统计数据
void Statistic(Student stu[]) {
	system("cls");
	int n = Read(stu);
	cout << endl << "======>>    输出学生统计数据    <<======\n" << endl;
	cout << "-------------------------------------------------" << endl;
	cout << "班级" << "\t" << "学号" << "\t" << "姓名" << "\t" << "平均分" << "\t" << "总分" << endl;
	cout << "-------------------------------------------------" << endl;
	for (int i = 0; i < n; i++)
		cout << stu[i].class_0 << "\t" << stu[i].num << "\t" << stu[i].name << "\t" << stu[i].average << "\t" << stu[i].total << "\t" << endl;
	cout << "-------------------------------------------------" << endl;
	getMax(stu);
	getMin(stu);
	getAvg(stu);
	system("pause");
}

//查询学号输出学生信息
void LookupNum(Student stu[]) {
	system("cls");
	int n = Read(stu);
	int s;
	int i = 0;
	cout << endl << "======>>    查找学生成绩    <<======" << endl;
	cout << "请输入要查找学生的学号:";
	cin >> s;
	while ((stu[i].num - s) != 0 && i < n)i++;
	if (i == n) {
		cout << "======>>    对不起,无法找到该学生......    <<======" << endl;
	}
	else {
		cout << "----------------------------" << endl;
		cout << "班级:" << stu[i].class_0 << endl;
		cout << "学号:" << stu[i].num << endl;
		cout << "姓名:" << stu[i].name << endl;
		cout << "电子技术:" << stu[i].elec << endl;
		cout << "C++程序设计:" << stu[i].c_program << endl;
		cout << "多媒体技术:" << stu[i].media << endl;
		cout << "大学英语:" << stu[i].english << endl;
		cout << "高等数学:" << stu[i].math << endl;
		cout << "大学体育:" << stu[i].sport << endl;
		cout << "马克思主义基本原理:" << stu[i].polity << endl;
		cout << "平均分:" << stu[i].average << endl;
		cout << "总分:" << stu[i].total << endl;
	}
}

//查询姓名输出学生信息
void LookupName(Student stu[]) {
	system("cls");
	int n = Read(stu);
	char s[8];
	int i = 0;
	cout << endl << "======>>    查找学生成绩    <<======" << endl;
	cout << "请输入要查找学生的姓名:";
	cin >> s;
	while (BF(stu[i].name, s) < 1 && i < n)i++;
	if (i == n) {
		cout << "======>>    对不起,无法找到该学生......    <<======" << endl;
	}
	else {
		cout << "----------------------------" << endl;
		cout << "班级:" << stu[i].class_0 << endl;
		cout << "学号:" << stu[i].num << endl;
		cout << "姓名:" << stu[i].name << endl;
		cout << "电子技术:" << stu[i].elec << endl;
		cout << "C++程序设计:" << stu[i].c_program << endl;
		cout << "多媒体技术:" << stu[i].media << endl;
		cout << "大学英语:" << stu[i].english << endl;
		cout << "高等数学:" << stu[i].math << endl;
		cout << "大学体育:" << stu[i].sport << endl;
		cout << "马克思主义基本原理:" << stu[i].polity << endl;
		cout << "平均分:" << stu[i].average << endl;
		cout << "总分:" << stu[i].total << endl;
	}
}

//修改学生成绩
void Modify(Student stu[]) {
	system("cls");
	int n = Read(stu);
	int s;
	int i = 0;
	cout << endl << "======>>    修改学生成绩    <<======" << endl;
	cout << "请输入要修改成绩学生的学号:";
	cin >> s;
	while ((stu[i].num - s) != 0 && i < n)i++;
	if (i == n) {
		cout << "======>>    对不起,无法找到该学生......    <<======" << endl;
	}
	else {
		cout << "---------------------------------------------------------------------------------------------" << endl;
		cout << "班级" << "\t" << "学号" << "\t" << "姓名" << "\t"
			<< "电子" << "\t" << "C++" << "\t" << "多媒体" << "\t"
			<< "英语" << "\t" << "数学" << "\t" << "体育" << "\t"
			<< "政治" << "\t" << "平均分" << "\t" << "总分" << endl;
		cout << "---------------------------------------------------------------------------------------------" << endl;
		cout << stu[i].class_0 << "\t" << stu[i].num << "\t" << stu[i].name << "\t"
			<< stu[i].elec << "\t" << stu[i].c_program << "\t" << stu[i].media << "\t"
			<< stu[i].english << "\t" << stu[i].math << "\t" << stu[i].sport << "\t"
			<< stu[i].polity << "\t" << stu[i].average << "\t" << stu[i].total << endl;
		cout << endl << "请重新输入该学生成绩: " << endl;
		cout << "电子技术成绩:";
		cin >> stu[i].elec;
		cout << "C++成绩:";
		cin >> stu[i].c_program;
		cout << "多媒体技术成绩:";
		cin >> stu[i].media;
		cout << "大学英语成绩:";
		cin >> stu[i].english;
		cout << "高等数学成绩:";
		cin >> stu[i].math;
		cout << "大学体育成绩:";
		cin >> stu[i].sport;
		cout << "马克思主义基本原理成绩:";
		cin >> stu[i].polity;
		stu[i].average = (stu[i].elec + stu[i].c_program + stu[i].media +
			stu[i].english + stu[i].math + stu[i].sport + stu[i].polity) / 7;
		stu[i].total = (stu[i].elec + stu[i].c_program + stu[i].media +
			stu[i].english + stu[i].math + stu[i].sport + stu[i].polity);
		cout << "平均分:" << stu[i].average << endl;
		cout << "总分:" << stu[i].total << endl;

		char c;
		cout << "======>>    是否保存数据 ?(y/n)";
		cin >> c;
		if (c != 'n' && c != 'N')
			Write(stu, n);
	}
}

//删除学生信息
void Delete(Student stu[]) {
	system("cls");
	int n = Read(stu);
	int s;
	int i = 0, j;
	cout << endl << "======>>    删除学生成绩    <<======" << endl;
	cout << "请输入要删除的学生的学号:";
	cin >> s;
	while ((stu[i].num - s) != 0 && i < n)i++;
	if (i == n) {
		cout << "======>>    对不起,无法找到该学生......    <<======" << endl;
	}
	else {
		for (j = i; j < n - 1; j++) {
			strcpy(stu[j].class_0, stu[j + 1].class_0);
			stu[j].num = stu[j + 1].num;
			strcpy(stu[j].name, stu[j + 1].name);
			stu[j].elec = stu[j + 1].elec;
			stu[j].c_program = stu[j + 1].c_program;
			stu[j].media = stu[j + 1].media;
			stu[j].english = stu[j + 1].english;
			stu[j].math = stu[j + 1].math;
			stu[j].sport = stu[j + 1].sport;
			stu[j].polity = stu[j + 1].polity;
			stu[j].average = stu[j + 1].average;
			stu[j].total = stu[j + 1].total;
		}
		cout << "======>>    提示:已成功删除!" << endl;
	}
	Write(stu, n - 1);
}

//增加学生成绩
void Insert(Student stu[]) {
	system("cls");
	int n = Read(stu);
	char s = '0';
	cout << endl << "=======>>    增加学生成绩    <<========" << endl;
	while (s != 'n' && s != 'N') {
		cout << "班级:";
		cin >> stu[n].class_0;
		cout << "学号:";
		cin >> stu[n].num;
		cout << "姓名:";
		cin >> stu[n].name;
		cout << "电子技术成绩:";
		cin >> stu[n].elec;
		cout << "C++成绩:";
		cin >> stu[n].c_program;
		cout << "多媒体技术成绩:";
		cin >> stu[n].media;
		cout << "大学英语成绩:";
		cin >> stu[n].english;
		cout << "高等数学成绩:";
		cin >> stu[n].math;
		cout << "大学体育成绩:";
		cin >> stu[n].sport;
		cout << "马克思主义基本原理成绩:";
		cin >> stu[n].polity;
		stu[n].average = (stu[n].elec + stu[n].c_program + stu[n].media +
			stu[n].english + stu[n].math + stu[n].sport + stu[n].polity) / 7;
		stu[n].total = (stu[n].elec + stu[n].c_program + stu[n].media +
			stu[n].english + stu[n].math + stu[n].sport + stu[n].polity);
		cout << "平均分:" << stu[n].average << endl;
		cout << "总分:" << stu[n].total << endl;
		n++;
		cout << "======>>    是否继续插入(y/n)";
		cin >> s;
	}
	Write(stu, n);
}

//按学生平均分降序排列
void Descend(Student stu[]) {
	int i, j, k;
	float s;
	char t[20];
	cout << endl << "======>>    降序排列    <<======" << endl;
	int n = Read(stu);
	for (i = 0; i < n - 1; i++) {
		for (j = 0; j < n - 1; j++) {
			if (stu[j].average < stu[j + 1].average) {
				//交换课程
				strcpy(t, stu[j + 1].class_0);
				strcpy(stu[j + 1].class_0, stu[j].class_0);
				strcpy(stu[j].class_0, t);
				//num
				k = stu[j + 1].num;
				stu[j + 1].num = stu[j].num;
				stu[j].num = k;

				//name
				strcpy(t, stu[j + 1].name);
				strcpy(stu[j + 1].name, stu[j].name);
				strcpy(stu[j].name, t);
				//elec
				s = stu[j + 1].elec;
				stu[j + 1].elec = stu[j].elec;
				stu[j].elec = s;
				//c_program
				s = stu[j + 1].c_program;
				stu[j + 1].c_program = stu[j].c_program;
				stu[j].c_program = s;
				//media
				s = stu[j + 1].media;
				stu[j + 1].media = stu[j].media;
				stu[j].media = s;
				//english
				s = stu[j + 1].english;
				stu[j + 1].english = stu[j].english;
				stu[j].english = s;
				//math
				s = stu[j + 1].math;
				stu[j + 1].math = stu[j].math;
				stu[j].math = s;
				//sport
				s = stu[j + 1].sport;
				stu[j + 1].sport = stu[j].sport;
				stu[j].sport = s;
				//polity
				s = stu[j + 1].polity;
				stu[j + 1].polity = stu[j].polity;
				stu[j].polity = s;
				//average
				s = stu[j + 1].average;
				stu[j + 1].average = stu[j].average;
				stu[j].average = s;
				//total
				s = stu[j + 1].total;
				stu[j + 1].total = stu[j].total;
				stu[j].total = s;
			}
		}
	}
	cout << "------------------------------------------------------------------------------------" << endl;
	cout << "班级" << "\t" << "学号" << "\t" << "姓名" << "\t"
		<< "电子" << "\t" << "C++" << "\t" << "多媒体" << "\t"
		<< "英语" << "\t" << "数学" << "\t" << "体育" << "\t"
		<< "政治" << "\t" << "平均分" << "\t" << "总分" << endl;
	cout << "------------------------------------------------------------------------------------" << endl;
	for (int i = 0; i < n; i++) {
		stu[i].order = i + 1;
		cout << stu[i].class_0 << "\t" << stu[i].num << "\t" << stu[i].name << "\t"
			<< stu[i].elec << "\t" << stu[i].c_program << "\t" << stu[i].media << "\t"
			<< stu[i].english << "\t" << stu[i].math << "\t" << stu[i].sport << "\t"
			<< stu[i].polity << "\t" << stu[i].average << "\t" << stu[i].total << endl;
	}
	Write(stu, n);
}

//按学生平均分升序排列
void Ascend(Student stu[]) {
	int i, j, k;
	float s;
	char t[20];
	cout << endl << "======>>    升序排列    <<======" << endl;
	int n = Read(stu);
	for (i = 0; i < n - 1; i++) {
		for (j = 0; j < n - 1; j++) {
			if (stu[j].average > stu[j + 1].average) {
				//交换课程
				strcpy(t, stu[j + 1].class_0);
				strcpy(stu[j + 1].class_0, stu[j].class_0);
				strcpy(stu[j].class_0, t);
				//num
				k = stu[j + 1].num;
				stu[j + 1].num = stu[j].num;
				stu[j].num = k;

				//name
				strcpy(t, stu[j + 1].name);
				strcpy(stu[j + 1].name, stu[j].name);
				strcpy(stu[j].name, t);
				//elec
				s = stu[j + 1].elec;
				stu[j + 1].elec = stu[j].elec;
				stu[j].elec = s;
				//c_program
				s = stu[j + 1].c_program;
				stu[j + 1].c_program = stu[j].c_program;
				stu[j].c_program = s;
				//media
				s = stu[j + 1].media;
				stu[j + 1].media = stu[j].media;
				stu[j].media = s;
				//english
				s = stu[j + 1].english;
				stu[j + 1].english = stu[j].english;
				stu[j].english = s;
				//math
				s = stu[j + 1].math;
				stu[j + 1].math = stu[j].math;
				stu[j].math = s;
				//sport
				s = stu[j + 1].sport;
				stu[j + 1].sport = stu[j].sport;
				stu[j].sport = s;
				//polity
				s = stu[j + 1].polity;
				stu[j + 1].polity = stu[j].polity;
				stu[j].polity = s;
				//average
				s = stu[j + 1].average;
				stu[j + 1].average = stu[j].average;
				stu[j].average = s;
				//total
				s = stu[j + 1].total;
				stu[j + 1].total = stu[j].total;
				stu[j].total = s;
			}
		}
	}
	cout << "------------------------------------------------------------------------------------" << endl;
	cout << "班级" << "\t" << "学号" << "\t" << "姓名" << "\t"
		<< "电子" << "\t" << "C++" << "\t" << "多媒体" << "\t"
		<< "英语" << "\t" << "数学" << "\t" << "体育" << "\t"
		<< "政治" << "\t" << "平均分" << "\t" << "总分" << endl;
	cout << "------------------------------------------------------------------------------------" << endl;
	for (int i = 0; i < n; i++) {
		stu[i].order = i + 1;
		cout << stu[i].class_0 << "\t" << stu[i].num << "\t" << stu[i].name << "\t"
			<< stu[i].elec << "\t" << stu[i].c_program << "\t" << stu[i].media << "\t"
			<< stu[i].english << "\t" << stu[i].math << "\t" << stu[i].sport << "\t"
			<< stu[i].polity << "\t" << stu[i].average << "\t" << stu[i].total << endl;
	}
	Write(stu, n);
}

//显示全部学生成绩
void Output(Student stu[]) {
	system("cls");
	int n = Read(stu);
	cout << endl << "======>>    显示全部学生成绩    <<======" << endl;
	if (!stu) {
		cout << "没有记录";
	}
	else {
		cout << "-------------------------------------------------------------------------------------------------" << endl;
		cout << "班级" << "\t" << "学号" << "\t" << "姓名" << "\t"
			<< "电子" << "\t" << "C++" << "\t" << "多媒体" << "\t"
			<< "英语" << "\t" << "数学" << "\t" << "体育" << "\t"
			<< "政治" << "\t" << "平均分" << "\t" << "总分" << endl;
		cout << "-------------------------------------------------------------------------------------------------" << endl;
		for (int i = 0; i < n; i++) {
			cout << stu[i].class_0 << "\t" << stu[i].num << "\t" << stu[i].name << "\t"
				<< stu[i].elec << "\t" << stu[i].c_program << "\t" << stu[i].media << "\t"
				<< stu[i].english << "\t" << stu[i].math << "\t" << stu[i].sport << "\t"
				<< stu[i].polity << "\t" << stu[i].average << "\t" << stu[i].total << endl;
		}
		cout << "-------------------------------------------------------------------------------------------------" << endl;
	}
}

//按平均分排序图形化菜单
int Sort() {
	char c;
	do {
		system("cls");
		cout << "******************************************************" << endl;
		cout << "----------------按平均分排列---------------------------" << endl;
		cout << "    *          【11】升序排列                     *    " << endl;
		cout << "    *          【22】降序排列                     *    " << endl;
		cout << "    *          【0】返回主页                      *    " << endl;
		cout << "******************************************************" << endl;
		cout << "请选择您的操作 (0-2):" << endl;
		c = getchar();
	} while (c < '0' || c > '2');
	return (c - '0');
}

//查找学生成绩图形化菜单
int Lookup() {
	char c;
	do {
		system("cls");
		cout << "******************************************************" << endl;
		cout << "----------------查找学生成绩---------------------------" << endl;
		cout << "    *          【11】按姓名查找                   *    " << endl;
		cout << "    *          【22】按学号查找                   *    " << endl;
		cout << "    *          【0】返回主页                      *    " << endl;
		cout << "******************************************************" << endl;
		cout << "请选择您的操作 (0-2):" << endl;
		c = getchar();
	} while (c < '0' || c > '2');
	return (c - '0');
}

//图形化主菜单
int Menu() {
	char c;
	do {
		system("cls");
		cout << "******************************************************" << endl;
		cout << "----------------欢迎使用学生成绩管理系统---------------" << endl;
		cout << "    *          【1】输入学生成绩                  *    " << endl;
		cout << "    *          【2】显示统计数据                  *    " << endl;
		cout << "    *          【3】查找学生成绩                  *    " << endl;
		cout << "    *          【4】修改学生成绩                  *    " << endl;
		cout << "    *          【5】删除学生成绩                  *    " << endl;
		cout << "    *          【6】插入学生成绩                  *    " << endl;
		cout << "    *          【7】按平均分排列                  *    " << endl;
		cout << "    *          【8】显示学生成绩                  *    " << endl;
		cout << "    *          【0】退出管理系统                  *    " << endl;
		cout << "******************************************************" << endl;
		cout << "请选择您的操作 (0-8):" << endl;
		c = getchar();
	} while (c < '0' || c > '8');
	return (c - '0');
}

//登录界面
void Welcome()//登陆界面
{
	cout << "******************************************************" << endl;
	cout << "---------欢迎使用学生成绩管理系统---------" << endl;
	cout << "                   制作人:梨涡泥窝                     " << endl;
	cout << "                   班级:计科                   " << endl;
	cout << "******************************************************" << endl;
	cout << "请您输入管理员登陆信息:" << endl;
}

//查找学生成绩执行条件
void CarryLookup()
{
	for (; Lookup() != 0;) {
		switch (Lookup()) {
		case 1:
			LookupName(stu);
			system("pause");
			break;
		case 2:
			LookupNum(stu);
			system("pause");
			break;
		case 0:
			break;
		}
	}
}

//按平均分排序执行条件
void CarrySort()
{
	while (Sort() != 0) {
		switch (Sort()) {
		case 1:
			Ascend(stu);
			system("pause");
			break;
		case 2:
			Descend(stu);
			system("pause");
			break;
		case 0:
			break;
		}
	}
}

//主菜单执行条件
void CarryMenu()
{
	for (;;) {
		switch (Menu()) {
		case 1:
			Input(stu);
			break;
		case 2:
			Statistic(stu);
			break;
		case 3:
			CarryLookup();
			system("pause");
			break;
		case 4:
			Modify(stu);
			system("pause");
			break;
		case 5:
			Delete(stu);
			system("pause");
			break;
		case 6:
			Insert(stu);
			system("pause");
			break;
		case 7:
			CarrySort();
			system("pause");
			break;
		case 8:
			Output(stu);
			system("pause");
			break;
		case 0:
			cout << endl << "================感谢您使用学生成绩管理系统==============\n" << endl;
			exit(0);
		}
	}
}

//管理员账号密码
int main() {
	system("color 70");
	Welcome();
	char ID[10];//管理员的账号
	char password[10];//密码
	mag a;
	strcpy(a.ID, "lzx");//把后者的内容拷贝到前者中
	strcpy(a.password, "123");//把后者的内容拷贝到前者中
	for (;;) {
		cout << "请输入管理员登录账号和密码:" << endl;
		cout << "账号:";
		cin >> ID;
		cout << "密码:";
		cin >> password;
		if ((strcmp(ID, a.ID) == 0) && (strcmp(password, a.password) == 0))
			CarryMenu();
		else {
			cout << "账号或密码不对:" << endl;
			continue;
		}
	}
	return 0;
}

2.测试运行结果

【0】登陆界面及主菜单:

数据结构与算法 课程设计报告——学生信息管理系统_第3张图片

数据结构与算法 课程设计报告——学生信息管理系统_第4张图片

【1】输入学生成绩(首次输入):  

数据结构与算法 课程设计报告——学生信息管理系统_第5张图片

【2】显示统计数据:

数据结构与算法 课程设计报告——学生信息管理系统_第6张图片

【3】查找学生成绩:    

数据结构与算法 课程设计报告——学生信息管理系统_第7张图片 数据结构与算法 课程设计报告——学生信息管理系统_第8张图片

【4】修改学生成绩:

数据结构与算法 课程设计报告——学生信息管理系统_第9张图片

【5】删除学生成绩:        

数据结构与算法 课程设计报告——学生信息管理系统_第10张图片      

【6】插入学生成绩:

数据结构与算法 课程设计报告——学生信息管理系统_第11张图片

【7】按平均分排列:

数据结构与算法 课程设计报告——学生信息管理系统_第12张图片数据结构与算法 课程设计报告——学生信息管理系统_第13张图片

【8】显示学生成绩:

数据结构与算法 课程设计报告——学生信息管理系统_第14张图片

五、开发日志

1. 时间:2021.12.15

老师要求做一个学生管理系统,据分析,需要对学生个人信息和成绩进行增删改查的功能实现,起初用的是Codeblocks来进行编写代码,后来觉得用Visual Studio来编写,在操作上更得心应手,于是改用后者。

将已经编写的代码复制到Visual Studio时提示strcpy函数错误,后来了解后跟scanf_s一样,也是要添加_s来保证此函数更安全。

2. 时间:2021.12.16

想设计一个二级菜单,以容纳降序或升序的选择及按姓名或学号查询信息。按姓名查询时想了一下要用什么算法来进行匹配,考虑到名字并不是很长的字符串,用了BF算法来进行查找匹配姓名,其他算法也有想过,但是相比BF算法代码量大而且复杂度差不多,最终还是选择BF算法。

在设计二级菜单时遇到了但返回主菜单时老是返回之前的二级菜单,原因是在子菜单函数里调用了主菜单的函数,而且无法跳出这个递归,造成无限循环。经过删除该引用主菜单的函数后,恢复正常。

3. 时间:2021.12.19

经检查功能,还差一个待实现的功能,就是求各科平均分、最高分和最低分,该功能将所有学生的成绩全部过一遍,而得出学生成绩,但该功能的算法还可以进一步优化。

经过一上午的努力,把功能全部实现了,新学会了如何读写文件,如何给程序设计一个账号密码进行访问等。

六、设计总结

在完成一个项目时,首先捋顺大流程,确立主要的框架,预留各个功能的接口后会比较合理且高效。同样的,类似甚至完全相同的功能可以通过共用函数来提高效率,减少部分工作量。由于功能完成后需要合并进行联调,对完成的功能中函数的命名也不能太过随意,避免有函数重名等现象;并且添加注释也会有助于别人的理解,也有助于联调时查错、改正。

在实训过程中,使我良好的锻炼了自己,首先是兴趣方面,通过编写学生信息管理系统使我更加喜欢编程,使我从以前的迷茫状态中解脱出来,使我了解了编程的真正意义。我想这对我以后的人生有着很大的帮助。其次通过学生信息管理系统使我对写程序有了一定的思路,不像以前无从下手,使我理解了算法的意义,使我懂得了模块化思想的好处。

通过数节课的编写代码,使我对书本上的知识有了更深的理解,甚至有很多不懂的问题在这过程中自然而然的理解了。对期末考试更有了信心。在周老师的悉心指导下,我对C++语言有了更深刻的理解,对程序的算法,数据的定义,程序的改错等方面的能力有了很大提高,自身的注意力,耐心,和对编程的兴趣有了很大增长,使我获益匪浅。

你可能感兴趣的:(数据库,c++,visualstudio)