做免费的网站教程,一个云主机可以做多少网站,民营建筑设计公司排名,seo交流博客目录
一、基本功能#xff1a;
二、包含的模块#xff1a;
三、系统介绍
1. 学生管理系统的功能#xff1a;
2. 具体的需求#xff1a;
3. 支持的标准#xff1a;
四、系统结构功能图#xff1a;
五、系统设计
1. 退出系统#xff1a;
2. 增加学生#xff1a…目录
一、基本功能
二、包含的模块
三、系统介绍
1. 学生管理系统的功能
2. 具体的需求
3. 支持的标准
四、系统结构功能图
五、系统设计
1. 退出系统
2. 增加学生
3. 展示学生
4. 删除学生
5. 修改学生
6. 查找学生
7. 学号排序
七、设计结果
1. 菜单页面
2. 增加学生页面
3. 显示学生页面
4. 删除学生页面
5. 修改学生页面
6. 查找及模糊查找学生页面
7. 学号排序页面
八、源码
1. 学生管理系统.cpp
2. info.cpp
3. studentManager.cpp
4. student.h
5. studentManager.h
6. info.h 学生管理系统是大一刚入学时的作品了比较稚嫩希望各位大佬进行批评指正。 设计说明
本系统为学生管理系统采用c语言在Visual Studio平台进行开发。 一、基本功能
1退出学生系统
2增加学生信息
3显示学生信息
4删除离校学生
5修改学生信息
6查找学生信息
7按照学号排序 二、包含的模块
1studentManager学生管理类内设上述1-7的功能函数
2Student学生类内设学生的学号、姓名等基本信息和展示学生信息的函数
3Info学生信息类继承Student学生类初始化Student类中的数据和函数 三、系统介绍
1. 学生管理系统的功能
退出系统增加学生显示学生删除学生修改学生查找学生排序学生。
2. 具体的需求
增加学生时学号不能是重复的且必须为12位数字年份前4位数字在一个合理的区间
性别只能为男或女年龄在一个合理的区间地址和专业可以为缺失值
删除和修改学生时如果输入了不存在的学号则返回错误输入的学号存在才能正常继续操作
查找学生可以是准确信息如广东省查找也可以多条件查找如18岁的浙江省男生还可以是模糊值查找如名字里含小字的学生这些不同类型的查找方法都可以计算符合条件的学生人数
排序学生是按照学号从小到大进行排序。
3. 支持的标准
Windows 11 版本 21H2 或更高版本家庭版、专业版、专业教育版、专业工作站版、企业版和教育版
Windows 10 版本 1909 或更高版本家庭版、专业版、教育版和企业版。
Windows Server Core 2022
Windows Server Core 2019
Windows Server 核心 2016 四、系统结构功能图 五、系统设计
1. 退出系统
使用exit函数返回0给系统即exit(0)以示正常退出中止程序。并打印您已退出系统欢迎下次使用以提示用户。 2. 增加学生
2.1判断学号是否存在isStuExit(num)
先设置一个index默认为-1for循环遍历数组内保存的学生学号若有学号与用户输入的学号一致则令index为该学号在数组中的位置。返回结果为若学号已存在返回学号在数组中的位置若学号不存在返回-1。 2.2 切割字符串的前n个字符getNchar(string str, int n)
nChars变量是保存切割后的字符参数str是要被切割的字符串n是要切割的字符个数。首先判断n是否0若不大于0则提示错误若字符串本身则n字符串本身长度其他情况则for循环n次把str的前n个字符通过push_back函数依次传到nChars内最后返回nChars。 2.3 保存文件saveStu()
先fstream File创建一个文件流然后File.open(“student.txt”ios::out创建或打开student.txt文件使用ios::out的方式写入文件。利用for循环遍历this-sStuArray数组中的每个对象中的每个信息sNum、sName等依次通过File 的方式写入文件最后用File.close()函数关闭文件使数据真正保存到文件中。 2.4 具体设计过程及功能算法描述
先提示用户输入想要添加的人数将新增的个数保存到变量addCount里面如果addCount0则提示错误终止添加如果addCount0则进入添加学生的程序。
先用newCount addCount this-sCount即最新人数 新增人数 原本人数来保存最新人数。
因为要创建父类指针学生类Student* 来指向子类指针Info具体学生所以用Student**指针来开辟一个新空间newSpace来保存new出来的Student*[newCount]大小。
接着判断一下原本的存放学生的数组是否为空如果不为空则先for循环把原本数组内的学生存到新空间内再进行添加新学生如果为空则直接添加新学生。
利用for循环遍历addCount次在内部设置学生信息的变量Num学号、Name姓名、Sex性别、Age年龄、Adress住址、Major专业。
然后提示用户输入要添加的学生学号对用户输入的学号进行判断若已存在则提示该学号已存在若不存在则继续进行其他判断Num.length()12学号的长度12 splitNum “2004” splitNum ”2023”
利用2.2的函数来截取学号的前4个字符判断是否在2004到2023的区间任一项不满足则提示错误都满足则添加其他信息。提示用户输入学生姓名性别。
性别设置ifSex”男” || Sex“女”判断只能输入“男”或“女”如输入其他字符则提示错误输入正确则提示用户输入年龄。
IfAge 14 Age 30判断年龄在14和30之间若不满足则提示错误若满足则询问用户是否录入学生地址和专业是则录入否则设置Adress地址或Major专业为“ “空格。
全部信息输入完成后新建一个Student*的指针对象stu使stu等于new出来的Info对象把NumName等学生信息传入进行初始化然后再让newSpace的this-sCount i个对象等于stu即录入成功。让this-sCount等于newCount更新为最新人数输出“添加成功”提示用户。
然后delett[]释放原本的内存空间数组再让this-sStuArray等于newSpace更新数组最后利用2.3的函数保存文件。 2.5 流程图 3. 展示学生
3.1变量isFileEmpty
文件是否为空的标志在构造函数内进行初始化。首先fstream File.open(“student.txt”, ios::in)打开文件if(!File.is_open()即利用is_open函数判断文件是否不存在若不存在为真则输出提示文件不存在再char chFile c设置一个变量ch接收读取到的文件的第一个字符if(File.eof())判断读取到的eof()是否为真。因为eof是文件尾部的标志若读取到第一个字符就是eof就代表文件读到头了则文件存在但为空其它情况则是文件存在且有数据则进行一系列初始化。 3.2 具体设计过程及功能算法描述
先用3.1的isFileEmpty属性判断文件是否存在若为真则提示“文件不存在或为空”其它则进入循环遍历sStuArray数组中的每个学生对象调用每个学生对象的内置函数showInfo()展示学生信息。最后退出程序。 3.3 流程图 4. 删除学生
4.1 this-sCount: 学生人数 4.2 具体设计过程及功能算法描述
首先用3.1的isFileEmpty标志判断文件是否存在为真则提示“文件不存在或为空”为假则提示“请输入您想要删除的学生学号”用变量num来保存用户输入的学号。
再用2.1的isStuExit(num)函数来判断想要删除的学号是否存在不存在则提示删除失败存在则利用isStuExit(num)返回的index该学号在数组中的位置删除数组中该位置的学生。
For循环从i index学号在数组中的位置开始遍历让数组中第[i 1]个依次覆盖第[i]个直到循环结束。
然后用4.1的this-sCount--更新学生人数2.3的this-saveStu()保存学生信息到文件提示“删除成功”。 4.3 流程图 5. 修改学生
5.1 具体设计过程及功能算法描述
首先用3.1的isFileEmpty标志判断文件是否存在为真则提示“文件不存在或为空”为假则提示“请输入您想要修改的学生学号”用变量num来保存用户输入的学号。
再用2.1的isStuExit(num)函数来判断想要修改的学号是否存在不存在则提示删除失败存在则利用isStuExit(num)返回的index该学号在数组中的位置修改数组中该位置的学生。
提示“查找成功 请输入您想要修改的学生信息”输入1-6的数字为单独修改学生的学号、姓名等用变量choose保存用户输入的数字。
若为1则代表要修改该学生的学号先用2.1的isStuExit(num)函数来判断想要修改的新学号是否存在若存在则提示“修改失败”
若不存在则this-sStuArray[index]-sNum newNum即令学生数组中的第index该学号在数组中的位置个的学号等于用户输入的新学号提示“修改成功”。
其他的修改情况以此类推。最后用2.3的saveStu()保存文件。 5.2 流程图 6. 查找学生
6.1 具体设计过程及功能算法描述
首先用3.1的isFileEmpty标志判断文件是否存在为真则提示“文件不存在或为空”为假则提示“请输入您想要查找的方式”用变量choose来保存用户输入的查找方式。输入1-6分别是按学号、姓名、性别等查找输入7是多条件查找输入8是模糊查找。
若输入1是按学号查找用2.1的isStuExit(num)函数来判断想要查找的学号是否存在不存在则提示查找失败存在则利用isStuExit(num)返回的index该学号在数组中的位置展示数组中该位置的学生信息
若输入2是按姓名查找提示用户输入想查询的姓名用变量name保存用户输入的姓名。先设置一个flag false表示默认未找到count 0表示符合条件的学生人数默认为0然后进入循环遍历学生数组。如果第i个学生名字与用户输入的name相匹配则调用showInfo展示该学生信息且令flag true找到学生count符合条件的学生人数1。如果flag false说明没找到提示查找失败。其他类型的查找以此类推
若输入7是多条件查找根据用户输入的查找条件遍历学生数组如多条件都能匹配则输出该学生信息
若输入8是模糊查找输入名字中的一个字可以找到名字中有这个字的所有学生。利用外层for循环i this-sCount遍历学生数组内层for循环j this-sStuArray[i]-sName.length()遍历学生数组中每个学生的名字ifthis-sStuArray[i]-sName[j] name即如果名字中有任何一个字与用户输入的字符匹配上了则输出该学生的信息。 6.2 流程图(由于有的功能太过相似所以只展示了个别流程 7. 学号排序
7.1 具体设计过程及功能算法描述
首先对学号前4位数年份进行排序按照外层循环从i0开始利用2.2的切割字符串的前n个字符函数getNchar(this-sStuArray[i]-sNum, 4)得到第i个学号的前4位数并设置当前最小值min i。
再内层循环ji1开始利用getNchar(this-sStuArray[j]-sNum, 4)得到第i1个学号的前4位数将两者对比若第j个比第i个小则令最小值变更为j即min j
然后判断如果min ! i即最小值改变了则更换第i和第j个的位置即第i个和第min个位置。然后进行整个学号this-sStuArray[i]-sNum的排序排序原理与上述过程相同。 7.2 流程图 七、设计结果
1. 菜单页面 说明根据提示输入0-6分别可以进入退出程序增加学生信息显示学生信息等页面调试无误。 2. 增加学生页面 说明首先提示输入想要添加的人数输入1就是添加单个学生输入大于1的数字则为批量添加学生若输入2004—2023区间以外的学号会提示错误输入已经存在的学号也会提示错误输入男女以外的性别会提示错误输入14—30以外的年龄会提示错误住址和专业可以选择1录入选择2不录入。最后输出添加成功。 3. 显示学生页面 说明按照提示输入2即可显示所有学生信息并且具有缺失值的学生信息如最后一行也可以显示在第二步刚刚添加上的202211701303的学生也可以立即显示。调试无误。 4. 删除学生页面 说明根据提示输入3进入删除学生页面若输入的想要删除的学号不存在则提示错误若存在则提示删除成功。再回到输入2进入显示学生页面刚刚删除的202211701303学生已经不存在了删除成功。调试无误。 5. 修改学生页面 说明根据提示输入4进入修改学生页面若输入的想要修改的学号不存在则提示错误若存在则根据提示输入想要修改的信息。输入1进入修改学号页面若修改的新学号已存在提示错误若不存在则修改成功。进入2显示学生页面查看202211701304号学生的学号已经修改为新学号202211701919了说明修改成功。调试无误。 6. 查找及模糊查找学生页面 说明根据提示输入5进入查找学生页面输入1-8分别是按学号查找按姓名查找等。输入2按姓名查找若查找的姓名不存在则提示错误若存在则展示符合该条件的学生信息和人数若输入7多条件查找则可以输入1-6的数字组合来组合条件若查找不到提示错误若查找到了则展示符合该条件的学生信息和人数若输入8模糊查找则可输入想要查找的学生的名字中的一个字若查找不到提示错误若查找到了则展示符合该条件的学生信息和人数 7. 学号排序页面 说明根据提示输入6进入学号排序页面图1为原本的顺序图2为输入6后进行排序后的结果按照学号从小到大排序成功。调试无误。 八、源码
1. 学生管理系统.cpp
#include iostream;
using namespace std;
#include studentManager.h
#include student.h
#include info.hint main() {studentManager st;int choice 0; // 用户的选择while (true) {st.showMenu(); // 展示菜单界面cout 请输入你的选择 endl;cin choice;switch (choice) {case 0: // 退出系统st.backsystem();break;case 1: // 增加学生st.addStu();break;case 2: // 显示学生st.showStu();break;case 3: // 删除学生st.deletStu();break;case 4: // 修改学生st.editStu();break;case 5: // 查找学生st.findStu();break;case 6: // 排序学生st.sortStu();break;default: // 输入其他数字-清空屏幕system(cls);break;}}system(pause);return 0;
} 2. info.cpp
#include info.hInfo::Info(string num, string name, string sex, int age, string adress, string major) {this-sNum num;this-sName name;this-sSex sex;this-sAge age;this-sAdress adress;this-sMajor major;
}void Info::showInfo() {cout this-sNum this-sName this-sSex this-sAge this-sAdress this-sMajor endl;
} 3. studentManager.cpp
#include studentManager.h;// 构造函数
studentManager::studentManager() { // 初始化fstream File;File.open(student.txt, ios::in);// 1 文件不存在的初始化if (!File.is_open()) {cout 文件不存在 endl; this-sCount 0; // 初始化学生人数和数组this-sStuArray NULL;this-isFileEmpty true; // 文件为空为真File.close();return;}// 2 文件存在但为空char ch;File ch;if (File.eof()) {cout 文件为空 endl;this-sCount 0; this-sStuArray NULL;this-isFileEmpty true; File.close();return;}// 3 文件存在 并记录数据int count this-getCount(); // 获取学生人数this-sCount count; // 更新学生人数this-sStuArray new Student * [this-sCount];this-initStu(); // 保存文件中数据到数组中
}// 展示菜单
void studentManager::showMenu() {cout ******************************************** endl;cout ********** 欢迎使用学生管理系统 ********* endl;cout ************* 0.退出管理程序 ************* endl;cout ************* 1.增加学生信息 ************* endl;cout ************* 2.显示学生信息 ************* endl;cout ************* 3.删除离校学生 ************* endl;cout ************* 4.修改学生信息 ************* endl;cout ************* 5.查找学生信息 ************* endl;cout ************* 6.按照学号排序 ************* endl;cout ******************************************** endl;cout endl;
}// 退出系统
void studentManager::backsystem() {cout 您已退出系统欢迎下次使用 endl;system(pause);exit(0); // 退出程序
}// 添加学生
void studentManager::addStu() {cout 请输入您想添加的学生人数 endl;int addCount 0;cin addCount;if (addCount 0) {int newCount this-sCount addCount; // 最新人数 原本人数 新增人数Student** newSpace new Student * [newCount]; // 新数组空间if (this-sStuArray ! NULL) { // 添加原来的职工for (int i 0; i this-sCount; i) {newSpace[i] this-sStuArray[i];}}for (int i 0; i addCount; i) {string Num; // 学号string Name; // 姓名string Sex; // 性别int Age; // 年龄string Adress; // 住址string Major; // 专业cout 请输入要添加的第 i 1 个学生的学号 endl;cin Num;int res this-isStuExit(Num); // 判断该学号是否已存在if (res -1) { // 学号不存在 可以添加string splitNum; // 要切割出来的学号的前n个数字splitNum getNchar(Num, 4); // 保存学号的前4个数字年份if (Num.length() 12 splitNum 2004 splitNum 2023) {cout 请输入要添加的第 i 1 个学生的姓名 endl;cin Name;cout 请输入要添加的第 i 1 个学生的性别 endl;cin Sex;if (Sex 男 || Sex 女) {cout 请输入要添加的第 i 1 个学生的年龄 endl;cin Age;if (Age 14 Age 30) {cout 您是否要录入该学生的住址 endl;cout 1 是 endl;cout 2 否 endl;int choose;cin choose;if (choose 1) {cout 请输入要添加的第 i 1 个学生的住址 endl;cin Adress;cout 您是否要录入该学生的专业 endl;cout 1 是 endl;cout 2 否 endl;int choose;cin choose;if (choose 1) {cout 请输入要添加的第 i 1 个学生的专业 endl;cin Major;} else {Major ;}} else {Adress ;cout 您是否要录入该学生的专业 endl;cout 1 是 endl;cout 2 否 endl;int choose;cin choose;if (choose 1) {cout 请输入要添加的第 i 1 个学生的专业 endl;cin Major;}else {Major ;}}/*fstream File;File.open(student.txt, ios::out | ios::app);File Num Name Sex Age Adress Major endl;File.close();*/Student* stu NULL;stu new Info(Num, Name, Sex, Age, Adress, Major);newSpace[this-sCount i] stu;this-sCount newCount; // 更新人数为最新人数this-isFileEmpty false; // 文件为空的标志为假cout 添加成功 endl;delete[] this-sStuArray;this-sStuArray newSpace;this-saveStu();}else {cout 您输入的年龄有误 请重新输入 endl;break;}}else {cout 性别只能输入男或女 请重新输入 endl;break;}}else {cout 您输入的学号有误 请重新输入 endl;break;}}else {cout 该学号已存在 请重新输入 endl;}}}else {cout 您输入的数字有误请重新输入 endl;system(pause);system(cls);}system(pause);system(cls);
}// 返回字符串的前n个字符
string studentManager::getNchar(string str, int n) {string nChars;if (n 0) {n 0;cout 输入有误, 请输入大于0的n endl;}if (n str.size()) {n str.size();}for (size_t i 0; i n; i) {nChars.push_back(str[i]);}return nChars;
}// 保存学生
void studentManager::saveStu() {fstream File;File.open(student.txt, ios::out);for (int i 0; i this-sCount; i) {File this-sStuArray[i]-sNum this-sStuArray[i]-sName this-sStuArray[i]-sSex this-sStuArray[i]-sAge this-sStuArray[i]-sAdress this-sStuArray[i]-sMajor endl;}File.close();
}// 获取学生人数
int studentManager::getCount() {fstream File;File.open(student.txt, ios::in);string Num; // 学号string Name; // 姓名string Sex; // 性别int Age; // 年龄string Adress; // 住址string Major; // 专业int Count 0; // 学生人数while (File Num File Name File File Sex File Age File Adress File Major) {Count; // 读到一条就加一条}File.close();return Count;
}// 初始化学生数组
void studentManager::initStu() {fstream File;File.open(student.txt, ios::in);string Num; // 学号string Name; // 姓名string Sex; // 性别int Age; // 年龄string Adress; // 住址string Major; // 专业int index 0;while (File Num File Name File File Sex File Age File Adress File Major) {Student* stu NULL;stu new Info(Num, Name, Sex, Age, Adress, Major);this-sStuArray[index] stu;index;}
}// 展示学生信息
void studentManager::showStu() {if (this-isFileEmpty) {cout 文件不存在或为空 endl;}else {for (int i 0; i this-sCount; i) {this-sStuArray[i]-showInfo();}}system(pause);system(cls);
}// 判断学号是否存在 存在则返回学生在数组中位置 不存在则返回-1
int studentManager::isStuExit(string num) {int index -1; // 默认为-1for (int i 0; i this-sCount; i) {if (this-sStuArray[i]-sNum num) {index i;break;}}return index;
}// 删除学生
void studentManager::deletStu() {if (this-isFileEmpty) { // 文件不存在或无数据cout 文件不存在或为空 endl;}else { // 文件有数据cout 请输入您想要删除的学生学号 endl;string num;cin num;int index this-isStuExit(num); // 判断该学号学生是否存在if (index ! -1) { // 学生存在 删除index位置的学生for (int i index; i this-sCount - 1; i) {// index后一个覆盖前一个依次类推this-sStuArray[i] this-sStuArray[i 1];}this-sCount--; // 更新学生人数this-saveStu(); // 更新学生信息到文件cout 成功删除学号为 num 的学生 endl;}else { // 学生不存在cout 删除失败 该学号学生不存在 endl;}}system(pause);system(cls);
}// 修改学生
void studentManager::editStu() {if (this-isFileEmpty) { // 文件不存在或无数据cout 文件不存在或为空 endl;}else { // 有数据cout 请输入您要修改的学生学号 endl;string num;cin num;int index this-isStuExit(num); // 判断学生是否存在if (index ! -1) { // 学生存在 进行修改string newNum; // 学号string newName; // 姓名string newSex; // 性别int newAge; // 年龄string newAdress; // 住址string newMajor; // 专业cout 查找成功 请输入您要修改的学生信息 endl;cout 1 修改学号 endl;cout 2 修改姓名 endl;cout 3 修改性别 endl;cout 4 修改年龄 endl;cout 5 修改住址 endl;cout 6 修改专业 endl;int choose;cin choose;switch(choose) {case 1: {cout 请输入您要修改的新学号 endl;cin newNum;int res this-isStuExit(newNum); // 判断要修改的新学号是否存在if (res -1) { // 学号不存在 可以修改this-sStuArray[index]-sNum newNum;cout 修改成功 endl;break;}else {cout 修改失败 该学号已存在 endl;break;}}case 2:{cout 请输入您要修改的新姓名 endl;cin newName;this-sStuArray[index]-sName newName;cout 修改成功 endl;break;}case 3:{cout 请输入您要修改的新性别 endl;cin newSex;this-sStuArray[index]-sSex newSex;cout 修改成功 endl;break;}case 4:{cout 请输入您要修改的新年龄 endl;cin newAge;this-sStuArray[index]-sAge newAge;cout 修改成功 endl;break;}case 5:{cout 请输入您要修改的新住址 endl;cin newAdress;this-sStuArray[index]-sAdress newAdress;cout 修改成功 endl;break;}case 6:{cout 请输入您要修改的新专业 endl;cin newMajor;this-sStuArray[index]-sMajor newMajor;cout 修改成功 endl;break;}default: // 输入其他数字-清空屏幕system(cls);break;}this-saveStu(); // 更新数组到文件中}else {cout 修改失败 该学号学生不存在 endl;}}system(pause);system(cls);
}// 查询学生
void studentManager::findStu() {if (this-isFileEmpty) {cout 文件不存在或为空 endl;}else {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;int choose;cin choose;if (choose 1) { // 按学号查找cout 请输入您要查找的学号 endl;string num;cin num;this-findNum(num);}else if (choose 2) { // 按姓名查找cout 请输入您要查找的姓名 endl;string name;cin name;this-findName(name);}else if (choose 3) { // 按性别查找cout 请输入您要查找的性别 endl;string sex;cin sex;this-findSex(sex);}else if (choose 4) { // 按年龄查找cout 请输入您要查找的年龄 endl;int age;cin age;this-findAge(age);}else if (choose 5) { // 按住址查找cout 请输入您要查找的住址 endl;string adress;cin adress;this-findAdress(adress);}else if (choose 6) { // 按专业查找cout 请输入您要查找的专业 endl;string major;cin major;this-findMajor(major);}else if (choose 7) { // 多条件查找cout 请输入2-7的数字组合 如按姓名性别查找 输入23 endl;int choose;cin choose;if (choose 23) { // 按姓名性别查找cout 请输入您要查找的姓名 endl;string name;cin name;cout 请输入您要查找的性别 endl;string sex;cin sex;int count 0;for (int i 0; i this-sCount; i) {if (this-sStuArray[i]-sName name this-sStuArray[i]-sSex sex) {this-sStuArray[i]-showInfo();count;}}cout 符合条件的人数为 count endl;}if (choose 345) { // 性别年龄住址cout 请输入您要查找的性别 endl;string sex;cin sex;cout 请输入您要查找的年龄 endl;int age;cin age;cout 请输入您要查找的住址 endl;string adress;cin adress;int count 0;for (int i 0; i this-sCount; i) {if (this-sStuArray[i]-sSex sex this-sStuArray[i]-sAge age this-sStuArray[i]-sAdress adress) {this-sStuArray[i]-showInfo();count;}}cout 符合条件的人数为 count endl;}}else if (choose 8) { // 模糊查找cout 请输入您要查询的姓名中含的某字 如陈 endl;char name;cin name;int count 0; // 符合条件的人数for (int i 0; i this-sCount; i) {for (int j 0; j this-sStuArray[i]-sName.length(); j) {if (this-sStuArray[i]-sName[j] name) {this-sStuArray[i]-showInfo();count;}}}cout 符合条件的人数为 count endl;}else {cout 查询失败 您输入的数字有误 endl;}} system(pause);system(cls);
}// 1 按学号查找
void studentManager::findNum(string num) {int res this-isStuExit(num); // 判断该学号学生是否存在if (res ! -1) { // 学生存在this-sStuArray[res]-showInfo();}else {cout 查找失败 该学号学生不存在 endl;}
}// 2 按姓名查找
void studentManager::findName(string name) {int flag false; // 是否查找成功的标志int count 0; // 符合条件的学生人数for (int i 0; i this-sCount; i) {if (this-sStuArray[i]-sName name) {this-sStuArray[i]-showInfo();flag true;count;}}if (flag true) {cout 该姓名的学生人数为 count endl;}else if (flag false) {cout 查找失败 该姓名学生不存在 endl;}
}// 3 按性别查找
void studentManager::findSex(string sex) {int count 0; // 符合条件的学生人数if (sex 男 || sex 女) {for (int i 0; i this-sCount; i) {if (this-sStuArray[i]-sSex sex) {this-sStuArray[i]-showInfo();count;}}cout 该性别的学生人数为 count endl;}else {cout 查找失败 性别只能输入男或女 endl;}
}// 4 按年龄查找
void studentManager::findAge(int age) {int flag false; // 是否查找成功的标志int count 0; // 符合条件的学生人数for (int i 0; i this-sCount; i) {if (this-sStuArray[i]-sAge age) {this-sStuArray[i]-showInfo();flag true;count;}}if (flag true) {cout 该年龄的学生人数为 count endl;}else if (flag false) {cout 查找失败 该年龄学生不存在 endl;}
}// 5 按住址查找
void studentManager::findAdress(string adress) {int flag false; // 是否查找成功的标志int count 0; // 符合条件的学生人数for (int i 0; i this-sCount; i) {if (this-sStuArray[i]-sAdress adress) {this-sStuArray[i]-showInfo();flag true;count;}}if (flag true) {cout 该住址的学生人数为 count endl;}else if (flag false) {cout 查找失败 该住址学生不存在 endl;}
}// 6 按专业查找
void studentManager::findMajor(string major) {int flag false; // 是否查找成功的标志int count 0; // 符合条件的学生人数for (int i 0; i this-sCount; i) {if (this-sStuArray[i]-sMajor major) {this-sStuArray[i]-showInfo();flag true;count;}}if (flag true) {cout 该专业的学生人数为 count endl;}else if (flag false) {cout 查找失败 该专业学生不存在 endl;}
}// 按学号大小排序
void studentManager::sortStu() {for (int i 0; i this-sCount; i) {// 按前4位数年份排序string splitNum4i; // 要切割出来的学号的前4个数字splitNum4i getNchar(this-sStuArray[i]-sNum, 4); // 保存学号的前4个数字年份int min i; // 目前最小值的下标for (int j i 1; j this-sCount; j) {string splitNum4j; // 要切割出来的学号的前n个数字splitNum4j getNchar(this-sStuArray[j]-sNum, 4); // 保存学号的前4个数字年份if (splitNum4i splitNum4j) {min j;}}if (min ! i) {Student* temp this-sStuArray[i];this-sStuArray[i] this-sStuArray[min];this-sStuArray[min] temp;}// 按学号排序int min2 i; // 目前最小值的下标for (int j i 1; j this-sCount; j) {if (this-sStuArray[i]-sNum this-sStuArray[j]-sNum) {min2 j;}}if (min2 ! i) {Student* temp this-sStuArray[i];this-sStuArray[i] this-sStuArray[min2];this-sStuArray[min2] temp;}}cout 排序成功 最新的数据为 endl;this-saveStu();this-showStu();system(pause);system(cls);
}// 析构函数
studentManager::~studentManager() {// 手动释放堆区数据if (this-sStuArray ! NULL) {delete[] this-sStuArray;this-sStuArray NULL;}
} 4. student.h
#pragma once
#include iostream
using namespace std;
#include stringclass Student {
public:virtual void showInfo() 0; // 显示学生信息string sNum; // 学号string sName; // 姓名string sSex; // 性别int sAge; // 年龄string sAdress; // 住址string sMajor; // 专业
};5. studentManager.h
#pragma once
#include iostream
using namespace std;#include student.h
#include info.h#include string
#include fstream
#include ctype.h
#include vectorclass studentManager {
public:studentManager(); // 构造函数void showMenu(); // 展示菜单void backsystem(); // 退出系统void addStu(); // 添加学生int sCount; // 原本学生人数Student** sStuArray; // 记录学生的数组string getNchar(string str, int n); // 返回输入的前n个字符void saveStu(); // 保存学生bool isFileEmpty; // 标志文件是否为空int getCount(); // 获取学生人数void initStu(); // 初始化学生数组void showStu(); // 展示学生信息int isStuExit(string num); // 根据学号判断该学生学生是否存在void deletStu(); // 删除学生void editStu(); // 修改学生void findStu(); // 查找学生void findNum(string num); // 1 按学号查找void findName(string name); // 2 按姓名查找void findSex(string sex); // 3 按性别查找void findAge(int age); // 4 按年龄查找void findAdress(string adress); // 5 按住址查找void findMajor(string major); // 6 按专业查找void sortStu(); // 排序~studentManager(); // 析构函数
}; 6. info.h
#pragma once
#include iostream
using namespace std;
#include student.hclass Info: public Student {
public:// 构造函数Info(string num, string name, string sex, int age, string adress, string major);// 展示学生信息virtual void showInfo();
};