Repository navigation
Expand file tree
/
Copy pathmainFunction.cpp
More file actions
125 lines (111 loc) · 2.47 KB
/
Copy pathmainFunction.cpp
File metadata and controls
125 lines (111 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "mianFunction.h"
void adminMenu(Identity* admin) {
while (true) {
//转换为子类指针
Admin* subAdmin = (Admin*)admin;
//show menu,使用父类指针
subAdmin->openMenu();
//接受用户输入
int select;
cout << "请输入你的选择:" << endl;
cin >> select;
if (select == 1) {//添加账号
cout << "添加账号" << endl;
subAdmin->addPerson();
}
else if (select == 2) {//查看账号
cout << "查看账号" << endl;
subAdmin->showPerson();
}
else if (select == 3) { //查看机房
cout << "查看机房" << endl;
subAdmin->showComputer();
}
else if (select == 4) {//清空预约
cout << "清空预约" << endl;
subAdmin->clearFile();
}
else {//注销登陆
delete admin;
cout << "注销登陆" << endl;
system("pause");
system("cls");
return;
}
}
}
void LogIn(string idengtityFile, int type) {
//读文件
ifstream ifs;//打开文件
ifs.open(idengtityFile, ios::in);
//打开失败
if (!ifs.is_open()) {
cout << "文件不存在" << endl;
ifs.close();
return;
}
//正常打开文件
//接收用户输入信息
string id;
string name;
string password;
cout << "输入你的姓名:" << endl;
cin >> name;
cout << "输入你的密码:" << endl;
cin >> password;
if (type == 1) {//学生
cout << "输入你的学号:" << endl;
cin >> id;
}
else if (type == 2) {//学生
cout << "输入你的职工号:" << endl;
cin >> id;
}
//开始在文件中查找信息和验证登陆
Identity* person = NULL;
if (type == 1) {
//验证学生登陆
string fId, fName, fPassword;
while (ifs >> fId && ifs >> fName && ifs >> fPassword) {
if (fId == id && fName == name && fPassword == password) {
person = new Student(id, name, password);
printMessage("学生验证登陆成功!");
//进入学生子菜单界面
return;
}
}
}
else if (type == 2) {
//验证教师登陆
string fId, fName, fPassword;
while (ifs >> fId && ifs >> fName && ifs >> fPassword) {
if (fId == id && fName == name && fPassword == password) {
person = new Teacher(id, name, password);
printMessage("教师验证登陆成功!");
//进入教师子菜单界面
return;
}
}
}
else if (type == 3) {
//验证管理员登陆
string fName, fPassword;
while (ifs >> fName && ifs >> fPassword) {
if (fName == name && fPassword == password) {
printMessage("管理员验证登陆成功!");
//进入管理员子菜单界面
person = new Admin(name, password);
adminMenu(person);
return;
}
}
}
//验证失败,输出错误信息
printMessage("验证失败!");
return;
}
void printMessage(const string& s) {
cout << s << endl;
system("pause");
system("cls");
}