/** * @copyright 2012 Chunhui Wang * * wangchunhui@wangchunhui.cn * * 学生学籍管理系统(12.06) */ #include <iostream> #include <fstream> #include <string> #include <iomanip> #include <conio.h> #include <string.h> #include <stdio.h> #include <windows.h> using namespace std; #define M 100000 #define BACKSPACE 8 string P_No[M]; string P_name[M]; string A_ID[M]; string A_name[M]; string A_password[M]; int A_Jur[M]; string S_name[M]; string S_No[M];//学号 string S_password[M]; string s_ID[M];//身份证号 string S_address[M]; string S_Tel[M]; char S_sex[M]; string user;//当前用户名 int Jur;//权限等级 super--9 admin--1 stu--2 int welcome(); int student_login(); int admin_login(); int Smenu(int); int Smenu_b(int); int Smenu_c(int); int Amenu(int); int Amenu_b(int); int Amenu_c(int); int Amenu_q(); //string S_safeCHECK(string); //string S_safeRECHECK(string); string AZ(string); string ZA(string); char *get_password(const char *prompt); class Pro //专业类---文件顺序 outfile<<PNo<<" "<<Pname<<" "<<endl; { private: string PNo; string Pname; public: int Padd() { cout<<"请输入专业名称:"; cin>>Pname; cin.sync(); cout<<"请输入专业代码:"; cin>>PNo; cin.sync(); ofstream outfile("Pro..Hui3yer.dat",ios::app);//app---追加 if(!outfile) { cerr<<"open error!"<<endl; exit(0); } PNo = AZ(PNo);//字符串存取前 Pname = AZ(Pname); outfile<<PNo<<" "<<Pname<<" "<<endl; outfile.close(); } int Pdelete() { int mark; char s; int k,i; mark = Pshow(); if(mark==0) { cout<<"没有专业信息"; getchar(); return 0; } cout<<"请选择一个删除序号<放弃(0)>:"; cin>>k;cin.sync(); if(k==0)return 0; cout<<"确定删除【y/n】?"; while(1) { cin>>s;cin.sync(); if(s=='y'||s=='Y') { ofstream outfile("Pro..Hui3yer.dat",ios::out); if(!outfile) { cerr<<"open error!"<<endl; exit(1); } for(i=0;i<mark-1;i++) { if(i!=k-1) { P_No[i] = AZ(P_No[i]); P_name[i] = AZ(P_name[i]); outfile<<P_No[i]<<" "<<P_name[i]<<" "<<endl; } } outfile.close(); cout<<"删除成功!"; getchar(); return 0; } if(s=='n'||s=='N') return 0; cout<<"输入有误:"; } } int Pshow() { int mark,i; ifstream infile("Pro..Hui3yer.dat",ios::in); if(!infile) { cout<<"请先添加哦~亲!"<<endl; getchar(); return 0; } cout<<"序号 专业代码 专业名称"<<endl; for(i=0; !infile.eof(); i++) { infile>>P_No[i]>>P_name[i]; P_No[i] = ZA(P_No[i]);//字符串读取后 P_name[i] = ZA(P_name[i]); } mark=i; for( i=0; i<mark-1;i++) { cout<<i+1<<" "<<P_No[i]<<" "<<P_name[i]<<endl; } infile.close(); getchar(); return mark; } int Psearch() { string temp; int i; ifstream infile("Pro..Hui3yer.dat",ios::in); if(!infile) { cerr<<"无法查找!"<<endl; return 0; } //查找 cout<<"输入查找的专业代号或专业名称:"; cin>>temp; cin.sync(); for(i=0; !infile.eof(); i++) { infile>>P_No[i]>>P_name[i]; P_No[i] = ZA(P_No[i]); P_name[i] = ZA(P_name[i]); if(P_No[i]==temp) { cout<<"代码:"<<P_No[i]<<" 专业名:"<<P_name[i]; infile.close(); getchar(); return 0; } if(P_name[i]==temp) { cout<<"代码:"<<P_No[i]<<" 专业名:"<<P_name[i]; infile.close(); getchar(); return 0; } } cout<<"查无此项!"; getchar(); infile.close(); } int Pchange() { int mark; char s; int k,i; mark = Pshow(); if(mark==0) { cout<<"专业不存在..." <<endl; getchar(); return 0; } cout<<"请选择一个序号进行修改<放弃修改(0)>:"; int choosemax=3; while(i) { cin>>k;cin.sync(); if(k==0) { return 0; } if(k>0&&k<mark) break; choosemax--; if(!choosemax) { cout<<"WARNING!"<<endl; getchar(); return 0; } cout<<"输入有误,重新输入:"; } cout<<"请输入专业名称:"; cin>>Pname;cin.sync(); cout<<"请输入专业代码:"; cin>>PNo;cin.sync(); cout<<"确定修改?【y/n】"; while(1) { cin>>s;cin.sync(); if(s=='y'||s=='Y') { ofstream outfile("Pro..Hui3yer.dat",ios::out); if(!outfile) { cerr<<"open error!"<<endl; exit(1); } for(i=0;i<mark-1;i++) { if(i==k-1) { PNo = AZ(PNo); Pname = AZ(Pname); outfile<<PNo<<" "<<Pname<<" "<<endl; } else { P_No[i] = AZ(P_No[i]); P_name[i] = AZ(P_name[i]); outfile<<P_No[i]<<" "<<P_name[i]<<" "<<endl; } } outfile.close(); cout<<"修改成功!"; getchar(); return 0; } if(s=='n'||s=='N') return 0; cout<<"输入有误:"; } } }; class student : public Pro { private: string SNo;//110405101--11:2011级,0405:计算机科学与技术专业,1:班级;07--学号 string Sname; string Spassword; string sID; string Saddress; char Ssex; string STel; public: int Sadd() { cout<<"请输入学号:";cin>>SNo;cin.sync(); cout<<"请输入姓名:";cin>>Sname;cin.sync(); //cout<<"请输入姓名:";gets(Sname);cin.sync(); cout<<"请输入性别【M/F】:";cin>>Ssex;cin.sync(); cout<<"请输入密码:";cin>>Spassword;cin.sync(); //cout<<"请输入密码:";gets(Spassword);cin.sync(); cout<<"请输入身份证号:";cin>>sID;cin.sync(); cout<<"请输入电话:";cin>>STel;cin.sync(); cout<<"请输入家庭住址:";cin>>Saddress;cin.sync(); //cout<<"请输入家庭住址:";gets(Saddress);cin.sync(); ofstream outfile("stu..Hui3yer.dat",ios::app);//app---追加 if(!outfile) { cerr<<"open error!"<<endl; exit(1); } SNo = AZ(SNo); Sname = AZ(Sname); Spassword = AZ(Spassword); sID = AZ(sID); STel = AZ(STel); Saddress = AZ(Saddress); outfile<<SNo<<" "<<Sname<<" "<<Ssex<<" "<<Spassword<<" "<<sID<<" "<<STel<<" "<<Saddress<<" "<<endl; outfile.close(); } int Sdelete() { int mark; char s; int k,i; mark = Sshow(); if(mark == 0) { cout<<"请先添加哦~亲!"<<endl; getchar(); return 0; } cout<<"请选择一个删除序号<放弃(0)>:"; cin>>k;cin.sync(); if(k==0) return 0; cout<<"确定删除【y/n】?"; while(1) { cin>>s;cin.sync(); if(s=='y'||s=='Y') { ofstream outfile("stu..Hui3yer.dat",ios::out); if(!outfile) { cerr<<"open error!"<<endl; exit(1); } for(i=0;i<mark-1;i++) { if(i!=k-1) { S_No[i] = AZ(S_No[i]); S_name[i] = AZ(S_name[i]); S_password[i] = AZ(S_password[i]); s_ID[i] = AZ(s_ID[i]); S_Tel[i] = AZ(S_Tel[i]); S_address[i] = AZ(S_address[i]); outfile<<S_No[i]<<" "<<S_name[i]<<" "<<S_sex[i]<<" "<<S_password[i]<<" "<<s_ID[i]<<" "<<S_Tel[i]<<" "<<S_address[i]<<" "<<endl; } } outfile.close(); cout<<"删除成功!"; getchar(); return 0; } if(s=='n'||s=='N') return 0; cout<<"输入有误:"; } } int Sshow() { int mark,i; ifstream infile("stu..Hui3yer.dat",ios::in);//nocreat---不创建<不支持?why> if(!infile) { return 0; } cout<<"序号 学号 姓名 性别 密码 身份证号 电话 家庭住址"<<endl; for(i=0; !infile.eof(); i++) { infile>>S_No[i]>>S_name[i]>>S_sex[i]>>S_password[i]>>s_ID[i]>>S_Tel[i]>>S_address[i]; S_No[i] = ZA(S_No[i]); S_name[i] = ZA(S_name[i]); S_password[i] = ZA(S_password[i]); s_ID[i] = ZA(s_ID[i]); S_Tel[i] = ZA(S_Tel[i]); S_address[i] = ZA(S_address[i]); } mark=i; for( i=0; i<mark-1;i++) { cout<<i+1<<" "<<S_No[i]<<" "<<S_name[i]<<" "<<S_sex[i]<<" "<<S_password[i]<<" "<<s_ID[i]<<" "<<S_Tel[i]<<" "<<S_address[i]<<" "<<endl; } infile.close(); getchar(); return mark; } int Ssearch() { int Hui=0; string temp; int i; ifstream infile("stu..Hui3yer.dat",ios::in); if(!infile) { cerr<<"无法查找!"<<endl; getchar(); return 0; } //按学号查找 cout<<"输入查找的学号或姓名:"; cin>>temp; cin.sync(); for(i=0; !infile.eof(); i++) { infile>>S_No[i]>>S_name[i]>>S_sex[i]>>S_password[i]>>s_ID[i]>>S_Tel[i]>>S_address[i]; S_No[i] = ZA(S_No[i]); S_name[i] = ZA(S_name[i]); S_password[i] = ZA(S_password[i]); s_ID[i] = ZA(s_ID[i]); S_Tel[i] = ZA(S_Tel[i]); S_address[i] = ZA(S_address[i]); if(S_No[i]==temp) { cout<<"学号:"<<S_No[i]<<endl; cout<<"姓名:"<<S_name[i]<<endl; cout<<"性别:"<<S_sex[i]<<endl; cout<<"密码:"<<S_password[i]<<endl; cout<<"身份证号:"<<s_ID[i]<<endl; cout<<"电话:"<<S_Tel[i]<<endl; cout<<"家庭住址:"<<S_address[i]<<endl; infile.close(); getchar(); return 0; } if(S_name[i]==temp) { cout<<"学号:"<<S_No[i]<<endl; cout<<"姓名:"<<S_name[i]<<endl; cout<<"性别:"<<S_sex[i]<<endl; cout<<"密码:"<<S_password[i]<<endl; cout<<"身份证号:"<<s_ID[i]<<endl; cout<<"电话:"<<S_Tel[i]<<endl; cout<<"家庭住址:"<<S_address[i]<<endl; cout<<endl; Hui=1; } } if(Hui) { getchar(); return 0; } cout<<"查无此项!"; getchar(); infile.close(); } int Schange() { int mark; char s; int k,i; mark = Sshow(); if(mark == 0) { cout<<"请先添加哦~亲!"<<endl; getchar(); return 0; } cout<<"请选择一个序号进行修改<放弃(0)>:"; int choosemax = 3; while(1) { cin>>k;cin.sync(); if(k==0) return 0; if(k>0&&k<mark) break; choosemax--; if(!choosemax) { cout<<"WARNNING。。。"; getchar(); return 0; } cout<<"输入有误,请重新输入:"; } //cin>>k;cin.sync(); cout<<"请输入学号:";cin>>SNo;cin.sync(); cout<<"请输入姓名:";cin>>Sname;cin.sync(); //cout<<"请输入姓名:";gets(Sname);cin.sync(); cout<<"请输入性别【M/F】:";cin>>Ssex;cin.sync(); cout<<"请输入密码:";cin>>Spassword;cin.sync(); //cout<<"请输入密码:";gets(Spassword);cin.sync(); cout<<"请输入身份证号:";cin>>sID;cin.sync(); cout<<"请输入电话:";cin>>STel;cin.sync(); cout<<"请输入家庭住址:";cin>>Saddress;cin.sync(); //cout<<"请输入家庭住址:";gets(Saddress);cin.sync(); cout<<"确定修改?【y/n】"; while(1) { cin>>s;cin.sync(); if(s=='y'||s=='Y') { ofstream outfile("stu..Hui3yer.dat",ios::out); if(!outfile) { cerr<<"open error!"<<endl; exit(1); } for(i=0;i<mark-1;i++) { if(i==k-1) { SNo = AZ(SNo); Sname = AZ(Sname); Spassword = AZ(Spassword); sID = AZ(sID); STel = AZ(STel); Saddress = AZ(Saddress); outfile<<SNo<<" "<<Sname<<" "<<Ssex<<" "<<Spassword<<" "<<sID<<" "<<STel<<" "<<Saddress<<" "<<endl; } else { S_No[i] = AZ(S_No[i]); S_name[i] = AZ(S_name[i]); S_password[i] = AZ(S_password[i]); s_ID[i] = AZ(s_ID[i]); S_Tel[i] = AZ(S_Tel[i]); S_address[i] = AZ(S_address[i]); outfile<<S_No[i]<<" "<<S_name[i]<<" "<<S_sex[i]<<" "<<S_password[i]<<" "<<s_ID[i]<<" "<<S_Tel[i]<<" "<<S_address[i]<<" "<<endl; } } outfile.close(); cout<<"修改成功!"; getchar(); return 0; } if(s=='n'||s=='N') return 0; cout<<"输入有误:"; } } int S_DOID(string S) { int j,i; char s1[3]; char s2[5]; for(j=0;j<2;j++) { s1[j]=S[j]; } s1[2]=' '; for(j=2;j<6;j++) { s2[j-2]=S[j]; } s2[4]=' '; //cout<<S<<endl; cout<<" 入学年份:20"<<s1<<"年 " ; ifstream infile("Pro..Hui3yer.dat",ios::in);//nocreat---不创建<不支持?why> if(!infile) { cerr<<"<部分信息丢失!>"<<endl; //getchar(); return 0; } for(i=0; !infile.eof(); i++) { infile>>P_No[i]>>P_name[i]; P_No[i] = ZA(P_No[i]); P_name[i] = ZA(P_name[i]); if((string)s2==P_No[i]) { cout<<"专业:"<<P_name[i]<<endl; infile.close(); // getchar(); return 0; } } cout<<"<该学生专业信息不存在!>"<<endl;; // getchar(); return 0; } }; //student AD_stu; //Pro AD_pro; class Admin : public student //管理员类 { private: string AID; string Aname; string Apassword; int AJur;//权限 jurisdiction //Pro Apro; //student Astu; public: int Aadd() { int n; cout<<"请输入管理员编号:"; cin>>AID;cin.sync(); cout<<"请输入管理员姓名(用户名):"; cin>>Aname;cin.sync(); //gets(Aname);cin.sync(); cout<<"请输入管理员用户密码:"; cin>>Apassword; cin.sync(); //gets(Apassword); cin.sync(); cout<<"请输入权限值:<Super--9 admin--1>"; cin>>AJur;cin.sync(); ofstream outfile("admin..Hui3yer.dat",ios::app); if(!outfile) { cerr<<"open error!"<<endl; getchar(); exit(1); } AID = AZ(AID); Aname = AZ(Aname); Apassword = AZ(Apassword); //AJur = AZ(AJur); outfile<<AID<<" "<<Aname<<" "<<Apassword<<" "<<AJur<<" "<<endl; outfile.close(); // cout<<"请输入管理员权限等级(输入-1查看帮助):"; // cin>>n;cin.sync(); // if(n==-1) // { // cout<<"***********************************************"<<endl; // cout<<"* 权限说明 *"<<endl; // cout<<"* 1:管理员---可以查看修改删除专业及学生信息 *"<<endl; // cout<<"* 9:super ---可以查看,修改全体学生信息 *"<<endl; // cout<<"* ###其余无效### *"<<endl; // cout<<"***********************************************"<<endl; // cout<<"请选择:"; // cin>>Jur;cin.sync(); // } // else Jur = n; return 0; } int Adelete() { int mark; char s; int k,i; mark = Ashow(); if(mark==0) { cout<<":( 没有添加哪里有得删呢?"; getchar(); return 0; } cout<<"请选择一个删除序号<放弃(0)>:"; cin>>k;cin.sync(); if(k==0) return 0; cout<<"确定删除【y/n】?"; while(1) { cin>>s;cin.sync(); if(s=='y'||s=='Y') { ofstream outfile("admin..Hui3yer.dat",ios::out); if(!outfile) { cerr<<"open error!"<<endl; exit(1); } for(i=0;i<mark-1;i++) { if(i!=k-1) { A_ID[i] = AZ(A_ID[i]); A_name[i] = AZ(A_name[i]); A_password[i] = AZ(A_password[i]); outfile<<A_ID[i]<<" "<<A_name[i]<<" "<<A_password[i]<<" "<<A_Jur[i]<<" "<<endl; } } outfile.close(); cout<<"删除成功!"; getchar(); return 0; } if(s=='n'||s=='N') return 0; cout<<"输入有误:"; } } int Ashow() { int mark,i; ifstream infile("admin..Hui3yer.dat",ios::in); if(!infile) { getchar(); return 0; } cout<<"序号 ID 姓名 密码 权限"<<endl; for(i=0; !infile.eof(); i++) { infile>>A_ID[i]>>A_name[i]>>A_password[i]>>A_Jur[i]; A_ID[i] = ZA(A_ID[i]); A_name[i] = ZA(A_name[i]); A_password[i] = ZA(A_password[i]); } mark=i; for( i=0; i<mark-1;i++) { cout<<i+1<<" "<<A_ID[i]<<" "<<A_name[i]<<" "<<A_password[i]<<" "<<A_Jur[i]<<" "<<endl; } infile.close(); getchar(); return mark; } int Asearch() { string temp; int i; ifstream infile("admin..Hui3yer.dat",ios::in); if(!infile) { cerr<<"无法查找!"<<endl; getchar(); return 0; } //按 XXX查找 cout<<"输入查找的ID:"; cin>>temp; cin.sync(); for(i=0; !infile.eof(); i++) { infile>>A_ID[i]>>A_name[i]>>A_password[i]>>A_Jur[i]; A_ID[i] = ZA(A_ID[i]); A_name[i] = ZA(A_name[i]); A_password[i] = ZA(A_password[i]); if(A_ID[i]==temp) { cout<<"ID:"<<A_ID[i]<<endl; cout<<"姓名:"<<A_name[i]<<endl; cout<<"密码:"<<A_password[i]<<endl; cout<<"权限:"<<A_Jur[i]<<endl; infile.close(); getchar(); return 0; } } cout<<"查无此项!"; getchar(); infile.close(); } int Achange() { int mark; char s; int k,i; mark = Ashow(); if(mark == 0) { cout<<"请先添加哦~亲!"<<endl; getchar(); return 0; } cout<<"请选择一个序号进行修改<放弃(0)>:"; int choosemax = 5; while(1) { cin>>k;cin.sync(); if(k==0) break; if(k>0&&k<mark) break; choosemax--; if(!choosemax) { cout<<"WARNNING。。。"; getchar(); return 0; } cout<<"输入有误,请重新输入:"; } cout<<"请输入管理员编号:"; cin>>AID;cin.sync(); //gets(AID);cin.sync(); cout<<"请输入管理员姓名(用户名):"; cin>>Aname;cin.sync(); //gets(Aname);cin.sync(); cout<<"请输入管理员用户密码:"; cin>>Apassword; cin.sync(); //gets(Apassword); cin.sync(); cout<<"请输入权限值:";cin>>AJur;cin.sync(); cout<<"确定修改?【y/n】"; while(1) { cin>>s;cin.sync(); if(s=='y'||s=='Y') { ofstream outfile("admin..Hui3yer.dat",ios::out); if(!outfile) { cerr<<"open error!"<<endl; exit(1); } for(i=0;i<mark-1;i++) { if(i=k-1) { AID = AZ(AID); Aname = AZ(Aname); Apassword = AZ(Apassword); outfile<<AID<<" "<<Aname<<" "<<Apassword<<" "<<AJur<<" "<<endl; } else { A_ID[i] = AZ(A_ID[i]); A_name[i] = AZ(A_name[i]); A_password[i] = AZ(A_password[i]); outfile<<A_ID[i]<<" "<<A_name[i]<<" "<<A_password[i]<<" "<<A_Jur[i]<<" "<<endl; } } outfile.close(); cout<<"修改成功!"; getchar(); return 0; } if(s=='n'||s=='N') return 0; cout<<"输入有误:"; } } }; int welcome()//主界面 --界面模版 { char n; int Mark; while(1) { system("cls"); Mark=1; cout<<"**********************************************************************"<<endl; cout<<"* *"<<endl; cout<<"* ★Hui3yer学生多功能管理系统★ *"<<endl; cout<<"* 用户类型选择 *"<<endl; cout<<"**********************************************************************"<<endl; cout<<"* *"<<endl; cout<<"* 请选择您的用户类型 *"<<endl; cout<<"* *"<<endl; cout<<"* 用户类型 请输入 *"<<endl; cout<<"* *"<<endl; cout<<"* ◆ 学生 1 *"<<endl; cout<<"* *"<<endl; cout<<"* ◆ 管理员 2 *"<<endl; cout<<"* *"<<endl; cout<<"* *"<<endl; cout<<"* ● 退出管理系统 0 *"<<endl; cout<<"* *"<<endl; cout<<"**********************************************************************"<<endl; cout<<"请选择功能:"; while(Mark) { cin>>n;cin.sync(); //if(n!=int(n)) n=-1; switch(n) { case '1': Smenu(student_login());Mark=0;break; case '2': Amenu(admin_login());Mark=0;break; case '0': exit(0); default : cout<<" 输入有误,请重新输入:"; } } } return 0; } int student_login() { int i; string password; system("cls"); ifstream infile("stu..Hui3yer.dat",ios::in); if(!infile) { cerr<<" 系统未开放使用!"; getchar(); exit(1); } infile.close(); cout<<" "<<endl; cout<<" ***********************************"<<endl; cout<<" * *"<<endl; cout<<" * ★Hui3yer学生多功能管理系统★ *"<<endl; cout<<" * 用户登录 *"<<endl; cout<<" ***********************************"<<endl; while(1) { cout<<" 用户名<学号>:"; cin>>user;cin.sync(); cout<<" 密码: "; cin>>password;cin.sync(); ifstream infile("stu..Hui3yer.dat",ios::in); for(i=0;!infile.eof();i++) { infile>>S_No[i]>>S_name[i]>>S_sex[i]>>S_password[i]>>s_ID[i]>>S_Tel[i]>>S_address[i]; S_No[i] = ZA(S_No[i]); S_name[i] = ZA(S_name[i]); S_password[i] = ZA(S_password[i]); s_ID[i] = ZA(s_ID[i]); S_Tel[i] = ZA(S_Tel[i]); S_address[i] = ZA(S_address[i]); if(user ==S_No[i] &&password == S_password[i]) { cout<<" 登录成功..."; getchar(); return i; } } cout<<" 用户名或密码错误..."; getchar(); infile.close(); } } int admin_login() { int i; string password; system("cls"); cout<<" "<<endl; cout<<" **********************************"<<endl; cout<<" * *"<<endl; cout<<" * ★Hui3yer学生多功能管理系统★ *"<<endl; cout<<" * 管理员用户登录 *"<<endl; cout<<" ***********************************"<<endl; ifstream infile("admin..Hui3yer.dat",ios::in); if(!infile) { cout<<" 超级用户:"; cin>>user; cin.sync(); if(user=="admin") { i=3; cout<<" 超级密码:"; while(i) { cin>>password;cin.sync(); //密码隐藏************* //char *H_password; //H_password = get_password( "" ); //********************* if(password == "admin") { password="admin"; Jur=9; cout<<" 登录已成功!"; getchar(); return 1; } else { i--; cout<<" 密码错误请重新输入:";cin.sync(); } } system("cls"); cerr<<" 密码输入错误次数过多强制退出..."; getchar(); exit(1); } else { system("cls"); cerr<<" 无权限使用..."; getchar(); exit(1); } } else { infile.close(); while(1) { user = ""; password = ""; cout<<" 用户名:"; cin>>user;cin.sync(); cout<<" 密码: "; cin>>password;cin.sync(); ifstream infile("admin..Hui3yer.dat",ios::in); for(i=0;!infile.eof();i++) { infile>>A_ID[i]; //A_ID[i] = ZA(A_ID[i]); infile>>A_name[i]; //A_name[i] = ZA(A_name[i]); infile>>A_password[i]; //A_password[i] = ZA(A_password[i]); infile>>A_Jur[i]; if(user == A_name[i]&&password == A_password[i]) { Jur=A_Jur[i]; cout<<" 登录成功..."; getchar(); infile.close(); return i; } } cout<<" 用户名或密码错误..."; getchar(); } } return 0; } int Smenu(int a) { char n; int Mark; int i; int mark; while(1) { system("cls"); student ST_stu; //Pro ST_pro; Mark=1; cout<<"**********************************************************************"<<endl; cout<<"* *"<<endl; cout<<"* ★Hui3yer学生多功能管理系统★ *"<<endl; cout<<"* 用户:"<<setw(10)<<user<<" *"<<endl; cout<<"**********************************************************************"<<endl; cout<<"* *"<<endl; cout<<"* 请选择 *"<<endl; cout<<"* *"<<endl; cout<<"* ┌--------------------- 学生功能窗 --------------------------┐*"<<endl; cout<<"* | | *"<<endl; cout<<"* |◆查看个人信息 a ◆修改密码 c | *"<<endl; cout<<"* |◆修改个人信息 b ◆学籍信息 d | *"<<endl; cout<<"* └---------------------------------------------------------------┘*"<<endl; cout<<"* *"<<endl; cout<<"* ● 退出管理系统 0 *"<<endl; cout<<"* *"<<endl; cout<<"**********************************************************************"<<endl; cout<<"请选择功能:"; while(Mark) { cin>>n;cin.sync(); switch(n) { case 'a': cout<<"学号:"<<S_No[a]<<endl; cout<<"姓名:"<<S_name[a]<<endl; cout<<"性别:"<<S_sex[a]<<endl; //cout<<"密码:"<<S_password[a]<<endl; cout<<"身份证号:"<<s_ID[a]<<endl; cout<<"电话:"<<S_Tel[a]<<endl; cout<<"家庭住址:"<<S_address[a]<<endl; getchar(); Mark=0;break; case 'b': cout<<"~~~~~~~~~~~~~原始数据~~~~~~~~~~~~ "<<endl; cout<<"学号:"<<S_No[a]<<endl; cout<<"姓名:"<<S_name[a]<<endl; cout<<"性别:"<<S_sex[a]<<endl; //cout<<"密码:"<<S_password[a]<<endl; cout<<"身份证号:"<<s_ID[a]<<endl; cout<<"电话:"<<S_Tel[a]<<endl; cout<<"家庭住址:"<<S_address[a]<<endl; cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "<<endl; cout<<"是否修改【Y/N】?"; char z; while(1) { cin>>z;cin.sync(); if(z=='Y'||z=='y') { Smenu_b(a);Mark=0;break; } else if(z=='N'||z=='n') { Mark=0;break; } } break; case 'c': Smenu_c(a);Mark=0;break; case 'd': ST_stu.S_DOID(S_No[a]);getchar();Mark=0;break; case '0': exit(0); default : cout<<" 输入有误,请重新输入:"; } } } return 0; } int Smenu_b(int a) { int i,mark; ifstream infile("stu..Hui3yer.dat",ios::in); for(i=0;!infile.eof();i++) { infile>>S_No[i]>>S_name[i]>>S_sex[i]>>S_password[i]>>s_ID[i]>>S_Tel[i]>>S_address[i]; S_No[i] = ZA(S_No[i]); S_name[i] = ZA(S_name[i]); S_password[i] = ZA(S_password[i]); s_ID[i] = ZA(s_ID[i]); S_Tel[i] = ZA(S_Tel[i]); S_address[i] = ZA(S_address[i]); } mark=i; infile.close(); cout<<"请输入学号:";cin>>S_No[a];cin.sync(); cout<<"请输入姓名:"; cin>>S_name[a];cin.sync(); //gets(S_name[a]);cin.sync(); cout<<"请输入性别【M/F】:";cin>>S_sex[a];cin.sync(); cout<<"请输入身份证号:";cin>>s_ID[a];cin.sync(); cout<<"请输入电话:";cin>>S_Tel[a];cin.sync(); cout<<"请输入家庭住址:"; cin>>S_address[a];cin.sync(); //gets(S_address[a]);cin.sync(); ofstream outfile("stu..Hui3yer.dat",ios::out); for(i=0;i<mark-1;i++) { S_No[i] = AZ(S_No[i]); S_name[i] = AZ(S_name[i]); S_password[i] = AZ(S_password[i]); s_ID[i] = AZ(s_ID[i]); S_Tel[i] = AZ(S_Tel[i]); S_address[i] = AZ(S_address[i]); outfile<<S_No[i]<<" "<<S_name[i]<<" "<<S_sex[i]<<" "<<S_password[i]<<" "<<s_ID[i]<<" "<<S_Tel[i]<<" "<<S_address[i]<<" "<<endl; } outfile.close(); return 0; } int Smenu_c(int a) { int i,mark; ifstream infile("stu..Hui3yer.dat",ios::in); for(i=0;!infile.eof();i++) { infile>>S_No[i]>>S_name[i]>>S_sex[i]>>S_password[i]>>s_ID[i]>>S_Tel[i]>>S_address[i]; S_No[i] = ZA(S_No[i]); S_name[i] = ZA(S_name[i]); S_password[i] = ZA(S_password[i]); s_ID[i] = ZA(s_ID[i]); S_Tel[i] = ZA(S_Tel[i]); S_address[i] = ZA(S_address[i]); } mark=i; infile.close(); cout<<"请输入新密码:"; cin>>S_password[a];cin.sync(); //gets(S_password[a]);cin.sync(); ofstream outfile("stu..Hui3yer.dat",ios::out); for(i=0;i<mark-1;i++) { S_No[i] = AZ(S_No[i]); S_name[i] = AZ(S_name[i]); S_password[i] = AZ(S_password[i]); s_ID[i] = AZ(s_ID[i]); S_Tel[i] = AZ(S_Tel[i]); S_address[i] = AZ(S_address[i]); outfile<<S_No[i]<<" "<<S_name[i]<<" "<<S_sex[i]<<" "<<S_password[i]<<" "<<s_ID[i]<<" "<<S_Tel[i]<<" "<<S_address[i]<<" "<<endl; } outfile.close(); return 0; } int Amenu(int a) { system("MAX"); char n; int Mark; while(1) { system("cls"); //student AD_stu; //Pro AD_pro; Admin AD_admin; Mark=1; cout<<"**********************************************************************"<<endl; cout<<"* *"<<endl; cout<<"* ★Hui3yer学生多功能管理系统★ *"<<endl; cout<<"* 用户:"<<setw(10)<<user<<" *"<<endl; cout<<"**********************************************************************"<<endl; cout<<"* *"<<endl; cout<<"* 请选择 *"<<endl; cout<<"* *"<<endl; cout<<"* 功能名 请输入 功能名 请输入 *"<<endl; cout<<"* ◆ 添加专业信息 1 ◆ 添加学生信息 6 *"<<endl; cout<<"* ◆ 删除专业信息 2 ◆ 删除学生信息 7 *"<<endl; cout<<"* ◆ 修改专业信息 3 ◆ 修改学生信息 8 *"<<endl; cout<<"* ◆ 查找专业信息 4 ◆ 查找学生信息 9 *"<<endl; cout<<"* ◆ 显示专业信息 5 ◆ 显示学生信息 s *"<<endl; cout<<"* ◆ 显示学生学籍 q *"<<endl; cout<<"* ┌-------------- 以下选项仅适用于Super管理员 ----------------┐*"<<endl; cout<<"* | | *"<<endl; cout<<"* |◆ 添加管理员 A ◆ 修改管理员 D | *"<<endl; cout<<"* |◆ 删除管理员 B ◆ 查找管理员 E | *"<<endl; cout<<"* |◆ 显示管理员 C | *"<<endl; cout<<"* └---------------------------------------------------------------┘*"<<endl; cout<<"* ┌--------------- 以下选项仅适用于普通管理员 ----------------┐*"<<endl; cout<<"* | | *"<<endl; cout<<"* |◆查看个人信息 a ◆修改密码 c | *"<<endl; cout<<"* |◆修改个人信息 b | *"<<endl; cout<<"* └---------------------------------------------------------------┘*"<<endl; cout<<"* *"<<endl; cout<<"* ● 退出管理系统 0 *"<<endl; cout<<"* *"<<endl; cout<<"**********************************************************************"<<endl; cout<<"请选择功能:"; while(Mark) { cin>>n;cin.sync(); //if(n!=int(n)) n=-1; switch(n) { case '1': AD_admin.Padd();Mark=0;break; case '2': AD_admin.Pdelete();Mark=0;break; case '3': AD_admin.Pchange();Mark=0;break; case '4': AD_admin.Psearch();Mark=0;break; case '5': AD_admin.Pshow();Mark=0;break; case '6': AD_admin.Sadd();Mark=0;break; case '7': AD_admin.Sdelete();Mark=0;break; case '8': AD_admin.Schange();Mark=0;break; case '9': AD_admin.Ssearch();Mark=0;break; case 's': AD_admin.Sshow();Mark=0;break; case 'q': Amenu_q();Mark=0;break; case 'A': AD_admin.Aadd();Mark=0;break; case 'B': AD_admin.Adelete();Mark=0;break; case 'C': AD_admin.Ashow();Mark=0;break; case 'D': AD_admin.Achange();Mark=0;break; case 'E': AD_admin.Asearch();Mark=0;break; case 'a': if(user=="admin") { cout<<"该选项不适用于超级管理员用户"<<endl; getchar(); Mark=0;break; } cout<<"管理员ID:"<<A_ID[a]<<endl; cout<<"管理员姓名:"<<A_name[a]<<endl; //cout<<"密码:"<<A_password[a]<<endl; cout<<"权限:"<<A_Jur[a]<<endl; getchar(); Mark=0;break; case 'b': Amenu_b(a);Mark=0;break; case 'c': Amenu_c(a);Mark=0;break; case '0': exit(0); default : cout<<" 输入有误,请重新输入:"; } } } return 0; } int Amenu_q() { student ST_stu; int i,mark; ifstream infile("stu..Hui3yer.dat",ios::in); if(!infile) { cout<<"没有学生。。。"<<endl;getchar(); return 0; } for(i=0;!infile.eof();i++) { infile>>S_No[i]>>S_name[i]>>S_sex[i]>>S_password[i]>>s_ID[i]>>S_Tel[i]>>S_address[i]; S_No[i] = ZA(S_No[i]); S_name[i] = ZA(S_name[i]); S_password[i] = ZA(S_password[i]); s_ID[i] = ZA(s_ID[i]); S_Tel[i] = ZA(S_Tel[i]); S_address[i] = ZA(S_address[i]); } mark=i; for(i=0;i<mark-1;i++) { cout<<"序号:"<<i+1<<"学号"<<S_No[i]<<" 姓名:"<< S_name[i] ; ST_stu.S_DOID(S_No[i]); } infile.close(); getwchar(); } int Amenu_b(int a) { int i,mark; ifstream infile("admin..Hui3yer.dat",ios::in); if(!infile) { cout<<"超级管理员无法修改!"; getchar(); return 0; } for(i=0;!infile.eof();i++) { infile>>A_ID[i]>>A_name[i]>>A_password[i]>>A_Jur[i]; A_ID[i] = ZA(A_ID[i]); A_name[i] = ZA(A_name[i]); A_password[i] = ZA(A_password[i]); } mark=i; infile.close(); cout<<"请输入ID:";cin>>A_ID[a];cin.sync(); cout<<"请输入姓名:"; cin>>A_name[a];cin.sync(); //gets(A_name[a]);cin.sync(); //cout<<"请输入密码:";A_password[i];cin.sync(); cout<<"请输入权限:";A_Jur[i];cin.sync(); ofstream outfile("admin..Hui3yer.dat",ios::out); for(i=0;i<mark-1;i++) { A_ID[i] = AZ(A_ID[i]); A_name[i] = AZ(A_name[i]); A_password[i] = AZ(A_password[i]); outfile<<A_ID[i]<<" "<<A_name[i]<<" "<<A_password[i]<<" "<<A_Jur[i]<<" "<<endl; } outfile.close(); return 0; } int Amenu_c(int a) { int i,mark; ifstream infile("admin..Hui3yer.dat",ios::in); if(!infile) { cout<<"超级管理员无法修改!"; getchar(); return 0; } for(i=0;!infile.eof();i++) { infile>>A_ID[i]>>A_name[i]>>A_password[i]>>A_Jur[i]; A_ID[i] = ZA(A_ID[i]); A_name[i] = ZA(A_name[i]); A_password[i] = ZA(A_password[i]); } mark=i; infile.close(); cout<<"请输入新密码:"; cin>>A_password[a];cin.sync(); //gets(A_password[a]);cin.sync(); ofstream outfile("admin..Hui3yer.dat",ios::out); for(i=0;i<mark-1;i++) { A_ID[i] = AZ(A_ID[i]); A_name[i] = AZ(A_name[i]); A_password[i] = AZ(A_password[i]); outfile<<A_ID[i]<<" "<<A_name[i]<<" "<<A_password[i]<<" "<<A_Jur[i]<<" "<<endl; } outfile.close(); return 0; } int main() { system("color 0E "); welcome(); return 0; } /* system("color XX "); 0 = 黑色 8 = 灰色 1 = 蓝色 9 = 淡蓝色 2 = 绿色 A = 淡绿色 3 = 湖蓝色 B = 淡浅绿色 4 = 红色 C = 淡红色 5 = 紫色 D = 淡紫色 6 = 黄色 E = 淡黄色 7 = 白色 F = 亮白色 */ //用于解决字符串问题* NO! string AZ(string s)//字符串存取前 { int len; len = s.length(); for(int i=0; i<len; i++) { if(s[i]==' ') s[i]='$'; } return (string)s; } string ZA(string s)//字符串读取后 { int len; len = s.length(); for(int i=0; i<len; i++) { if(s[i]=='$') s[i]=' '; } return (string)s; } char *get_password(const char *prompt) //密码隐藏 NO { static char buffer[128]; int i = 0; char letter=NULL; printf( prompt ); while ( ( i < 127 ) && ( letter!=' ' ) ) { letter = getch(); if ( letter == BACKSPACE ) { if( i > 0 ) { buffer[ --i ] = NULL; putchar( BACKSPACE ); putchar( ' ' ); putchar( BACKSPACE ); } else putchar( 7 ); } else if ( letter != ' ' ) { buffer[ i++ ] = letter; putchar( '*' ); } } buffer[i] = ' '; return buffer; } /* system("clor XX "); 0 = 黑色 8 = 灰色 1 = 蓝色 9 = 淡蓝色 2 = 绿色 A = 淡绿色 3 = 湖蓝色 B = 淡浅绿色 4 = 红色 C = 淡红色 5 = 紫色 D = 淡紫色 6 = 黄色 E = 淡黄色 7 = 白色 F = 亮白色 */ int NO() { int i; string password; system("cls"); cout<<" "<<endl; cout<<" **********************************"<<endl; cout<<" * *"<<endl; cout<<" * ★Hui3yer学生多功能管理系统★ *"<<endl; cout<<" * *"<<endl; cout<<" ***********************************"<<endl<<endl<<endl; cout<<" 没有权限!!! "<<endl<<endl<<endl; getwchar(); return 0; }