📄 menu.h
字号:
#include <iostream.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include "CsStuInfo.h"
#include "School.h"
void mypass(char *password)
{
char c;
int i = 0;
while (1) //控制密码输入
{
c = getch();
if (c == 8) //如果是backspace键则回退一个字符
{
if (i == 0) //已经没有字符无需回退
{
continue;
}
cout << '\b' << flush << ' ' << flush << '\b' << flush;
i--; //下标减1
password[i] = '\0'; //保证已输入的密码的最后一位是\0
continue;
}
if (c == 13)
{
break;
}
if ((c>47 && c<58 || c>64 && c<91 || c>96 && c<123) && i<19) //密码只能包含字母和数字
{
cout << '*' << flush;
password[i] = c;
i++;
}
else
{
continue;
}
password[i] = '\0'; //正常输入则在末尾加上结束标志
}
}
void show_menu(char *account, char *password) //主界面即登陆界面
{
cout<<"\n\n\t ☆☆☆☆欢迎进入学籍管理系统☆☆☆☆"<< endl << endl
<< " 学号: ";
cin >> account; //输入学号
cout << " 密码: " << flush;
mypass(password);
}
CsStuInfo *search(char *account, CsStuInfo *head)
{
CsStuInfo *p = head->next;
while (p != NULL)
{
if (strcmp(p->getnumber(), account) == 0)
{
return p;
}
p = p->next;
}
return NULL;
}
int checklogin(char *account, char *password, CsStuInfo *head)
{
if ((strcmp(account, "admin") == 0) && (strcmp(password, "lquterqtd") == 0))
{
return 1; //1管理员成功登录
}
else //非管理员登录
{
CsStuInfo *p;
p = search(account, head); //查找该学生
if (p == NULL)
{
return 2; //2不存在该学生
}
else //该用户存在,比对密码
{
if (strcmp(p->getpassword(), password) == 0)
{
return 3; //3学生成功登录
}
else
{
return 4; //4密码错误
}
}
}
}
void admin_browse(School *mod)
{
char ch, search;
bool temp;
while(1)
{
cout<<"\n\n\t ☆☆☆☆欢迎进入学籍管理系统☆☆☆☆"<< endl << endl;
cout << "\t\t\t1.输入学生信息" << endl
<< "\t\t\t2.显示学生信息" << endl
<< "\t\t\t3.查找学生" << endl
<< "\t\t\t4.删除学生信息" << endl
<< "\t\t\t5.统计学生成绩" << endl
<< "\t\t\t0.退出系统" << endl
<< "\n\t\t\t请选择:" << flush;
ch = getch();
switch(ch)
{
case '1':
system("cls");
mod->input();
cout << "\t\t按任意键返回主菜单..." << flush;
getch();
break;
case '2':
system("cls");
mod->output();
cout << "\t\t按任意键返回主菜单..." << flush;
getch();
break;
case '3':
system("cls");
mod->search_stu();
temp = true;
while (temp)
{
cout << "\n\t\t1.继续查询 2.返回主菜单\n\t\t" << flush;
search = getch();
switch(search)
{
case '1':
system("cls");
mod->search_stu();
break;
case '2':
system("cls");
temp = false;
break;
default:
break;
}
}
break;
case '4':
system("cls");
mod->delete_stu_info();
cout << "\n\t\t按任意键返回主菜单..." << flush;
getch();
break;
case '5':
system("cls");
mod->calc_stu_score();
cout << "\t\t按任意键返回主菜单..." << flush;
getch();
break;
case '0':
mod->save_info();
mod->save_total();
cout << "0\n\t\t" << flush;
system("cls");
cout << "\n\n\t\t信息已保存,可正常退出..." << endl;
exit(0);
break;
default:
system("cls");
break;
}//end of switch
system("cls");
}//end of while
}
void stu_browse(CsStuInfo *p, School *mod) //参数指针p指向存放该学生个人信息的结点
{
char ch;
while (1)
{
cout<<"\n\n\t ☆☆☆☆欢迎进入学籍管理系统☆☆☆☆"<< endl << endl;
cout << "\t\t\t1.查询个人信息" << endl
<< "\t\t\t2.学期成绩查询" << endl
<< "\t\t\t3.修改密码" << endl
<< "\t\t\t0.退出系统" << endl
<< "\n\t\t\t请选择:" << flush;
ch = getch();
switch(ch)
{
case '1':
system("cls");
p->output_info();
cout << "\n\t\t按任意键返回主菜单..." << flush;
getch();
system("cls");
break;
case '2':
system("cls");
p->output_score();
cout << "\n\t\t按任意键返回主菜单..." << flush;
getch();
system("cls");
break;
case '3':
system("cls");
p->reset_password();
mod->save_info();
cout << "\n\t\t按任意键返回主菜单..." << flush;
getch();
system("cls");
break;
case '0':
cout << "0\n\t\t" << flush;
system("cls");
cout << "\n\n\t\t信息已保存,可正常退出..." << endl;
exit(0);
break;
default:
system("cls");
break;
}//end of switch
system("cls");
}//end of while
}
void login_1(School *mod)
{
system("cls");
admin_browse(mod);
}
void login_2()
{
system("cls");
cout << "\t\t\t访学生不存在,请与管理员联系" << endl;
}
void login_3(char *account, CsStuInfo *head, School *mod)
{
system("cls");
CsStuInfo *p = search(account, head);
stu_browse(p, mod);
}
void login_4()
{
system("cls");
cout << "\t\t\t密码错误,请重新登录!" << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -