题目:实现一个简单的信息管理系统,如成绩管理系统,学籍信息管理系统,超市管理系统,银行管理系统等,题目可以自定义。
要求:
1.功能完善,实现基本的业务功能(信息的增删查改,以及数据分析等),需要连接文本文档,不需要连接数据库。
2.使用面向对象的程序设计思想实现,类中必须包含必要的数据成员,构造函数以及成员函数。
3.使用到继承,派生,多态,文本文件操作。
一、需求分析
用一个登录界面来区分管理员和学生登录,让学生可以查询自己的个人信息和修改自己的密码,而便于管理员管理学生的信息,并且可以看到学院的优秀率和平均绩点,将学生和管理员的权限分开。数据的规范有要求的输出到文本中。
二、功能设计
登录界面,学生登录界面,管理员登录界面。
登录界面:登录功能,忘记密码功能。判断登录是否为学生。
学生登录界面:学生自己的个人信息和修改密码功能。
管理员登录界面:显示学生信息,添加学生信息,修改学生信息,查询学生信息,删除学生信息,学生信息汇总。
部分功能设计:验证码登录确认,验证码为长度5的四个字母一个数字(显示问题将数字不为1和0)。判断身份证号为18位,前17位纯数字,最后一位为x(X)或者数字。判断学号要求纯数字13位。判断绩点在0到5之间。每次添加删除数据后,数据以相同学院及绩点高低排序后显示。学院平均绩点,学院人数,优秀率。数据文件的读取,分析,写出数据。
三、对象(类)设计
四、编码与测试
1.初始的管理员用户名为admin 密码为123456(代码中的主函数创建的管理员类对象)
2.原始数据.txt是指最初数据的文本文档
3.Test.txt是程序运行时读取数据的文本文档(与原始数据一致)
4.LastDataValue .txt是退出程序后保存学生数据的文本文档
5.analyzeData.txt是数据分析的结果的文本文档
6.代码.txt是程序代码的文本文档
7.可以将读取目标文件(Test.txt)和写出最后数据的文档(LastDataValue.txt)指向同一文件,就可以满足每次的增删查改可以保存到下一次运行
8.所用的文本文件编码形式都为:ANSI(以免出现乱码情况)此代码我是用codeblocks20.03版本编写,若要用其他编译器需要自己修改代码
ps:有什么意见或者问题可以留言或者私聊我,我会想办法帮你解决。
以下是运行文件(需要自己创建相应的文本文档):
代码演示:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <time.h>
#include <fstream>
using namespace std;
//用户类
class User{
public:
User(){
}
User(string name,string num ,string passWord, string idCard){
this->name = name;
this->num = num;
this->passWord = passWord;
this->idCard = idCard;
}
string getName(){
return name;
}
void setName(string name){
this->name = name;
}
string getNum(){
return num;
}
void setNum(string num){
this->num = num;
}
string getPassWord(){
return passWord;
}
void setPassWord(string passWord){
this->passWord = passWord;
}
string getIdCard(){
return idCard;
}
void setIdCard(string idCard){
this->idCard = idCard;
}
virtual void display()=0;
protected:
string name;
string num;
string passWord;
string idCard;
};
//学生类
class Student:public User{
public:
Student(){
}
Student(string name,string num,string passWord,string idCard,string college,string major,double point):User(name,num,passWord,idCard){
this->college = college;
this->major = major;
this->point = point;
}
string getCollege(){
return college;
}
void setCollege(string college){
this->college = college;
}
string getMajor(){
return major;
}
void setMajor(string major){
this->major = major;
}
double getPoint(){
return point;
}
void setPoint(double point){
this->point = point;
}
void display();
private:
string college;
string major;//专业
double point;
};
void Student::display(){
cout<<"|"<<name<<"\t"<<num<<"\t"<<college<<"\t"<<major<<" "<<idCard<<"\t";
cout.setf(ios::fixed);
cout.precision(2);
cout<<point<<"|"<<endl;
}
//管理员类
class Admin:public User{
public:
Admin(){
}
Admin(string name,string num,string passWord,string idCard,string phoneNum):User(name,num,passWord,idCard){
this->phoneNum = phoneNum;
}
string getPhoneNum(){
return phoneNum;
}
void setPhoneNum(string phoneNum){
this->phoneNum = phoneNum;
}
void display(){}
void display(vector<Student> students){
for(unsigned i = 0; i < students.size(); i++){
students[i].display();
}
}
private:
string phoneNum;
};
vector<Student> swapStudent(vector<Student> student,int a,int b){//交换vector<Student>中对象的位置
Student temp = student[a];
student[a] = student[b];
student[b] = temp;
return student;
}
vector<Student> sortVector(vector<Student> sortStudent){//选择排序
int size = (int)sortStudent.size();
if(size < 1){
return sortStudent;
}
for(int i = 0; i < size - 1; i++){
int minIndex = i;
for(int j = i + 1; j < size; j++){
minIndex = sortStudent[minIndex].getPoint() < sortStudent[j].getPoint() ? j : minIndex;
}
sortStudent = swapStudent(sortStudent,i,minIndex);
}
return sortStudent;
}
vector<Student> sortStudents(vector<Student> student){
if(student.empty()){
return student;
}
//学院排序
int col = 1;//指向当前学院的最后一个对象的后一个位置
int index = 1;//遍历标识
//col - 1始终指向当前学院最后一个对象的位置
//col 始终指向当前学院最后一个对象的后一个位置 作为交换边界
//index 来寻找相等学院 若相等 交换index和col 并且都后走一步 否则index自身++
while(col != (int)student.size()){
if(student[col - 1].getCollege() == student[index].getCollege()){
student = swapStudent(student,col,index);
col++;
index++;
}else{
index++;
}
if(index >= (int)student.size() && col != (int)student.size()){//防止越界
col++;
index = col;
}
}
//在学院排序好之后绩点排序
vector<Student> sortStudent;
sortStudent.push_back(student[0]);
int lastCollege = 0;//最后相同学院的下标值
int indexs = 1;
while(indexs != (int)student.size()){
if(student[indexs - 1].getCollege() != student[indexs].getCollege()){//在学院不相等的情况下 清空sortStudet
sortStudent.clear();
lastCollege = indexs;
}
sortStudent.push_back(student[indexs]);
sortStudent = sortVector(sortStudent);
for(int i = 0, j = lastCollege; i < (int)sortStudent.size(); i++, j++){//排序返回到Student容器
student[j] = sortStudent[i];
}
indexs++;
}
return student;
}
void printNowStudent(vector<Student> students, int now){//学生界面-=-当前学生信息
cout<<"|***************************学生信息如下************************************|"<<endl;
cout<<"|姓名\t学号\t\t所属学院\t专业班级 身份证\t\t绩点|"<<endl;
students[now].display();
}
void judgeReturn(){//退出设置
string c;
cout<<"输入0返回:";
cin>>c;
while(c != "0"){
cout<<"输入0返回:";
cin>>c;
}
cout<<"**********************************"<<endl;
}
bool verification(){//随机验证码
//生成1数字4字母的随机验证码
char ch1[52] = {};//字母字符数组
char ch2[8] = {};//数字字符数组//除去1和0
for(int i = 2; i < 10; i++){
ch2[i - 2] = (char)(48 + i);
}
for(int i = 0; i < 26; i++){
ch1[i] = (char)(65 + i);
}
for(int i = 26; i < 52; i++){
ch1[i] = (char)(97 + i - 26);
}
//生产纯字母的验证码
srand((unsigned int)time(NULL));
while(true){
string str = "";
for(int i = 0; i < 5; i++){
str += ch1[rand()%52];
}
string temp;
int j = rand()%5;//随机替换位置
char num = ch2[rand()%8];//随机替换的数字
string str1 = "";
str1 += num;
str.replace(j, str1.length(),str1);
cout<<"验证码(区分大小写):"<<str<<endl;
cout<<"请输入验证码:";
cin>>temp;
if(temp == str){
return true;
}else{
cout<<"验证码错误!"<<endl;
}
}
}
//判断学生学号是否存在
bool repeat(vector<Student> students, string num){
for(unsigned i = 0; i < students.size(); i++){
if(students[i].getNum() == num){
return false;
}
}
return true;
}
int repeatNum(vector<Student> students, string num){//查找当前学生位置
for(unsigned i = 0; i < students.size(); i++){
if(students[i].getNum() == num){
return i;
}
}
return -1;
}
int repeatVtNum(vector <Student> students, string num){//查找当前学生容器中的位置
int vt = 0;
for(unsigned i = 0; i < students.size(); i++){
if(num == students[i].getNum()){
return vt;
}
vt++;
}
return -1;
}
vector<Student> studentRevamp(vector<Student> students,int now){//学生修改自己的密码
while(true){
string newPassWord1;
string newPassWord2;
cout<<"请输入新密码:";
cin>>newPassWord1;
cout<<"请再次输入密码:";
cin>>newPassWord2;
if(newPassWord1 == newPassWord2){
students[now].setPassWord(newPassWord1);
cout<<"修改成功!"<<endl;
break;
}else{
cout<<"两次输入密码不一致!请重试!"<<endl;
}
}
return students;
}
vector<Student> studentMenu(vector<Student> students,int nowStudent){//学生菜单界面
cout<<"|*******************************您的信息如下:************************************|"<<endl;
cout<<"|姓名\t学号\t\t所属学院\t专业班级 身份证\t\t绩点|"<<endl;
students[nowStudent].display();
string x;
while(true){
cout<<"是否修改密码(Y/N):";
cin>>x;
if(x == "Y"){
students = studentRevamp(students,nowStudent);
break;
}else if(x=="N"){
break;
}else{
cout<<"输入错误!"<<endl;
}
}
return students;
}
void print(vector<Student> students){//管理员菜单-=-显示学生信息
if(students.empty()){
cout<<"暂无学生信息!"<<endl;
}else{
cout<<"|---------------------------显示学生信息------------------------------------|"<<endl;
cout<<"|***************************学生信息如下************************************|"<<endl;
cout<<"|姓名\t学号\t\t所属学院\t专业班级 身份证\t\t绩点|"<<endl;
//cout<<students.size()<<endl;
for(unsigned i = 0; i < students.size(); i++){
students[i].display();
}
cout<<"|---------------------------------------------------------------------------|"<<endl;
}
judgeReturn();
}
//判断学号是否符合要求13位
bool limitNum(string num){
if((int)num.length() != 13){
return false;
}
char arr[10] = {};
for(int i = 0; i < 10; i++){
arr[i] = (char)(48 + i);
}
int k = 0;
for(int i = 0;i < 13; i++){
for(int j = 0; j < 10; j++){
if(num.at(i) == arr[j])
k++;
}
}
if(k != 13){
return false;
}else{
return true;
}
}
//确定是18位密码 首位不为0 中间只能是数字 末尾可以是数字也可以是xX
bool judgeId(string idCard){
char arr[10] = {};
for(int i = 0; i < 10; i++){
arr[i] = (char)(48 + i);
}
int k = 0;
for(int i = 0;i < (int)idCard.length(); i++){
for(int j = 0; j < 10; j++){
if(idCard.at(i) == arr[j])
k++;
}
}
if(idCard.at(17) == 'x' || idCard.at(17) == 'X'){
k++;
}
if(k == 18){
return true;
}else{
return false;
}
}
string limitId(){//身份证确认
while(true){
string str;
cout<<"请输入身份证号:";
cin>>str;
if(str.length() == 18 && str.at(0) != '0' && judgeId(str)){
return str;
}else{
cout<<"身份证号不符合要求!"<<endl;
}
}
}
vector<Student> add(vector<Student> students){//管理员菜单-=-添加学生信息
cout<<"|**********添加学生信息**********|"<<endl;
string num;
cout<<"请输入添加学生学号:";
cin>>num;
while(!limitNum(num)){
cout<<"学号格式错误!请重新输入:";
cin>>num;
}
if(repeat(students,num)){
string name;
cout<<"请输入姓名:";
cin>>name;
string college;
cout<<"请输入所属院系:";
cin>>college;
string major;
cout<<"请输入所属专业班级:";
cin>>major;
string idCard;
idCard = limitId();
//默认密码身份证后八位
string passWord = "";
for(int i = 10; i < (int)idCard.length(); i++){//无符号类型有可能溢出
passWord += idCard.at(i);
}
cout<<"默认密码为:"<<passWord<<endl;
double point;
cout<<"请输入绩点:";
cin>>point;
while(point < 0 && point > 5){
cout<<"输入绩点错误!请重新输入:";
cin>>point;
}
Student s(name,num,passWord,idCard,college,major,point);
students.insert(students.end(),s);
cout<<"添加成功!"<<endl;
}else{
cout<<"学号此学号已存在!"<<endl;
}
judgeReturn();
return students;
}
vector<Student> revampStudent(vector<Student> students){//管理员菜单-=-修改学生信息
cout<<"|**********修改学生信息**********|"<<endl;
if(students.empty()){
cout<<"暂无学生信息!"<<endl;
judgeReturn();
return students;
}
cout<<"请输入修改学生学号:";
string num;
cin>>num;
int now = repeatNum(students,num);
if(now == -1){
cout<<"此学号不存在!"<<endl;
}else{
printNowStudent(students,now);
cout<<"选择修改内容(标签):";
string x;
cin>>x;
while(x != "姓名" && x != "学号" && x != "所属学院" && x != "专业班级" && x != "身份证" && x != "绩点" && x != "重置密码"){
cout<<"输入错误!请重新输入:";
cin>>x;
}
if(x == "姓名"){
string name;
cout<<"请输入修改后姓名:";
cin>>name;
students[now].setName(name);
}else if(x == "学号"){
string num;
cout<<"请输入修改后学号:";
cin>>num;
while(!repeat(students,num) || !limitNum(num)){
cout<<"学号重复或者学号格式错误!请重新输入:";
cin>>num;
}
students[now].setNum(num);
}else if(x == "所属学院"){//修改学院要修改专业班级
string college;
cout<<"请输入修改后所属学院:";
cin>>college;
students[now].setCollege(college);
string major;
cout<<"请输入修改后所属专业班级:";
cin>>major;
students[now].setMajor(major);
}else if(x == "专业班级"){
string major;
cout<<"请输入修改后专业班级:";
cin>>major;
students[now].setMajor(major);
}else if(x == "身份证"){
string idCard;
idCard = limitId();
students[now].setIdCard(idCard);
}else if(x == "绩点"){
double point;
cout<<"请输入修改后绩点:";
cin>>point;
while(point < 0 && point > 5){
cout<<"输入绩点错误!请重新输入:";
cin>>point;
}
students[now].setPoint(point);
}else{
string passWord = "";
for(int i = 10; i < 18; i++){
passWord += students[now].getIdCard().at(i);
}
cout<<"重置密码为:"<<passWord<<endl;
students[now].setPassWord(passWord);
}
cout<<"修改成功!"<<endl;
}
judgeReturn();
return students;
}
void queryStudent(vector<Student> students){//管理员菜单-=-查询学生信息
cout<<"|**********查询学生信息**********|"<<endl;
if(students.empty()){
cout<<"暂无学生信息!"<<endl;
judgeReturn();
return;
}
string num;
cout<<"请输入查询学生学号:";
cin>>num;
int now = repeatNum(students,num);
if(now != -1){
printNowStudent(students,now);
}else{
cout<<"此学号不存在!"<<endl;
}
judgeReturn();
}
vector<Student> deleteStudent(vector<Student> students){//管理员菜单-=-删除学生信息
cout<<"|**********删除学生信息**********|"<<endl;
if(students.empty()){
cout<<"暂无学生信息!"<<endl;
judgeReturn();
return students;
}
string num;
cout<<"请输入删除学生的学号:";
cin>>num;
int now = repeatNum(students, num);
int vt = repeatVtNum(students, num);//在容器中的位置
if(vt != -1){
printNowStudent(students, now);
string x;
cout<<"确认是否删除(Y/N):";
cin>>x;
while(x != "Y" && x != "N"){
cout<<"输入错误!请重新输入:";
cin>>x;
}
if(x == "Y"){
students.erase(students.begin() + vt);
cout<<"删除成功!"<<endl;
}else{
cout<<"取消删除!"<<endl;
}
}else{
cout<<"学号不存在!"<<endl;
}
judgeReturn();
return students;
}
void foutAnalyseData(vector<Student> student){//数据分析的写入
if(student.empty()){
return;
}
vector<string> sumCollege;//学院
vector<int> collegeNum;//学院人数
vector<double> avgPoint;//绩点累加
vector<int> qualifiedNum;//优秀人数
int numIndex = 0;//指向第一个出现的学院 学院唯一
//添加第一个数据对象
sumCollege.push_back(student[numIndex].getCollege());
collegeNum.push_back(1);
avgPoint.push_back(student[numIndex].getPoint());
qualifiedNum.push_back(0);
if(student[numIndex].getPoint() >= 3.0){
qualifiedNum[numIndex]++;
}
int index = 1;
while(index < (int)student.size()){//开始遍历
if(sumCollege[numIndex] == student[index].getCollege()){
collegeNum[numIndex]++;//相同学院 人数+1
avgPoint[numIndex] += student[index].getPoint();//绩点累加
}else{
sumCollege.push_back(student[index].getCollege());//不同学院 添加学院
numIndex++;//学院数+1
collegeNum.push_back(1);//将该学院人数设置为1
avgPoint.push_back(student[index].getPoint());//添加绩点
qualifiedNum.push_back(0);//将优秀人数设置为0
}
if(student[index].getPoint() >= 3.0){//判断是否优秀
qualifiedNum[numIndex]++;
}
index++;
}
ofstream outf("analyzeData.txt");
for(int i = 0; i < (int)sumCollege.size(); i++){
outf<<sumCollege[i]<<" "<<collegeNum[i]<<"人 "<<"平均绩点:";
outf.setf(ios::fixed);
outf.precision(2);
outf<<avgPoint[i]/collegeNum[i]<<" 优秀率:"<<((double)qualifiedNum[i]/collegeNum[i])*100<<"%"<<endl;
}
outf.close();
}
//各学院绩点平均值
void analyse(vector<Student> student){//管理员信息-=-学生数据分析
cout<<"|**********学生数据分析**********|"<<endl;
if(student.empty()){
cout<<"暂无学生信息!"<<endl;
judgeReturn();
return;
}
vector<string> sumCollege;//学院
vector<int> collegeNum;//学院人数
vector<double> avgPoint;//绩点累加
vector<int> qualifiedNum;//优秀人数
int numIndex = 0;//指向第一个出现的学院 学院唯一
//添加第一个数据对象
sumCollege.push_back(student[numIndex].getCollege());
collegeNum.push_back(1);
avgPoint.push_back(student[numIndex].getPoint());
qualifiedNum.push_back(0);
if(student[numIndex].getPoint() >= 3.0){
qualifiedNum[numIndex]++;
}
int index = 1;
while(index < (int)student.size()){//开始遍历
if(sumCollege[numIndex] == student[index].getCollege()){
collegeNum[numIndex]++;//相同学院 人数+1
avgPoint[numIndex] += student[index].getPoint();//绩点累加
}else{
sumCollege.push_back(student[index].getCollege());//不同学院 添加学院
numIndex++;//学院数+1
collegeNum.push_back(1);//将该学院人数设置为1
avgPoint.push_back(student[index].getPoint());//添加绩点
qualifiedNum.push_back(0);//将优秀人数设置为0
}
if(student[index].getPoint() >= 3.0){//判断是否优秀
qualifiedNum[numIndex]++;
}
index++;
}
for(int i = 0; i < (int)sumCollege.size(); i++){
cout<<sumCollege[i]<<" "<<collegeNum[i]<<"人 "<<"平均绩点:";
cout.setf(ios::fixed);
cout.precision(2);
cout<<avgPoint[i]/collegeNum[i]<<" 优秀率:"<<((double)qualifiedNum[i]/collegeNum[i])*100<<"%"<<endl;
}
ofstream outf("analyzeData.txt");
for(int i = 0; i < (int)sumCollege.size(); i++){
outf<<sumCollege[i]<<" "<<collegeNum[i]<<"人 "<<"平均绩点:";
outf.setf(ios::fixed);
outf.precision(2);
outf<<avgPoint[i]/collegeNum[i]<<" 优秀率:"<<((double)qualifiedNum[i]/collegeNum[i])*100<<"%"<<endl;
}
outf.close();
judgeReturn();
}
vector<Student> adminMenu(vector<Student> students){//管理员菜单
students = sortStudents(students);
cout<<"|***********管理员菜单***********|"<<endl;
cout<<"|*--------1.显示学生信息--------*|"<<endl;
cout<<"|*--------2.添加学生信息--------*|"<<endl;
cout<<"|*--------3.修改学生信息--------*|"<<endl;
cout<<"|*--------4.查询学生信息--------*|"<<endl;
cout<<"|*--------5.删除学生信息--------*|"<<endl;
cout<<"|*--------6.学生数据汇总--------*|"<<endl;
cout<<"|*------------7.退出------------*|"<<endl;
string x;
cout<<" 请选择操作:";
cin>>x;
while(x != "1" && x != "2" && x != "3" && x != "4" && x != "5" && x != "6" && x != "7"){
cout<<"输入错误!请重新输入:";
cin>>x;
}
if(x == "1"){
print(students);//显示学生信息
students = adminMenu(students);
}else if(x == "2"){
students = add(students);//添加学生信息
students = adminMenu(students);
}else if(x == "3"){
students = revampStudent(students);//修改学生信息
students = adminMenu(students);
}else if(x == "4"){
queryStudent(students);//查询学生信息
students = adminMenu(students);
}else if(x == "5"){
students = deleteStudent(students);//删除学生信息
students = adminMenu(students);
}else if(x == "6"){
analyse(students);//数据汇总
students = adminMenu(students);
}else{
foutAnalyseData(students);//将数据写入到目标文本文件
cout<<"退出成功!"<<endl;
}
return students;
}
vector<Student> adminPassWord(vector<Student> students,vector<Admin> admins,int nowAdmin){//管理员密码验证
string passWord;
cout<<"请输入密码:";
cin>>passWord;
verification();
if(admins[nowAdmin].getPassWord() == passWord){
cout<<"登录成功!"<<endl;
students = adminMenu(students);
}else{
cout<<"用户名或密码错误!登陆失败!"<<endl;
}
return students;
}
vector<Student> studentPassWord(vector<Student> students,string num){//学生密码验证
int nowStudent = repeatNum(students,num);
string passWord;
cout<<"请输入密码:";
cin>>passWord;
verification();
if(nowStudent != -1 && students[nowStudent].getPassWord() == passWord){
cout<<"登录成功!"<<endl;
students = studentMenu(students,nowStudent);
}else{
cout<<"用户名或密码错误!登录失败!"<<endl;
}
return students;
}
vector<Student> loginMenu(vector<Student> students,vector<Admin> admins){//用户登录界面
cout<<"|***********用户登录*************|"<<endl;
string str;
cout<<"请输入用户名:";
cin>>str;
//先判断是否为管理员
int loginChooes = -1;
for(unsigned i = 0; i < admins.size(); i++){
if(str == admins[i].getNum()){
loginChooes = i;
break;
}
}
if(loginChooes != -1){
students = adminPassWord(students,admins,loginChooes);
}else{
students = studentPassWord(students,str);
judgeReturn();
}
return students;
}
vector<Student> forgetPassWord(vector<Student> students){//忘记密码
cout<<"|***********忘记密码*************|"<<endl;
cout<<"请输入学号:";
string num;
cin>>num;
cout<<"请输入身份证号:";
string idCard;
cin>>idCard;
int nowNum = repeatNum(students,num);
if(nowNum != -1 && idCard == students[nowNum].getIdCard()){
students = studentRevamp(students,nowNum);
}else{
cout<<"学号或身份证号错误!"<<endl;
}
judgeReturn();
return students;
}
void outFile(vector<Student> students){//数据写出
ofstream fout("LastDateValue.txt");
//ofstream fout("Test.txt");
if(!fout){
cout<<"打开文件失败!"<<endl;
abort();
}
for(int i = 0; i < (int)students.size(); i++){
fout<<students[i].getName()<<" "<<students[i].getNum()<<" "<<students[i].getPassWord()<<" "<<students[i].getIdCard()<<" "<<students[i].getCollege()<<" "<<students[i].getMajor()<<" ";
fout.setf(ios::fixed);
fout.precision(2);
fout<<students[i].getPoint()<<endl;
}
fout.close();
}
vector<Student> menu(vector<Student> students,vector<Admin> admins){//菜单
string x;
cout<<"|================================|"<<endl;
cout<<"|=----欢迎到学生信息管理系统----=|"<<endl;
cout<<"|=-----------1.登录-------------=|"<<endl;
cout<<"|=---------2.忘记密码-----------=|"<<endl;
cout<<"|=-----------3.退出-------------=|"<<endl;
cout<<"|================================|"<<endl;
cout<<" 请选择操作:";
cin>>x;
while(x != "1" && x != "2" && x != "3"){
cout<<"操作错误!请选择操作:";
cin>>x;
}
if(x == "1"){
students = loginMenu(students,admins);
students = menu(students,admins);
}else if(x == "2"){
students = forgetPassWord(students);
students = menu(students,admins);
}else{
cout<<" 退出成功!"<<endl;
}
return students;
}
vector<Student> fileData(vector<Student> students){//写入数据
ifstream fin("Test.txt");
if(!fin){
cout<<"文件打开失败!"<<endl;
abort();
}
vector<string> FileData;
while(!fin.eof()){
string str;
fin>>str;
FileData.push_back(str);
}
if(!FileData.empty()){
int indexF = 0;
while(indexF + 6 < (int)FileData.size()){
string name = FileData[indexF++];
string num = FileData[indexF++];
string passWord = FileData[indexF++];
string idCard = FileData[indexF++];
string college = FileData[indexF++];
string major = FileData[indexF++];
double point = atof(FileData[indexF++].c_str());//将string类型转化成double类型
Student s(name,num,passWord,idCard,college,major,point);
students.push_back(s);
}
}
fin.close();
return students;
}
int main()
{
vector<Student> students;//学生
students = fileData(students);//打开目标文本文件读取数据
vector<Admin> admins;//管理员
Admin a("admin","admin","123456","420115200203170056","18827664695");//为了方便学号设置为amdin
admins.push_back(a);
students = sortStudents(students);//将数据按照学院顺序和绩点高低来排列
students = menu(students,admins);//进入菜单
outFile(students);//写出数据
foutAnalyseData(students);//将分析数据写入到目标文本文件
return 0;
}