Skip to content

Commit 107dfa0

Browse files
YiminYimin
authored andcommitted
编写了readme,修复了一些bug。
1 parent 24f7212 commit 107dfa0

6 files changed

Lines changed: 123 additions & 6 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
#作者信息
77
author.txt
8+
#程序运行产生的配置和日志文件
9+
/ATM/records/
10+
/ATM/configs/
811

912
# User-specific files
1013
*.rsuser

ATM/CLI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void CLI::login()
164164
map<string, string> res = myMachine.login(username, password);
165165
if (res["code"] == "0")
166166
{
167-
cout << GREEN <<"欢迎使用" << RESET << endl;
167+
cout << GREEN << "您好," << res["msg"] << "欢迎使用" << RESET << endl;
168168
start("home");
169169
return;
170170
}

ATM/Machine.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ Machine::~Machine()
1717
}
1818

1919
map<string, string> Machine::login(string username, string password)
20-
{
20+
{
21+
//存放结果
2122
map<string, string> res;
23+
//配置
2224
map<string, map<string, string>> config = userCfg.cfgData;
25+
//遍历用户
2326
for (auto& i : config)
2427
{
28+
//如果找到了用户
2529
if (i.first == username)
2630
{
2731
//错误次数
@@ -36,7 +40,8 @@ map<string, string> Machine::login(string username, string password)
3640
is_login = true;
3741
loginRec.remove(username);
3842
res["code"] = "0";
39-
res["msg"] = "用户" + username + "成功登录";
43+
//返回用户姓名
44+
res["msg"] = i.second["name"];
4045
return res;
4146
}
4247
//密码错误
@@ -75,7 +80,13 @@ map<string, string> Machine::withdraw(int value)
7580
res["msg"] = "不是100的整数倍";
7681
return res;
7782
}
78-
else if (value >= 500)
83+
else if (value <= 0)
84+
{
85+
res["code"] = "15";
86+
res["msg"] = "金额不合法";
87+
return res;
88+
}
89+
else if (value >= this->once_limit)
7990
{
8091
res["code"] = "9";
8192
res["msg"] = "超出单次取款限额";
@@ -87,7 +98,7 @@ map<string, string> Machine::withdraw(int value)
8798
res["msg"] = "余额不足";
8899
return res;
89100
}
90-
else if ((withdrawRec.get_amount(current_user) + value) >= 2000)
101+
else if ((withdrawRec.get_amount(current_user) + value) >= this->day_limit)
91102
{
92103
res["code"] = "8";
93104
res["msg"] = "超出单日取款限额";
@@ -118,6 +129,12 @@ map<string, string> Machine::revise_pwd(string old_pwd, string new_pwd)
118129
res["msg"] = "旧密码不正确";
119130
return res;
120131
}
132+
else if (!is_pwd_valid(new_pwd))
133+
{
134+
res["code"] = "12";
135+
res["msg"] = "密码不符合安全策略:6位 数字";
136+
return res;
137+
}
121138
else
122139
{
123140
userCfg.set(current_user, "password", new_pwd);
@@ -215,6 +232,12 @@ map<string, string> Machine::transfer(string target_username, int value)
215232
res["msg"] = "目标用户不存在";
216233
return res;
217234
}
235+
else if (value <= 0)
236+
{
237+
res["code"] = "15";
238+
res["msg"] = "金额不合法";
239+
return res;
240+
}
218241
else if (remain < value)
219242
{
220243
res["code"] = "6";

ATM/Machine.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ using namespace std;
2525
code 12 密码不符合安全策略
2626
code 13 虚假身份证号
2727
code 14 银行卡号不符合要求
28+
code 15 金额不合法
2829
*/
2930
class Machine
3031
{
@@ -69,4 +70,8 @@ class Machine
6970
//身份证号校验位对应的加权因子
7071
const vector<int> verify_sum_vec =
7172
{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
73+
//单日取款限额
74+
const int day_limit = 2000;
75+
//单次取款限额
76+
const int once_limit = 500;
7277
};

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright © 2024 谢宜民
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,78 @@
1-
# ATM
1+
# homework-ATM
2+
控制台模拟ATM自动存取款机。程序设计课程期末实验项目,供大家学习。
3+
4+
## 使用说明
5+
按照提示输入数字并按下 `Enter` 进行操作。
6+
7+
### 注册
8+
需要提供以下信息:
9+
- **银行卡号**(19位数字)
10+
- **身份证号码**(会计算校验位)
11+
- **姓名**
12+
- **密码**(6位数字)
13+
14+
每个初始用户具有 10,000 元初始金额。
15+
16+
### 登录
17+
输入银行卡号和密码。
18+
19+
每个号码**每日连续输入三次错误密码**后将会被锁定。
20+
21+
登录成功后进入[主页](#主页)
22+
23+
### 主页
24+
主界面,提供以下入口:
25+
- [取款](#取款已登录)
26+
- [转账](#转账已登录)
27+
- [余额查询](#余额查询已登录)
28+
- [修改密码](#修改密码已登录)
29+
- 退出登录
30+
31+
### 取款(已登录)
32+
输入取款金额
33+
34+
单次取款限额**500**元,单日取款限额**2000**元。
35+
36+
### 转账(已登录)
37+
输入目标用户的银行卡号和转账金额。
38+
39+
需要二次确认目标用户的银行卡号。
40+
41+
### 余额查询(已登录)
42+
查询当前账户余额。
43+
44+
### 修改密码(已登录)
45+
输入旧密码,并两次确认新密码。
46+
47+
## 注意事项
48+
1. 建议使用最新版 Windows 终端以获得最佳使用体验;
49+
2. 编译时使用 C++ 20 以上的标准;
50+
3. 在可执行文件或源代码所在目录下建立`author.txt`,并在第一行填入作者信息。
51+
52+
## 项目特点
53+
54+
### 模块化
55+
分为多个模块:
56+
- **命令行用户界面(CLI)**
57+
- **后端(Machine)**
58+
- **配置文件管理(ConfigMgr)**
59+
- **操作记录(Recorder)**
60+
61+
### 异步
62+
将CLI成员函数注册为活动,并使用`start`启动活动,异步执行,顺序明确。
63+
64+
## 快速开始
65+
1. 安装 Microsoft Visual Studio;
66+
2. 克隆仓库到本地:
67+
```powershell
68+
git clone https://github.com/XieYimin3/homework-ATM.git
69+
```
70+
3. 使用Visual Studio打开解决方案:
71+
```powershell
72+
cd homework-ATM\ATM
73+
.\ATM.sln
74+
```
75+
3. 编译项目并运行。
76+
77+
## 许可
78+
这个项目使用的许可证类型是 MIT,详见 [LICENSE](./LICENSE) 文件。

0 commit comments

Comments
 (0)