目 录
第一章 需求分析
第二章 概要设计
第三章 详细设计
第四章 测试报告
第五章 安装及使用
第六章 项目总结
第七章 源码
一.需求分析
学生成绩管理是一个学校不可缺少的部分,它的内容对于学校的管理者和学生以及学生家长来说都至关重要,所以一个良好的学生成绩管理系统应该能够为用户提供充足的信息和快捷的查询手段。学生成绩管理系统对学校加强学生成绩管理有着极其重要的作用.由于各个大学都在持续扩招,学生的数量日益庞大,对于如何管理如此庞大的学生成绩数据显得更为复杂,传统的手工成绩管理不仅工作量大,而且容易出现问题,如:效率低、保密性差,另外时间一长,将产生大量的文件和数据,这对于查找、更新和维护都带来了不少的困难。已不能适应时代的发展。本作品能实现学生信息的快速添加,查找,排序,插入,删除,修改,输出平均成绩及总和。为老师录学生成绩提供较大的方便,提高效率,节省时间。
二.概要设计
1.功能设计
该学生成绩管理系统可以按功能进行模块划分,其模块图如图所示。
2.功能运行流程图
系统的执行应从功能菜单的选择开始,依据用户的选择来进行后续的处理,直到用户选择保存数据并退出系统为止,其间应对用户的选择做出判断及异常处理。系统的流程图如图所示。、
三.详细设计
界面设计:
关键算法:
四.测试报告
功能测试图:
功能2,3,4,5,6,7,8,9与以上的1功能运行界面类似,测试结果正确且运行快速。
测试总结:本作品可实现学生信息的快速添加,查找,排序,插入,删除,修改,输出平均成绩及总和。在测试过程中,程序运行速度快,信息安全性封闭性高,拓展性强,对于老师录成绩来说方便性跟可用性高。
五.安装及使用
1.打开事先存放好程序的文件
2.点击程序。
3.使用vs2022运行即可。
4.操作进行的任何信息处理都已经放在运行时创建的文件里。
5.根据系统界面操作即可。
六.项目总结
感悟:
作品制作过程中对界面操作系统与存储文件的对接理解更深刻了,对学生不同信息的增删改存的设计属于分块设计,最后通过界面将它们联系在一起,实现学生信息管理系统的功能实现。
后续升级方向:
1.输出所有学生信息太多了,后续可以细化设计,如输出某个班的学生的信息,某门课的一个班的学生的信息。
2.目前信息系统只适用教师对系统进行使用,后续可增加学生进行自己的信息的查询功能,使系统功能更加多样化。
3.程序集中在一个文件,不太便于后续分块升级,之后可以将代码分文件存储,以便优化和系统升级。
七.源码
#include <iostream>
#include <fstream>
#include <list>
#include <sstream> //字符串转换
using namespace std;
//信息管理系统类
class Mamasys
{
private:
//学生全局结构
struct Student
{//虽然学生属性都是字符串类型,但是后面对数据进行处理时,
//也会将部分字符串数据转换为数字类型进行操作
string name; //姓名
string age; //年龄
string num; //学号
string CppScore; //C++成绩
string MathScore; //高等数学成绩
};
list<Student> studlist; //存储所有学生信息的容器
string path; //文件路径
//将容器中所有信息写入到文件中
void ofsallMess()
{
ofstream ofst;
//以清空源文件内容方式打开文件
ofst.open(path, ios::trunc);
//判断文件是否打开成功
if (!ofst.is_open())
{
cout << "文件打开失败" << endl;
return;
}文章来源地址https://www.toymoban.com/news/detail-782099.html
//将容器中的所有信息写入到文件中,这里的endl必须在开头写,末尾不能写,否则会出现一系列问题
for (list<Student>::const_iterator it = studlist.begin(); it != studlist.end(); it++)
ofst << endl << it->num << endl << it->name << endl << it->age << endl << it->CppScore << endl << it->MathScore;
//关闭文件
ofst.close();
}
public:
//构造函数用于将文件中的内容按格式读取到list<Student>中
Mamasys()
{
cout << "输入你的文件路径,加后缀名,一般为txt文件(没有则创建该文件):" << endl;
cin >> path;
ifstream ifstr;
ifstr.open(path, ios::in); //打开文件路径中的文件,如果打开失败则创建该文件
if (!ifstr.is_open())
{
ofstream temp(path); //创建文件
temp.open(path, ios::out);
if (!temp.is_open()) //检测是否创建成功
{
cout << "创建文件失败,退出程序" << endl;
exit(-1);
}
//文件成功创建则关闭文件
temp.close();
}
system("cls");
//将文件中所有内容读取到list容器中
ifstream ifst;
ifst.open(path, ios::in);
char line[14]; //这里必须是字符数组
Student temp;
//空读取一行因为新文件第一行不保存内容
ifst.getline(line, sizeof(line));
//成行读取文件中的内容
//循环读取五行信息,每五行将信息插入到容器中
while (!ifst.eof())
{
//保存到临时学生temp中
ifst.getline(line, sizeof(line));
temp.num = line; //学号
ifst.getline(line, sizeof(line));
temp.name = line; //姓名
ifst.getline(line, sizeof(line));
temp.age = line; //年龄
ifst.getline(line, sizeof(line));
temp.CppScore = line; //C++成绩
ifst.getline(line, sizeof(line));
temp.MathScore = line; //高数成绩
//将temp插入到学生容器中
studlist.push_back(temp);
}
Hint(); //显示提示信息
}
//输出提示信息成员函数
void Hint()
{
cout << "--------学生信息管理系统--------" << endl << 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 << "9 退出程序" << endl << endl;
cout << "所有功能在执行完毕后,都会自动将当前信息保存进文件" << endl << endl;
}
//添加学生信息
bool AddMess()
{
//创建一个学生结构
Student student;
L1:
//输出提示信息,并输入学生信息,输入-1结束输入
cout << "学号: "; cin >> student.num;
if (student.num == "-1") return false;
//读入学号时,遍历所有的学生学号信息,如果学号相同则输出提示并重新输入
for (list<Student>::const_iterator it = studlist.begin(); it != studlist.end(); it++)
if (it->num == student.num)
{
cout << endl << "学号信息重复,请重新输入:" << endl << endl;
goto L1; //返回到输入的地方
}
//返回false则停止添加学生信息
cout << "姓名: "; cin >> student.name;
if (student.name == "-1") return false;
cout << "年龄: "; cin >> student.age;
if (student.age == "-1") return false;
cout << "C++成绩: "; cin >> student.CppScore;
if (student.CppScore == "-1") return false;
cout << "高数成绩: "; cin >> student.MathScore;
if (student.MathScore == "-1") return false;
cout << endl;
studlist.push_back(student); //将新添加的学生信息尾插到容器中
//只将新添加的学生信息追加到文件中
//创建写入流对象
ofstream ofst;
//在文件路径中以追加方式打开文件
ofst.open(path, ios::app);
//将学生信息按顺序写入到文件中,这里的endl,只能按照这个格式写
ofst << endl << student.num << endl << student.name << endl << student.age << endl << student.CppScore << endl << student.MathScore;
//关闭文件
ofst.close();
//返回true继续录入学生信息
return true;
}
//查看所有学生信息
void PrintMess()
{
cout << endl;
for (list<Student>::const_iterator it = studlist.begin(); it != studlist.end(); it++)
{
cout << "学号: " << it->num << endl;
cout << "姓名: " << it->name << endl;
cout << "年龄: " << it->age << endl;
cout << "C++成绩: " << it->CppScore << endl;
cout << "高数成绩: " << it->MathScore << endl << endl;
}
}
//查找(姓名||学号)
void FindMess()
{
char key;
cout << "输入1代表按学号查找,其他代表按姓名查找" << endl;
cin >> key;
//按学号查找
if (key == '1')
{
string findnum;
cout << "请输入需要查找的学生序号:";
cin >> findnum;
for (list<Student>::const_iterator it = studlist.begin(); it != studlist.end(); it++)
if (it->num == findnum)
{
cout << "学号: " << it->num << endl;
cout << "姓名: " << it->name << endl;
cout << "年龄: " << it->age << endl;
cout << "C++成绩: " << it->CppScore << endl;
cout << "高数成绩: " << it->MathScore << endl << endl;
return; //因为学号具有唯一性,所以找到后输出完信息直接返回
}
//函数没有结束执行到这里说明没有找到学号,输出提示信息
cout << "没有找到学号为“ " << findnum << " ”的学生" << endl;
}
//按姓名查找
else
{
string findname;
cout << "请输入需要查找的学生姓名:";
cin >> findname;
bool sign = false; //标记是否找到学生
//输出所有名为findname的学生信息
for (list<Student>::const_iterator it = studlist.begin(); it != studlist.end(); it++)
if (it->name == findname)
{
cout << "学号: " << it->num << endl;
cout << "姓名: " << it->name << endl;
cout << "年龄: " << it->age << endl;
cout << "C++成绩: " << it->CppScore << endl;
cout << "高数成绩: " << it->MathScore << endl << endl;
sign = true;
}
//如果没有找到则输出提示信息
if (!sign)
cout << "没有找到名为“" << findname << "”的学生" << endl;
}
}
private:
//通过二元谓词改变list.stor()的排序规则
class Studentrule_1_1
{//按照学号升序排序
public:
bool operator()(Student& p1, Student& p2)
{
//将属性字符转换为数字,然后根据数字排序
int temp_1; stringstream ss_1; ss_1 << p1.num; ss_1 >> temp_1;
int temp_2; stringstream ss_2; ss_2 << p2.num; ss_2 >> temp_2;
return temp_1 < temp_2;
}
};
class Studentrule_1_2
{//按照学号降序排序
public:
bool operator()(Student& p1, Student& p2)
{
//将属性字符转换为数字,然后根据数字排序
int temp_1; stringstream ss_1; ss_1 << p1.num; ss_1 >> temp_1;
int temp_2; stringstream ss_2; ss_2 << p2.num; ss_2 >> temp_2;
return temp_1 > temp_2;
}
};
class Studentrule_2_1
{//按照C++升序排序
public:
bool operator()(Student& p1, Student& p2)
{
//将属性字符转换为数字,然后根据数字排序
int temp_1; stringstream ss_1; ss_1 << p1.CppScore; ss_1 >> temp_1;
int temp_2; stringstream ss_2; ss_2 << p2.CppScore; ss_2 >> temp_2;
return temp_1 < temp_2;
}
};
class Studentrule_2_2
{//按照C++降序排序
public:
bool operator()(Student& p1, Student& p2)
{
//将属性字符转换为数字,然后根据数字排序
int temp_1; stringstream ss_1; ss_1 << p1.CppScore; ss_1 >> temp_1;
int temp_2; stringstream ss_2; ss_2 << p2.CppScore; ss_2 >> temp_2;
return temp_1 < temp_2;
}
};
class Studentrule_3_1
{//按照高数升序排序
public:
bool operator()(Student& p1, Student& p2)
{
//将属性字符转换为数字,然后根据数字排序
int temp_1; stringstream ss_1; ss_1 << p1.MathScore; ss_1 >> temp_1;
int temp_2; stringstream ss_2; ss_2 << p2.MathScore; ss_2 >> temp_2;
return temp_1 < temp_2;
}
};
class Studentrule_3_2
{//按照高数降序排序
public:
bool operator()(Student& p1, Student& p2)
{
//将属性字符转换为数字,然后根据数字排序
int temp_1; stringstream ss_1; ss_1 << p1.MathScore; ss_1 >> temp_1;
int temp_2; stringstream ss_2; ss_2 << p2.MathScore; ss_2 >> temp_2;
return temp_1 < temp_2;
}
};
public:
//指定排序规则
//1,按照学号升序
//排序
void SortMess()
{
char key_1 = '0';
cout << "输入1代表按学号排序,输入2代表按C++成绩排序,其他代表按高数成绩排序" << endl;
cin >> key_1; //接收键值执行不同的排序规则
cout << "输入1代表升序排序,其他代表降序排序" << endl;
char key_2 = '0';
cin >> key_2;
switch (key_1)
{
case '1': key_2 == '1' ? studlist.sort(Studentrule_1_1()) : studlist.sort(Studentrule_1_2()); break;
case '2': key_2 == '1' ? studlist.sort(Studentrule_2_1()) : studlist.sort(Studentrule_2_2()); break;
default: key_2 == '1' ? studlist.sort(Studentrule_3_1()) : studlist.sort(Studentrule_3_2());
}
//将容器中内容写入文件中
ofsallMess();
cout << "已排序" << endl;
}
//向中间插入学生数据
void InsertMess()
{
string instudnum = "0";
bool sign = false;
L1:
cout << "请输入需要插入在学生前面的该学生的学号:" << endl;
cin >> instudnum;
list<Student>::const_iterator it;
for (it = studlist.begin(); it != studlist.end(); it++)
if (instudnum == it->num) break;
//如果it==容器末尾迭代器了,则说明没有找到该学号
if (it == studlist.end())
{
cout << "没有找到该学号" << endl;
goto L1;
}
//创建一个学生结点,将该结点信息,插入到容器中
Student student;
L2:
//输出提示信息,并输入学生信息
cout << "学号: "; cin >> student.num;
//读入学号时,遍历所有的学生学号信息,如果学号相同则输出提示并重新输入
for (list<Student>::const_iterator it = studlist.begin(); it != studlist.end(); it++)
if (it->num == student.num)
{
cout << "学号信息重复,请重新输入:" << endl;
goto L2; //返回到输入的地方
}
//输入这个学生的信息
cout << "姓名: "; cin >> student.name;
cout << "年龄: "; cin >> student.age;
cout << "C++成绩: "; cin >> student.CppScore;
cout << "高数成绩: "; cin >> student.MathScore;
//将该结点插入到容器中
studlist.insert(it, student);
//将容器中内容写入文件中
ofsallMess();
cout << "已插入" << endl;
}
//删除学生的数据
void DeteleMess()
{
char key = '0';
cout << "输入1代表按学号删除单个学生数据,其他代表按姓名删除所有学生数据" << endl;
cin >> key;
if (key == '1')
{
//从容器中查找和需要删除和学生的学号一样的学号,找到则删除,并刷新文件内容
string detestunum;
cout << "请输入需要删除的学生的学号:" << endl;
cin >> detestunum;
for (list<Student>::const_iterator it = studlist.begin(); it != studlist.end(); it++)
if (it->num == detestunum)
{
studlist.erase(it);
ofsallMess();
cout << "已删除" << endl;
return;
}
cout << "没有找到该学号的学生" << endl;
}
else
{
string detestuname;
cout << "请输入需要删除的学生的姓名:" << endl;
cin >> detestuname;
bool sign = false;
//遍历容器寻找与需要删除姓名的学生相同名的学生,找到了则删除
for (list<Student>::const_iterator it = studlist.begin(); it != studlist.end(); it++)
if (it->name == detestuname)
{
//这里有点问题,连续的重名无法清除,只能先用笨办法解决了
it = studlist.erase(it);
if (it->name == detestuname) it = studlist.erase(it);
if (it->name == detestuname) it = studlist.erase(it);
if (it->name == detestuname) it = studlist.erase(it);
if (it->name == detestuname) it = studlist.erase(it);
ofsallMess(); //刷新文件
sign = true;
}
//输出提示信息
if (sign == false)
cout << "没有找到该姓名的学生" << endl;
else
cout << "已删除" << endl;
}
}
//修改学生的信息
void ModifyMess()
{
string Modstudentnum;
L1:
cout << "请输入需要修改的学生的学号:" << endl;
cin >> Modstudentnum;
//接收学号后,先遍历一遍容器查看是否有该学号,如果没有则重新输入
list<Student>::const_iterator it;
for (it = studlist.begin(); it != studlist.end(); it++)
if (it->num == Modstudentnum) break;
if (it == studlist.end())
{
cout << "没有找到该学号";
goto L1;
}
//修改迭代器指向结点的值
for (list<Student>::iterator it = studlist.begin(); it != studlist.end(); it++)
if (it->num == Modstudentnum)
{
//先输出原信息
cout << endl << "该学生原信息:" << endl << endl;
cout << "学号: " << it->num << endl;
cout << "姓名: " << it->name << endl;
cout << "年龄: " << it->age << endl;
cout << "C++成绩: " << it->CppScore << endl;
cout << "高数成绩: " << it->MathScore << endl << endl;
//再修改
cout << "需要修改信息:" << endl << endl;
cout << "学号: "; cin >> it->num;
cout << "姓名: "; cin >> it->name;
cout << "年龄: "; cin >> it->age;
cout << "C++成绩: "; cin >> it->CppScore;
cout << "高数成绩: "; cin >> it->MathScore;
break;
}
//刷新文件中的信息
ofsallMess();
cout << endl << "已修改" << endl;
}
//C:\\Users\\ASUS\\Desktop\\测试, txt
//统计学生数据
void StatMess()
{
//功能:返回学生的总个数
//所有学生各成绩的总分、平均分
//年龄和、平均年龄
int cppscoresum = 0, mathscoresum = 0; //成绩和
int cppscoreave = 0, mathscoreave = 0; //成绩平均值
int agesum = 0, ageave = 0, num = 0; //年龄和、年龄平均值、学生数
for (list<Student>::iterator it = studlist.begin(); it != studlist.end(); it++)
{
//将C++成绩转换为数字
int Cpptemp;
stringstream ss_1;
ss_1 << it->CppScore;
ss_1 >> Cpptemp;
cppscoresum += Cpptemp; //统计C++成绩和
//将数学成绩转换为数字
int Mathtemp;
stringstream ss_2;
ss_2 << it->MathScore;
ss_2 >> Mathtemp;
mathscoresum += Mathtemp; //统计数学成绩和
//将年龄转换为数字
int Agetemp;
stringstream ss_3;
ss_3 << it->age;
ss_3 >> Agetemp;
agesum += Agetemp; //统计年龄和
num++;
}
//C++平均成绩
cppscoreave = cppscoresum / num;
//数学平均成绩
mathscoreave = mathscoresum / num;
//平均年龄
ageave = agesum / num;
cout << "总学生数:" << num << endl << endl;
cout << "C++平均成绩:" << cppscoreave << " C++总成绩:" << cppscoresum << endl << endl;
cout << "高等数学平均成绩:" << mathscoreave << " 数学总成绩:" << mathscoresum << endl << endl;
cout << "平均年龄:" << ageave << endl << endl;
}
};
//主函数
int main()
{
//设置控制台标题
system("title C++ 学生信息管理系统");
//创建管理系统对象
Mamasys mamasys;
//key接收一个值,根据key的值执行不同的功能
char key = '0';
cout << endl << "请输入需要执行的功能:" << endl;
cin >> key;
cout << endl;
while (true)
{
switch (key)
{
case '1': //添加学生信息
cout << "自动循环添加数据,结束添加请输入-1" << endl << endl;
while (mamasys.AddMess());
cout << endl << "已添加" << endl << endl;
break;
case '2': //输出所有信息
mamasys.PrintMess();
break;
case '3': //查找 姓名||学号
mamasys.FindMess();
break;
case '4': //排序 学号、C++成绩、高数成绩、升序、降序
mamasys.SortMess();
break;
case '5': //在中间插入学生数据
mamasys.InsertMess();
break;
case '6': //删除学生的数据
mamasys.DeteleMess();
break;
case '7': //修改学生的数据
mamasys.ModifyMess();
break;
case '8': //修改学生的数据
mamasys.StatMess();
break;
case '9': //退出程序
return 0;文章来源:https://www.toymoban.com/news/detail-782099.html
}
system("pause");
system("cls"); //每次功能执行完,清屏,输出提示信息
mamasys.Hint();
//功能执行完毕,key再接收一个值
cout << endl << "请输入需要执行的功能:" << endl;
cin >> key;
cout << endl;
}
return 0;
}
到了这里,关于数据结构课程设计:学生成绩管理系统的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!