📄 学生选课系统.cpp
字号:
{
char *sno;
sno=new char;
cout<<"\n\n\n\n\t\t\t请输入你的用户名按回车键确认:";
cin>>sno;
strcpy(stu.m_csno,sno);
return sno;
}
//*********************************************************************
char* CLand::Setscode()
{
char *scode,f;
scode=new char;
int _f=0;
while(1)
{
f=getch();
if(f==13)
break;
if(f==8)
{
if(_f>0)
{
putchar(8);
putchar(0);
putchar(8);
_f--;
}
}
else
{
scode[_f++]=f;
cout<<"*";
}
}
scode[_f]='\0';
strcpy(m_cscode,scode);
return scode;
}
//*********************************************************************
char* CLand::Setadmin()
{
char *admin;
admin=new char;
cout<<"\n\n\n\n\t\t\t请输入您的用户名按回车键确认:";
cin>>admin;
strcpy(m_cadmin,admin);
return admin;
}
//*********************************************************************
char* CLand::Setadmincode()
{
char *admincode,f;
admincode=new char;
int _f=0;
while(1)
{
f=getch();
if(f==13)
break;
if(f==8)
{
if(_f>0)
{
putchar(8);
putchar(0);
putchar(8);
_f--;
}
}
else
{
admincode[_f++]=f;
cout<<"*";
}
}
admincode[_f]='\0';
strcpy(m_cadmincode,admincode);
return admincode;
}
//*********************************************************************
char* CLand::Settno()
{
char *tno;
tno=new char;
cout<<"\n\n\n\n\n\t\t\t请输入您的用户名按回车键确认:";
cin>>tno;
strcpy(teacher.m_ctno,tno);
return tno;
}
//*********************************************************************
char* CLand::Settcode()
{
char *tcode,f;
tcode=new char;
int _f=0;
while(1)
{
f=getch();
if(f==13)
break;
if(f==8)
{
if(_f>0)
{
putchar(8);
putchar(0);
putchar(8);
_f--;
}
}
else
{
tcode[_f++]=f;
cout<<"*";
}
}
tcode[_f]='\0';
strcpy(m_ctcode,tcode);
return tcode;
}
//*********************************************************************
void CLand::Writef(char *fp)
{
ofstream fout(fp);
if (!fout)
{
cout<<"文件不能打开"<<endl;
}
else
{
fout<<endl;
fout<<stu.m_csno<<setw(20)<<m_cscode;
}
fout.close();
}
//*********************************************************************
void CLand::Writef1(char *fp)
{
ofstream fout(fp);
if (!fout)
{
cout<<"文件不能打开"<<endl;
}
else
{
fout<<endl;
fout<<teacher.m_ctno<<setw(20)<<m_ctcode;
}
fout.close();
}
//*********************************************************************
void CLand::Writef2(char *fp)
{
ofstream fout(fp);
if (!fout)
{
cout<<"文件不能打开"<<endl;
}
else
{
fout<<endl;
fout<<m_cadmin<<setw(20)<<m_cadmincode;
}
fout.close();
}
//*********************************************************************
void CLand::Readf(char *fp)
{
ifstream fin(fp);
if (!fin)
{
cout<<"文件不能打开"<<endl;
}
fin.get();
while (!fin.eof())
{
fin>>stu.m_csno>>m_cscode;
}
fin.close();
}
//*********************************************************
void CLand::Readf1(char *fp)
{
ifstream fin(fp);
if (!fin)
{
cout<<"文件不能打开"<<endl;
}
fin.get();
while (!fin.eof())
{
fin>>teacher.m_ctno>>m_ctcode;
}
fin.close();
}
//*********************************************************************
void CLand::Readf2(char *fp)
{
ifstream fin(fp);
if (!fin)
{
cout<<"文件不能打开"<<endl;
}
fin.get();
while (!fin.eof())
{
fin>>m_cadmin>>m_cadmincode;
}
fin.close();
}
//*********************************************************************
char* CLand::Queryf(char *fp)
{
int c=0,d=0,_f=0,n=0,flag=0;
char _e[20],sno[20],scode[20];
ifstream fin(fp);
while(c<=2)
{
cout<<"\n\n\n\n\t\t\t欢迎你进入学生选课端\n";
cout<<"\n\t\t\t你的用户名为你的学号";
cin>>sno;
fin.close();
fin.clear();
fin.open("student.txt");
if (!fin)
{
cout<<"\n\n\n\n\t\t你的用户名不存在!"<<endl;
cout<<"\t\t你可能是还没有注册,请你先到管理员处注册!"<<endl;
cout<<"\t\t请按任意键继续!";
getch();
system("cls");
handle_Memu1();
}
fin.get();
fin.close();
fin.clear();
fin.open("student.txt");
while (!fin.eof())
{
fin>>stu.m_csno>>stu.m_csname>>stu.m_csex>>stu.m_cbanji>>stu.m_czhuanye
>>stu.m_imaxcourse>>stu.m_ifactcourse;
if (strcmp(stu.m_csno,sno)==0)
{
flag=1;
strcpy(_e,sno);
while(d<=2)
{
cout<<"\n\t\t\t你的初始密码为你的学号"<<endl;
cout<<"\n\t\t\t请你及时修改你的密码"<<endl;
cout<<"\n\t\t\t请输入你的密码按回车键确认:";
strcpy(scode,Setscode());
fin.close();
fin.clear();
fin.open("scode.txt");
if (!fin)
{
if(strcmp(_e,scode)==0)
{
Writef("scode.txt");
handle_Memu3(sno);
}
system("cls");
d++;
cout<<"\n\n\t\t\t密码输入错误!请重新输入!\n"<<endl;
if(d>=3)
{
system("cls");
cout<<"\n\n\t\t\t输入错误密码超过三次!请按任意键退出.."<<endl;
exit(0);
}
strcpy(scode,Setscode());
}
fin.get();
while (!fin.eof())
{
fin>>stu.m_csno>>m_cscode;
if(strcmp(m_cscode,scode)==0)
{
Writef("scode.txt");
handle_Memu3(sno);
}
else
{
if(strcmp(_e,scode)==0)
{
Writef("scode.txt");
handle_Memu3(sno);
}
}
}
system("cls");
d++;
cout<<"\n\n\t\t\t密码输入错误!请重新输入!\n"<<endl;
if(d>=3)
{
system("cls");
cout<<"\n\n\t\t\t输入错误密码超过三次!请按任意键退出.."<<endl;
exit(0);
}
}
}
}
if(!flag)
{
c++;
system("cls");
cout<<"\n\n\n\n\t\t你的用户名输入错误!"<<endl;
}
if(c>=3)
{
system("cls");
cout<<"\n\n\t\t\t用户名输入错误超过三次!请按任意键退出.."<<endl;
exit(0);
}
}
fin.close();
return NULL;
}
//********************************************************************
char* CLand::Queryf1(char *fp)
{
int c=0,d=0,_f=0,n=0,flag=0;
char _g[20],tcode[20],tno[20];
ifstream fin(fp);
while(c<=2)
{
strcpy(tno,Settno());
fin.close();
fin.clear();
fin.open("teacher.txt");
if (!fin)
{
cout<<"\n\n\n\n\t\t您的用户名不存在!"<<endl;
cout<<"\t\t您可能是还没有注册,请您先到管理员处注册!"<<endl;
cout<<"\t\t请按任意键继续!";
getch();
system("cls");
handle_Memu1();
}
fin.get();
fin.close();
fin.clear();
fin.open("teacher.txt");
while (!fin.eof())
{
fin>>teacher.m_ctno>>teacher.m_ctname>>teacher.m_ctxi>>
teacher.m_ctsex>>teacher.m_ctzhicheng;
if (strcmp(teacher.m_ctno,tno)==0)
{
flag=1;
strcpy(_g,tno);
while(d<=2)
{
cout<<"\n\t\t\t您的初始密码为您的编号"<<endl;
cout<<"\n\t\t\t请您及时修改您的密码"<<endl;
cout<<"\n\t\t\t请输入您的密码按回车键确认:";
strcpy(tcode,Settcode());
fin.close();
fin.clear();
fin.open("tcode.txt");
if (!fin)
{
if(strcmp(_g,tcode)==0)
{
Writef1("tcode.txt");
handle_Memu4();
}
system("cls");
d++;
cout<<"\n\n\t\t\t密码输入错误!请重新输入!\n"<<endl;
if(d>=3)
{
system("cls");
cout<<"\n\n\t\t\t输入错误密码超过三次!请按任意键退出.."<<endl;
exit(0);
}
strcpy(tcode,Settcode());
}
fin.get();
while (!fin.eof())
{
fin>>teacher.m_ctno>>m_ctcode;
if(strcmp(m_ctcode,tcode)==0||strcmp(_g,tcode)==0)
{
Writef1("tcode.txt");
handle_Memu4();
}
}
system("cls");
d++;
cout<<"\n\n\t\t\t密码输入错误!请重新输入!\n"<<endl;
if(d>=3)
{
system("cls");
cout<<"\n\n\t\t\t输入错误密码超过三次!请按任意键退出.."<<endl;
exit(0);
}
}
break;
}
if(!flag)
{
c++;
system("cls");
cout<<"\n\n\n\n\t\t您的用户名输入错误!"<<endl;
}
if(c>=3)
{
system("cls");
cout<<"\n\n\t\t\t用户名输入错误超过三次!请按任意键退出.."<<endl;
exit(0);
}
}
}
fin.close();
return NULL;
}
//********************************************************************
char* CLand::Queryf2(char *fp)
{
int c=0,d=0,_f=0,n=0,flag=0;
char admin[20],admincode[20];
ifstream fin(fp);
fin.close();
fin.clear();
fin.open("admin.txt");
if (!fin)
{
system("cls");
cout<<"\n\n\n\n\t\t\t欢迎您进入课程管理端\n";
cout<<"\n\t\t\t您的用户名为admin"<<endl;
while(c<=2)
{
strcpy(admin,Setadmin());
if(strcmp("admin",admin)==0)
{
flag=1;
while(d<=2)
{
cout<<"\n\t\t\t您的初始密码为admin"<<endl;
cout<<"\n\t\t\t请您及时修改您的密码"<<endl;
cout<<"\n\t\t\t请输入您的密码并按回车键确认:";
strcpy(admincode,Setadmincode());
if(strcmp("admin",admincode)==0)
{
Writef2("admin.txt");
handle_Memu5();
}
else
{
system("cls");
d++;
cout<<"\n\n\t\t\t密码输入错误!请重新输入!\n"<<endl;
}
if(d>=3)
{
system("cls");
cout<<"\n\n\t\t\t输入错误密码超过三次!请按任意键退出.."<<endl;
exit(0);
}
}
}
if(!flag)
{
c++;
system("cls");
cout<<"\n\n\t\t\t用户名输入错误!请重新输入!\n"<<endl;
}
if(c>=3)
{
system("cls");
cout<<"\n\n\t\t\t用户名输入错误超过三次!请按任意键退出.."<<endl;
exit(0);
}
}
}
fin.get();
while(c<=2)
{
strcpy(admin,Setadmin());
fin.close();
fin.clear();
fin.open("admin.txt");
while (!fin.eof())
{
fin>>m_cadmin>>m_cadmincode;
if (strcmp(m_cadmin,admin)==0)
{
flag=1;
while(d<=2)
{
cout<<"\n\t\t\t您的初始密码为admin"<<endl;
cout<<"\n\t\t\t请你及时修改你的密码"<<endl;
cout<<"\n\t\t\t请输入你的密码并按回车键确认:";
strcpy(admincode,Setadmincode());
ifstream fin(fp);
fin.close();
fin.clear();
fin.open("admin.txt");
if (!fin)
{
cout<<"\n\n\n\n\t\t您的用户名不存在!"<<endl;
exit(0);
}
fin.get();
while (!fin.eof())
{
fin>>m_cadmin>>m_cadmincode;
if(strcmp(m_cadmincode,admincode)==0)
{
handle_Memu5();
}
}
system("cls");
d++;
cout<<"\n\n\t\t\t密码输入错误!请重新输入!\n"<<endl;
if(d>=3)
{
system("cls");
cout<<"\n\n\t\t\t输入错误密码超过三次!请按任意键退出.."<<endl;
exit(0);
}
}
}
}
if(!flag)
{
c++;
system("cls");
cout<<"\n\n\n\n\t\t您的用户名输入错误!"<<endl;
}
if(c>=3)
{
system("cls");
cout<<"\n\n\t\t\t用户名输入错误超过三次!请按任意键退出.."<<endl;
exit(0);
}
}
fin.close();
return NULL;
}
//********************************************************************
void CLand::modifiy(char *fp)
{
char sno[20];
int c=0,d=0,_f=0,n=0,flag=0;
char scode[20];
cout<<"\n\t\t\t请输入你的用户名按回车键确认:";
cin>>sno;
ifstream fin(fp);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -