Compare commits
6
Commits
1.0
...
772b417cb2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
772b417cb2 | ||
|
|
f4737c82f6 | ||
|
|
93e0214536 | ||
|
|
74e467e111 | ||
|
|
7d623c1993 | ||
|
|
ae99d48eda |
@@ -0,0 +1,5 @@
|
|||||||
|
*.o
|
||||||
|
*.exe
|
||||||
|
bank.dat
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/tasks.json
|
||||||
@@ -1,135 +1,140 @@
|
|||||||
# 简易银行账户管理系统
|
# 简易银行账户管理系统
|
||||||
|
|
||||||
## 项目简介
|
## 项目简介
|
||||||
这是一个基于C语言开发的简易银行账户管理系统,支持基本的银行账户操作功能,包括开户、登录、存款、取款、查询余额、账户管理等。系统采用模块化设计,代码结构清晰,易于维护和扩展。
|
这是一个基于C语言开发的简易银行账户管理系统,支持基本的银行账户操作功能,包括开户、登录、存款、取款、查询余额、账户管理等。系统采用模块化设计,代码结构清晰,易于维护和扩展。
|
||||||
|
|
||||||
## 功能特性
|
## 功能特性
|
||||||
- **账户管理**
|
- **账户管理**
|
||||||
- 创建普通用户账户(权限2)
|
- 创建普通用户账户(权限2)
|
||||||
- 创建管理员账户(权限1)
|
- 创建管理员账户(权限1)
|
||||||
- 删除账户(仅管理员可操作)
|
- 删除账户(仅管理员可操作)
|
||||||
- 修改密码
|
- 修改密码
|
||||||
- **账户操作**
|
- **账户操作**
|
||||||
- 存款
|
- 存款
|
||||||
- 取款
|
- 取款
|
||||||
- 查询余额
|
- 查询余额
|
||||||
- **系统功能**
|
- **系统功能**
|
||||||
- 用户登录验证
|
- 用户登录验证
|
||||||
- 权限分级(管理员/普通用户)
|
- 权限分级(管理员/普通用户)
|
||||||
- 数据持久化(自动保存到文件)
|
- 数据持久化(自动保存到文件)
|
||||||
- 自动初始化默认管理员账户
|
- 交易流水查询(管理员)
|
||||||
|
- 自动初始化默认管理员账户
|
||||||
## 系统架构
|
|
||||||
### 核心模块
|
## 系统架构
|
||||||
1. **主程序 (bank.c)**
|
### 核心模块
|
||||||
- 程序入口点
|
1. **主程序 (bank.c)**
|
||||||
- 菜单显示和用户交互
|
- 程序入口点
|
||||||
- 权限控制逻辑
|
- 菜单显示和用户交互
|
||||||
|
- 权限控制逻辑
|
||||||
2. **账户管理 (account.c)**
|
|
||||||
- 账户创建、删除
|
2. **账户管理 (account.c)**
|
||||||
- 账户查找
|
- 账户创建、删除
|
||||||
- 登录验证
|
- 账户查找
|
||||||
- 密码修改
|
- 登录验证
|
||||||
- 显示所有账户信息
|
- 密码修改
|
||||||
|
- 显示所有账户信息
|
||||||
3. **交易处理 (transaction.c)**
|
|
||||||
- 存款功能
|
3. **交易处理 (transaction.c)**
|
||||||
- 取款功能
|
- 存款功能
|
||||||
- 余额查询
|
- 取款功能
|
||||||
|
- 余额查询
|
||||||
4. **数据持久化 (file_io.c)**
|
|
||||||
- 数据保存到文件(bank.dat)
|
4. **数据持久化 (file_io.c)**
|
||||||
- 从文件加载数据
|
- 数据保存到文件(bank.dat)
|
||||||
- 初始化默认管理员账户
|
- 从文件加载数据
|
||||||
|
- 初始化默认管理员账户
|
||||||
5. **工具函数 (utils.c)**
|
|
||||||
- 输入验证和清理
|
5. **工具函数 (utils.c)**
|
||||||
- 安全的整数和浮点数输入
|
- 输入验证和清理
|
||||||
|
- 安全的整数和浮点数输入
|
||||||
6. **头文件 (bank.h)**
|
|
||||||
- 全局常量定义
|
6. **头文件 (bank.h)**
|
||||||
- 账户结构体定义
|
- 全局常量定义
|
||||||
- 函数声明
|
- 账户结构体定义
|
||||||
|
- 函数声明
|
||||||
### 数据结构
|
|
||||||
```c
|
7. **日志模块(log.c)**
|
||||||
typedef struct strAccount
|
- 日志记录和存储(循环链表)
|
||||||
{
|
|
||||||
int id; // 账户ID(从1000开始)
|
### 数据结构
|
||||||
char name[31]; // 姓名(最多30字符)
|
```c
|
||||||
double balance; // 账户余额
|
typedef struct strAccount
|
||||||
int password; // 6位数字密码
|
{
|
||||||
int quanxian; // 权限(1=管理员,2=普通用户)
|
int id; // 账户ID(从1000开始)
|
||||||
} STACCOUNT;
|
char name[31]; // 姓名(最多30字符)
|
||||||
```
|
double balance; // 账户余额
|
||||||
|
int password; // 6位数字密码
|
||||||
## 使用说明
|
int quanxian; // 权限(1=管理员,2=普通用户)
|
||||||
### 编译
|
} STACCOUNT;
|
||||||
```bash
|
```
|
||||||
gcc bank.c account.c transaction.c file_io.c utils.c -o bank_system
|
|
||||||
```
|
## 使用说明
|
||||||
|
### 编译
|
||||||
### 运行
|
```bash
|
||||||
```bash
|
gcc bank.c account.c transaction.c file_io.c utils.c -o bank_system
|
||||||
./bank_system
|
```
|
||||||
```
|
|
||||||
|
### 运行
|
||||||
### 操作流程
|
```bash
|
||||||
1. **初始界面**(未登录状态)
|
./bank_system
|
||||||
- 选项1:开户(创建普通用户账户)
|
```
|
||||||
- 选项2:登录
|
|
||||||
- 选项0:退出系统
|
### 操作流程
|
||||||
|
1. **初始界面**(未登录状态)
|
||||||
2. **普通用户界面**(登录后)
|
- 选项1:开户(创建普通用户账户)
|
||||||
- 选项1:存款
|
- 选项2:登录
|
||||||
- 选项2:取款
|
- 选项0:退出系统
|
||||||
- 选项3:查询余额
|
|
||||||
- 选项0:退出账户
|
2. **普通用户界面**(登录后)
|
||||||
|
- 选项1:存款
|
||||||
3. **管理员界面**(登录后)
|
- 选项2:取款
|
||||||
- 选项1:存款
|
- 选项3:查询余额
|
||||||
- 选项2:取款
|
- 选项0:退出账户
|
||||||
- 选项3:查询余额
|
|
||||||
- 选项4:显示所有账户
|
3. **管理员界面**(登录后)
|
||||||
- 选项5:删除账户
|
- 选项1:存款
|
||||||
- 选项6:创建管理员账户
|
- 选项2:取款
|
||||||
- 选项0:退出账户
|
- 选项3:查询余额
|
||||||
|
- 选项4:显示所有账户
|
||||||
### 默认账户
|
- 选项5:删除账户
|
||||||
系统首次运行时会自动创建一个默认管理员账户:
|
- 选项6:创建管理员账户
|
||||||
- **账户ID**: 1000
|
- 选项7:查看交易流水
|
||||||
- **姓名**: admin
|
- 选项0:退出账户
|
||||||
- **密码**: 123456
|
|
||||||
- **权限**: 管理员
|
### 默认账户
|
||||||
|
系统首次运行时会自动创建一个默认管理员账户:
|
||||||
## 技术细节
|
- **账户ID**: 1000
|
||||||
- **最大账户数量**: 50个
|
- **姓名**: admin
|
||||||
- **密码规则**: 6位数字(100000-999999)
|
- **密码**: 123456
|
||||||
- **数据存储**: 二进制文件(bank.dat)
|
- **权限**: 管理员
|
||||||
- **输入验证**: 所有数值输入都包含错误处理
|
|
||||||
- **内存管理**: 使用全局数组存储账户数据
|
## 技术细节
|
||||||
|
- **最大账户数量**: 50个
|
||||||
## 文件说明
|
- **密码规则**: 6位数字(100000-999999)
|
||||||
- `bank.c` - 主程序文件
|
- **数据存储**: 二进制文件(bank.dat)
|
||||||
- `account.c` - 账户管理功能实现
|
- **输入验证**: 所有数值输入都包含错误处理
|
||||||
- `transaction.c` - 交易处理功能实现
|
- **内存管理**: 使用全局数组存储账户数据
|
||||||
- `file_io.c` - 文件读写功能实现
|
|
||||||
- `utils.c` - 工具函数实现
|
## 文件说明
|
||||||
- `bank.h` - 头文件,包含结构体定义和函数声明
|
- `bank.c` - 主程序文件
|
||||||
- `bank.dat` - 数据存储文件(运行时自动生成)
|
- `account.c` - 账户管理功能实现
|
||||||
|
- `transaction.c` - 交易处理功能实现
|
||||||
## 注意事项
|
- `file_io.c` - 文件读写功能实现
|
||||||
1. 密码必须为6位数字
|
- `utils.c` - 工具函数实现
|
||||||
2. 存款和取款金额必须为正数
|
- `bank.h` - 头文件,包含结构体定义和函数声明
|
||||||
3. 取款时会检查账户余额是否充足
|
- `bank.dat` - 数据存储文件(运行时自动生成)
|
||||||
4. 删除账户功能仅管理员可用
|
|
||||||
5. 系统会自动保存所有操作到文件,确保数据持久化
|
## 注意事项
|
||||||
|
1. 密码必须为6位数字
|
||||||
## 扩展建议
|
2. 存款和取款金额必须为正数
|
||||||
- 添加交易记录功能
|
3. 取款时会检查账户余额是否充足
|
||||||
- 实现账户排序和搜索
|
4. 删除账户功能仅管理员可用
|
||||||
- 增加更多权限级别
|
5. 系统会自动保存所有操作到文件,确保数据持久化
|
||||||
- 改进用户界面(如使用图形界面)
|
|
||||||
- 添加数据加密功能
|
## 扩展建议
|
||||||
|
- ~~添加交易记录功能~~
|
||||||
|
- 实现账户排序和搜索
|
||||||
|
- 增加更多权限级别
|
||||||
|
- 改进用户界面(如使用图形界面)
|
||||||
|
- 添加数据加密功能
|
||||||
- 实现多用户并发访问
|
- 实现多用户并发访问
|
||||||
@@ -6,15 +6,15 @@
|
|||||||
extern STACCOUNT g_astAccounts[];
|
extern STACCOUNT g_astAccounts[];
|
||||||
extern int g_iAccCount;
|
extern int g_iAccCount;
|
||||||
|
|
||||||
/* 函数功能:处理用户的创建账户操作
|
/* 函数功能:处理用户的创建账户操作
|
||||||
思考处理步骤,写到函数体内注释
|
思考处理步骤,写到函数体内注释
|
||||||
* 参数:无
|
* 参数:无
|
||||||
* 存款信息要写入全局变量g_astAccounts中
|
* 存款信息要写入全局变量g_astAccounts中
|
||||||
* 返回值:无
|
* 返回值:无
|
||||||
* 存款失败怎么处理?
|
* 存款失败怎么处理?
|
||||||
*/
|
*/
|
||||||
void InitAdminAccount() {
|
void InitAdminAccount() {
|
||||||
printf("初始化默认管理员账户");
|
printf("初始化默认管理员账户");
|
||||||
g_astAccounts[0].id = 1000;
|
g_astAccounts[0].id = 1000;
|
||||||
strcpy(g_astAccounts[0].name, "admin");
|
strcpy(g_astAccounts[0].name, "admin");
|
||||||
g_astAccounts[0].balance = 0.0;
|
g_astAccounts[0].balance = 0.0;
|
||||||
@@ -25,73 +25,73 @@ void InitAdminAccount() {
|
|||||||
|
|
||||||
void CreateAccount(int quanxian)
|
void CreateAccount(int quanxian)
|
||||||
{
|
{
|
||||||
// (1)合法性检查
|
// (1)合法性检查
|
||||||
if(MAX_ACCOUNTS < g_iAccCount)
|
if(MAX_ACCOUNTS < g_iAccCount)
|
||||||
{
|
{
|
||||||
printf("账户数量已达上限!\n");
|
printf("账户数量已达上限!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// (2)定义局部变量(函数内使用的变量)
|
// (2)定义局部变量(函数内使用的变量)
|
||||||
STACCOUNT stNewAcc; //账户变量,结构体变量定义
|
STACCOUNT stNewAcc; //账户变量,结构体变量定义
|
||||||
//char cInput[NAME_LEN]; //接输入的名字字符串
|
//char cInput[NAME_LEN]; //接输入的名字字符串
|
||||||
|
|
||||||
// (3)功能实现
|
// (3)功能实现
|
||||||
printf("请输入姓名(最多30个字符): ");
|
printf("请输入姓名(最多30个字符): ");
|
||||||
|
|
||||||
//这里有风险,怎么改进?
|
//这里有风险,怎么改进?
|
||||||
scanf("%30s", stNewAcc.name);
|
scanf("%30s", stNewAcc.name);
|
||||||
//stNewAcc.name[NAME_LEN - 1] = '\0'; // 确保null终止
|
//stNewAcc.name[NAME_LEN - 1] = '\0'; // 确保null终止
|
||||||
//输密码
|
//输密码
|
||||||
int temp_password;
|
int temp_password;
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("请输入密码\n");
|
printf("请输入密码\n");
|
||||||
scanf("%d",&temp_password);
|
scanf("%d",&temp_password);
|
||||||
if (99999<temp_password&&temp_password<999999) {
|
if (99999<temp_password&&temp_password<999999) {
|
||||||
printf("设置成功\n");
|
printf("设置成功\n");
|
||||||
stNewAcc.password=temp_password;
|
stNewAcc.password=temp_password;
|
||||||
SaveData();
|
SaveData();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printf("密码不符合规范!请重新输入\n");
|
printf("密码不符合规范!请重新输入\n");
|
||||||
}
|
}
|
||||||
//需求中要求账户ID从1000开始,初始化账户余额
|
//需求中要求账户ID从1000开始,初始化账户余额
|
||||||
stNewAcc.id = 1000 + g_iAccCount;
|
stNewAcc.id = 1000 + g_iAccCount;
|
||||||
stNewAcc.balance = 0.0;
|
stNewAcc.balance = 0.0;
|
||||||
stNewAcc.quanxian = quanxian;
|
stNewAcc.quanxian = quanxian;
|
||||||
g_astAccounts[g_iAccCount] = stNewAcc;
|
g_astAccounts[g_iAccCount] = stNewAcc;
|
||||||
|
|
||||||
//把记录账户数量的全局变量自增。加过之后自增,所以下标0占用,数量是1个
|
//把记录账户数量的全局变量自增。加过之后自增,所以下标0占用,数量是1个
|
||||||
g_iAccCount++;
|
g_iAccCount++;
|
||||||
|
|
||||||
printf("开户成功! 账户ID: %d\n", stNewAcc.id);
|
printf("开户成功! 账户ID: %d\n", stNewAcc.id);
|
||||||
SaveData();
|
SaveData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 函数功能:处理用户的显示所有用户信息的操作
|
/* 函数功能:处理用户的显示所有用户信息的操作
|
||||||
思考处理步骤,写到函数体内注释
|
思考处理步骤,写到函数体内注释
|
||||||
* 参数:无
|
* 参数:无
|
||||||
* 从全局变量g_astAccounts中取信息,并显示
|
* 从全局变量g_astAccounts中取信息,并显示
|
||||||
* 返回值:无
|
* 返回值:无
|
||||||
* 存款失败怎么处理?
|
* 存款失败怎么处理?
|
||||||
*/
|
*/
|
||||||
void ShowAccounts()
|
void ShowAccounts()
|
||||||
{
|
{
|
||||||
//(1)输出用户内容提示
|
//(1)输出用户内容提示
|
||||||
printf("\n所有账户信息:\n");
|
printf("\n所有账户信息:\n");
|
||||||
|
|
||||||
//(2)检查是否有账户了?异常情况无账户的处理
|
//(2)检查是否有账户了?异常情况无账户的处理
|
||||||
if (0 == g_iAccCount)
|
if (0 == g_iAccCount)
|
||||||
{
|
{
|
||||||
printf("暂无账户信息\n");
|
printf("暂无账户信息\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//(3)打印表头
|
//(3)打印表头
|
||||||
printf("%-8s %-30s %-10s %-3s\n", "ID", "姓名", "余额","权限");
|
printf("%-8s %-30s %-10s %-3s\n", "ID", "姓名", "余额","权限");
|
||||||
printf("------------------------------------------------------\n");
|
printf("------------------------------------------------------\n");
|
||||||
|
|
||||||
//(4)循环打印每一行
|
//(4)循环打印每一行
|
||||||
for(int i = 0; i < g_iAccCount; i++)
|
for(int i = 0; i < g_iAccCount; i++)
|
||||||
{
|
{
|
||||||
printf("%-8d %-30s %-10.2f %-10d\n",
|
printf("%-8d %-30s %-10.2f %-10d\n",
|
||||||
@@ -99,37 +99,37 @@ void ShowAccounts()
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//登录账户,返回权限
|
//登录账户,返回权限
|
||||||
int LoginAccount(int temp_id) {
|
int LoginAccount(int temp_id) {
|
||||||
int temp_password;
|
int temp_password;
|
||||||
if (FindAccount(temp_id)==-1) {
|
if (FindAccount(temp_id)==-1) {
|
||||||
printf("没有找到账户\n");
|
printf("没有找到账户\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("请输入密码");
|
printf("请输入密码");
|
||||||
scanf("%d", &temp_password);
|
scanf("%d", &temp_password);
|
||||||
if (g_astAccounts[FindAccount(temp_id)].password==temp_password) {
|
if (g_astAccounts[FindAccount(temp_id)].password==temp_password) {
|
||||||
printf("欢迎用户%s \n",g_astAccounts[FindAccount(temp_id)].name);
|
printf("欢迎用户%s \n",g_astAccounts[FindAccount(temp_id)].name);
|
||||||
if (g_astAccounts[FindAccount(temp_id)].quanxian==1) {
|
if (g_astAccounts[FindAccount(temp_id)].quanxian==1) {
|
||||||
printf("您目前以管理员身份登录");
|
printf("您目前以管理员身份登录");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {return 2;}
|
else {return 2;}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("密码错误,请重新输入\n");
|
printf("密码错误,请重新输入\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 函数功能:根据输入的用户ID找到
|
/* 函数功能:根据输入的用户ID找到
|
||||||
思考处理步骤,写到函数体内注释
|
思考处理步骤,写到函数体内注释
|
||||||
* 参数:无
|
* 参数:无
|
||||||
* 用户ID跟数组ID
|
* 用户ID跟数组ID
|
||||||
* 返回值:无
|
* 返回值:无
|
||||||
* 存款失败怎么处理?
|
* 存款失败怎么处理?
|
||||||
*/
|
*/
|
||||||
int FindAccount(int id)
|
int FindAccount(int id)
|
||||||
{
|
{
|
||||||
@@ -140,15 +140,15 @@ int FindAccount(int id)
|
|||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
//删除账户
|
//删除账户
|
||||||
void DeleteAccount(int id) {
|
void DeleteAccount(int id) {
|
||||||
printf("正在删除\n");
|
printf("正在删除\n");
|
||||||
int i=FindAccount(id);
|
int i=FindAccount(id);
|
||||||
if (i==-1) {
|
if (i==-1) {
|
||||||
printf("有这个账户吗你就删");
|
printf("有这个账户吗你就删");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("正在删除一下账户...");
|
printf("正在删除一下账户...");
|
||||||
printf("%-8d %-30s %-10.2f %-3d\n",
|
printf("%-8d %-30s %-10.2f %-3d\n",
|
||||||
g_astAccounts[i].id, g_astAccounts[i].name, g_astAccounts[i].balance,g_astAccounts[i].quanxian);
|
g_astAccounts[i].id, g_astAccounts[i].name, g_astAccounts[i].balance,g_astAccounts[i].quanxian);
|
||||||
for (; i < g_iAccCount-i; i++)
|
for (; i < g_iAccCount-i; i++)
|
||||||
@@ -162,24 +162,24 @@ void DeleteAccount(int id) {
|
|||||||
void ChangePassword(int id) {
|
void ChangePassword(int id) {
|
||||||
int temp_password;
|
int temp_password;
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("请输入原密码");
|
printf("请输入原密码");
|
||||||
scanf("%d",&temp_password);
|
scanf("%d",&temp_password);
|
||||||
if (g_astAccounts[FindAccount(id)].password==temp_password) {
|
if (g_astAccounts[FindAccount(id)].password==temp_password) {
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("请输入新密码\n");
|
printf("请输入新密码\n");
|
||||||
scanf("%d",&temp_password);
|
scanf("%d",&temp_password);
|
||||||
if (99999<temp_password&&temp_password<999999) {
|
if (99999<temp_password&&temp_password<999999) {
|
||||||
printf("修改成功\n");
|
printf("修改成功\n");
|
||||||
g_astAccounts[FindAccount(id)].password=temp_password;
|
g_astAccounts[FindAccount(id)].password=temp_password;
|
||||||
SaveData();
|
SaveData();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printf("密码不符合规范!请重新输入\n");
|
printf("密码不符合规范!请重新输入\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("密码错误,请重新输入");
|
printf("密码错误,请重新输入");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "bank.h"
|
#include "bank.h"
|
||||||
|
LogQueue g_logQueue; // <-- 新增:定义全局日志队列
|
||||||
STACCOUNT g_astAccounts[MAX_ACCOUNTS];
|
STACCOUNT g_astAccounts[MAX_ACCOUNTS];
|
||||||
|
|
||||||
int g_iAccCount = 1;
|
int g_iAccCount = 1;
|
||||||
@@ -12,53 +12,54 @@ int d_id;
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
LoadData();
|
LoadData();
|
||||||
//(1)导入数据
|
//(1)导入数据
|
||||||
// which fuction?
|
// which fuction?
|
||||||
|
|
||||||
//应该先导入数据再欢迎?还是欢迎了再导入数据?
|
//应该先导入数据再欢迎?还是欢迎了再导入数据?
|
||||||
printf("=== 简易银行账户管理系统 ===\n");
|
printf("=== 简易银行账户管理系统 ===\n");
|
||||||
printf("欢迎使用! 系统已加载%d个账户\n", g_iAccCount);
|
printf("欢迎使用! 系统已加载%d个账户\n", g_iAccCount);
|
||||||
InitAdminAccount();//初始化管理员账号
|
InitAdminAccount();//初始化管理员账号
|
||||||
int iChoice=-1; //选择标志
|
InitLogQueue();
|
||||||
|
int iChoice=-1; //选择标志
|
||||||
int pChoice=-1;
|
int pChoice=-1;
|
||||||
while (1) {
|
while (1) {
|
||||||
//持续显示菜单的秘诀
|
//持续显示菜单的秘诀
|
||||||
//(2)显示主菜单,并且处理用户的选择
|
//(2)显示主菜单,并且处理用户的选择
|
||||||
if (quanxian==-2){break;}
|
if (quanxian==-2){break;}
|
||||||
printf("\n=== 简易银行账户管理系统 ===\n");
|
printf("\n=== 简易银行账户管理系统 ===\n");
|
||||||
switch(quanxian) {
|
switch(quanxian) {
|
||||||
case 0:
|
case 0:
|
||||||
printf("1. 开户\n2. 登录 \n0. 退出\n");
|
printf("1. 开户\n2. 登录 \n0. 退出\n");
|
||||||
//printf("1. 开户\n2. 存款\n3. 取款\n4. 查询\n5. 显示所有账户\n6. 退出\n");
|
//printf("1. 开户\n2. 存款\n3. 取款\n4. 查询\n5. 显示所有账户\n6. 退出\n");
|
||||||
printf("请选择: ");
|
printf("请选择: ");
|
||||||
iChoice=-1;
|
iChoice=-1;
|
||||||
scanf("%d", &iChoice);
|
scanf("%d", &iChoice);
|
||||||
switch(iChoice) {
|
switch(iChoice) {
|
||||||
case 1://CREATE
|
case 1://CREATE
|
||||||
//调用创建账号的函数
|
//调用创建账号的函数
|
||||||
CreateAccount(2);
|
CreateAccount(2);
|
||||||
quanxian=0;
|
quanxian=0;
|
||||||
break;
|
break;
|
||||||
case 2://LOGIN
|
case 2://LOGIN
|
||||||
printf("请输入账户id");
|
printf("请输入账户id");
|
||||||
scanf("%d", &user_id);
|
scanf("%d", &user_id);
|
||||||
quanxian=LoginAccount(user_id);
|
quanxian=LoginAccount(user_id);
|
||||||
break;
|
break;
|
||||||
case 0://EXIT
|
case 0://EXIT
|
||||||
printf("谢谢使用!\n按任意键退出\n");
|
printf("谢谢使用!\n按任意键退出\n");
|
||||||
getchar();
|
getchar();
|
||||||
quanxian=-2;
|
quanxian=-2;
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
//还要实现哪些菜单吗?
|
//还要实现哪些菜单吗?
|
||||||
//如果要做排序展示,要做什么?
|
//如果要做排序展示,要做什么?
|
||||||
default: //好的编码习惯,对无效值做处理
|
default: //好的编码习惯,对无效值做处理
|
||||||
printf("无效选择!\n");
|
printf("无效选择!\n");
|
||||||
break; //好的编码加上break,万一default挪了个位置呢?
|
break; //好的编码加上break,万一default挪了个位置呢?
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
printf("1. 存款\n2. 取款\n3. 查询\n4. 显示所有账户\n5. 删除账户\n6. 创建管理员账户\n0. 退出账户");
|
printf("1. 存款\n2. 取款\n3. 查询\n4. 显示所有账户\n5. 删除账户\n6. 创建管理员账户\n7.查看交易\n日志0. 退出账户");
|
||||||
pChoice=-1;
|
pChoice=-1;
|
||||||
scanf("%d", &pChoice);
|
scanf("%d", &pChoice);
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ int main(void)
|
|||||||
ShowAccounts();
|
ShowAccounts();
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
printf("请输入要删除的id");
|
printf("请输入要删除的id");
|
||||||
scanf("%d", &d_id);
|
scanf("%d", &d_id);
|
||||||
DeleteAccount(d_id);
|
DeleteAccount(d_id);
|
||||||
g_iAccCount--;
|
g_iAccCount--;
|
||||||
@@ -84,20 +85,23 @@ int main(void)
|
|||||||
case 6:
|
case 6:
|
||||||
CreateAccount(1);
|
CreateAccount(1);
|
||||||
break;
|
break;
|
||||||
|
case 7:
|
||||||
|
ShowTransactionLogs();
|
||||||
|
break;
|
||||||
case 0://EXIT
|
case 0://EXIT
|
||||||
printf("谢谢使用!\n按任意键退出");
|
printf("谢谢使用!\n按任意键退出");
|
||||||
getchar();
|
getchar();
|
||||||
quanxian=-2;
|
quanxian=-2;
|
||||||
//还要实现哪些菜单吗?
|
//还要实现哪些菜单吗?
|
||||||
//如果要做排序展示,要做什么?
|
//如果要做排序展示,要做什么?
|
||||||
default: //好的编码习惯,对无效值做处理
|
default: //好的编码习惯,对无效值做处理
|
||||||
printf("无效选择!\n");
|
printf("无效选择!\n");
|
||||||
break; //好的编码加上break,万一default挪了个位置呢?
|
break; //好的编码加上break,万一default挪了个位置呢?
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
printf("1. 存款\n2. 取款\n3. 查询\n0.退出账户");
|
printf("1. 存款\n2. 取款\n3. 查询\n0.退出账户");
|
||||||
pChoice=-1;
|
pChoice=-1;
|
||||||
scanf("%d", &pChoice);
|
scanf("%d", &pChoice);
|
||||||
switch(pChoice) {
|
switch(pChoice) {
|
||||||
@@ -111,22 +115,22 @@ int main(void)
|
|||||||
QueryBalance(user_id);
|
QueryBalance(user_id);
|
||||||
break;
|
break;
|
||||||
case 0://EXIT
|
case 0://EXIT
|
||||||
printf("谢谢使用!\n按任意键退出");
|
printf("谢谢使用!\n按任意键退出");
|
||||||
getchar();
|
getchar();
|
||||||
quanxian=-2;
|
quanxian=-2;
|
||||||
break;
|
break;
|
||||||
//还要实现哪些菜单吗?
|
//还要实现哪些菜单吗?
|
||||||
//如果要做排序展示,要做什么?
|
//如果要做排序展示,要做什么?
|
||||||
default: //好的编码习惯,对无效值做处理
|
default: //好的编码习惯,对无效值做处理
|
||||||
printf("无效选择!\n");
|
printf("无效选择!\n");
|
||||||
break; //好的编码加上break,万一default挪了个位置呢?
|
break; //好的编码加上break,万一default挪了个位置呢?
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//(3)调用保存数据的函数
|
//(3)调用保存数据的函数
|
||||||
// which fuction?
|
// which fuction?
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#ifndef BANK_H
|
#ifndef BANK_H
|
||||||
#define BANK_H
|
#define BANK_H
|
||||||
|
#define MAX_LOGS 100 // 日志队列最大容量,防止无限增长
|
||||||
|
#define MAX_ACCOUNTS 50 //系统规格为50个账户
|
||||||
|
#define NAME_LEN 31 //用户名字最长30字符,因此需要多1个字符串结束符
|
||||||
|
|
||||||
#define MAX_ACCOUNTS 50 //系统规格为50个账户
|
// 账户信息,每个账户id对应了名字、账户余额等信息,是不是用数据结构定义比较合适?
|
||||||
#define NAME_LEN 31 //用户名字最长30字符,因此需要多1个字符串结束符
|
|
||||||
|
|
||||||
// 账户信息,每个账户id对应了名字、账户余额等信息,是不是用数据结构定义比较合适?
|
|
||||||
typedef struct strAccount
|
typedef struct strAccount
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
@@ -16,39 +16,65 @@ typedef struct strAccount
|
|||||||
|
|
||||||
// strAccount STACCOUNT;
|
// strAccount STACCOUNT;
|
||||||
|
|
||||||
// 函数声明,main函数中调用的各模块函数需要在程序公用的.h中声明
|
// 函数声明,main函数中调用的各模块函数需要在程序公用的.h中声明
|
||||||
// 公开出来被其他模块调用的函数,也应该在公用的.h中声明
|
// 公开出来被其他模块调用的函数,也应该在公用的.h中声明
|
||||||
|
|
||||||
//创建账户的函数
|
//创建账户的函数
|
||||||
void CreateAccount(int quanxian);
|
void CreateAccount(int quanxian);
|
||||||
|
|
||||||
//实现存款的函数
|
//实现存款的函数
|
||||||
void Deposit(int id);
|
void Deposit(int id);
|
||||||
|
|
||||||
//实现取款的函数
|
//实现取款的函数
|
||||||
void Withdraw(int id);
|
void Withdraw(int id);
|
||||||
|
|
||||||
//查询余额的函数
|
//查询余额的函数
|
||||||
void QueryBalance(int id);
|
void QueryBalance(int id);
|
||||||
|
|
||||||
//显示全部账户的函数
|
//显示全部账户的函数
|
||||||
void ShowAccounts();
|
void ShowAccounts();
|
||||||
|
|
||||||
//数据持久化函数
|
//数据持久化函数
|
||||||
void SaveData();
|
void SaveData();
|
||||||
|
|
||||||
//加载数据的函数
|
//加载数据的函数
|
||||||
void LoadData();
|
void LoadData();
|
||||||
|
|
||||||
//根据ID查找账户数组id的函数
|
//根据ID查找账户数组id的函数
|
||||||
int FindAccount(int iD);
|
int FindAccount(int iD);
|
||||||
|
|
||||||
//登录函数,返回用户权限
|
//登录函数,返回用户权限
|
||||||
int LoginAccount(int temp_id);
|
int LoginAccount(int temp_id);
|
||||||
|
|
||||||
//销户
|
//销户
|
||||||
void DeleteAccount(int id);
|
void DeleteAccount(int id);
|
||||||
|
|
||||||
void InitAdminAccount();
|
void InitAdminAccount();
|
||||||
|
|
||||||
|
// 日志条目结构
|
||||||
|
typedef struct {
|
||||||
|
int account_id; // 涉及的账户ID
|
||||||
|
char type[10]; // 操作类型: "Deposit" 或 "Withdraw"
|
||||||
|
double amount; // 交易金额
|
||||||
|
double balance; // 交易后的余额
|
||||||
|
char timestamp[20]; // 时间戳 (格式: YYYY-MM-DD HH:MM:SS)
|
||||||
|
char location[50]; // 地点信息
|
||||||
|
} LogEntry;
|
||||||
|
|
||||||
|
// 环形队列结构
|
||||||
|
typedef struct {
|
||||||
|
LogEntry logs[MAX_LOGS];
|
||||||
|
int front; // 队头指针
|
||||||
|
int rear; // 队尾指针
|
||||||
|
} LogQueue;
|
||||||
|
|
||||||
|
// 全局日志队列变量 (在 bank.c 中定义,在其他文件中 extern 引用)
|
||||||
|
extern LogQueue g_logQueue;
|
||||||
|
|
||||||
|
// 日志函数声明
|
||||||
|
void InitLogQueue(); // 初始化队列
|
||||||
|
int IsLogQueueFull(); // 检查队列是否满
|
||||||
|
int IsLogQueueEmpty(); // 检查队列是否空
|
||||||
|
int EnqueueLog(int id, const char* type, double amt, double bal); // 入队
|
||||||
|
void ShowTransactionLogs(); // 显示所有日志
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "bank.h"
|
||||||
|
#include <io.h>
|
||||||
|
|
||||||
|
#define FILE_NAME bank.bat
|
||||||
|
|
||||||
|
//要操作的全局变量,但不在本模块定义需要声明为外部引入
|
||||||
|
extern STACCOUNT g_astAccounts[];
|
||||||
|
extern int g_iAccCount;
|
||||||
|
|
||||||
|
/* 函数功能:数据持久化,将内存中的账户数据保存到文件中
|
||||||
|
保存方式为二进制
|
||||||
|
保存到文件bank.bat中,该文件名只在本模块用使用
|
||||||
|
* 参数:无
|
||||||
|
* 保存信息来自全局变量g_astAccounts
|
||||||
|
* 返回值:无
|
||||||
|
* 保存是失败怎么处理?
|
||||||
|
*/
|
||||||
|
void SaveData()
|
||||||
|
{
|
||||||
|
FILE *file = fopen("bank.dat", "wb");
|
||||||
|
fwrite(g_astAccounts, sizeof(STACCOUNT), 50, file);
|
||||||
|
fclose(file);
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* 函数功能:从文件bank.bat中把账户数据读取到内存
|
||||||
|
操作的文件名仅在本模块中使用
|
||||||
|
* 参数:无
|
||||||
|
* 信息读取后放入全局变量g_astAccounts
|
||||||
|
* 返回值:无
|
||||||
|
* 读取失败怎么处理?
|
||||||
|
*/
|
||||||
|
void LoadData()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int result=0;
|
||||||
|
FILE *file = fopen("bank.dat", "rb");
|
||||||
|
if (file == NULL) {
|
||||||
|
InitAdminAccount();
|
||||||
|
g_iAccCount= 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fread(g_astAccounts, sizeof(STACCOUNT), 50, file);
|
||||||
|
}
|
||||||
|
fclose( file);
|
||||||
|
for (i = 0; i < 50; i++) {
|
||||||
|
if (g_astAccounts[i].id != 0) {
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_iAccCount= result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include "bank.h"
|
||||||
|
|
||||||
|
// 初始化日志队列
|
||||||
|
void InitLogQueue() {
|
||||||
|
g_logQueue.front = 0;
|
||||||
|
g_logQueue.rear = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查队列是否满
|
||||||
|
int IsLogQueueFull() {
|
||||||
|
return (g_logQueue.rear + 1) % MAX_LOGS == g_logQueue.front;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查队列是否空
|
||||||
|
int IsLogQueueEmpty() {
|
||||||
|
return g_logQueue.front == g_logQueue.rear;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取当前时间字符串
|
||||||
|
void GetCurrentTimeStr(char* buf) {
|
||||||
|
time_t t = time(NULL);
|
||||||
|
struct tm tm = *localtime(&t);
|
||||||
|
sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d",
|
||||||
|
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
|
||||||
|
tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 入队操作:记录交易
|
||||||
|
// 参数: 账户ID, 类型("Deposit"/"Withdraw"), 交易金额, 交易后余额
|
||||||
|
int EnqueueLog(int id, const char* type, double amt, double bal) {
|
||||||
|
// 如果队列满,通过移动 front 指针覆盖最旧的日志 (环形队列特性)
|
||||||
|
if (IsLogQueueFull()) {
|
||||||
|
// 覆盖旧数据,队头自动出队
|
||||||
|
g_logQueue.front = (g_logQueue.front + 1) % MAX_LOGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 准备日志条目
|
||||||
|
int pos = g_logQueue.rear;
|
||||||
|
g_logQueue.logs[pos].account_id = id;
|
||||||
|
strcpy(g_logQueue.logs[pos].type, type);
|
||||||
|
g_logQueue.logs[pos].amount = amt;
|
||||||
|
g_logQueue.logs[pos].balance = bal;
|
||||||
|
GetCurrentTimeStr(g_logQueue.logs[pos].timestamp);
|
||||||
|
strcpy(g_logQueue.logs[pos].location, "宇宙总行"); // 根据你的需求固定地点
|
||||||
|
|
||||||
|
// 队尾指针后移
|
||||||
|
g_logQueue.rear = (g_logQueue.rear + 1) % MAX_LOGS;
|
||||||
|
|
||||||
|
return 1; // 成功
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示所有日志 (从队头到队尾)
|
||||||
|
void ShowTransactionLogs() {
|
||||||
|
if (IsLogQueueEmpty()) {
|
||||||
|
printf("暂无交易日志记录。\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n=== 交易流水日志 ===\n");
|
||||||
|
printf("%-5s %-8s %-10s %-10s %-15s %-20s\n", "ID", "操作", "金额", "余额", "时间", "地点");
|
||||||
|
printf("--------------------------------------------------------------\n");
|
||||||
|
|
||||||
|
int i = g_logQueue.front;
|
||||||
|
while (i != g_logQueue.rear) {
|
||||||
|
LogEntry e = g_logQueue.logs[i];
|
||||||
|
printf("%-5d %-8s %-10.2f %-10.2f %-15s %-20s\n",
|
||||||
|
e.account_id, e.type, e.amount, e.balance, e.timestamp, e.location);
|
||||||
|
i = (i + 1) % MAX_LOGS;
|
||||||
|
}
|
||||||
|
}
|
||||||
+30
-28
@@ -5,96 +5,98 @@
|
|||||||
extern STACCOUNT g_astAccounts[];
|
extern STACCOUNT g_astAccounts[];
|
||||||
extern int g_iAccCount;
|
extern int g_iAccCount;
|
||||||
|
|
||||||
/* 函数功能:处理用户的存款操作
|
/* 函数功能:处理用户的存款操作
|
||||||
需要什么步骤?
|
需要什么步骤?
|
||||||
* 参数:无
|
* 参数:无
|
||||||
* 存款信息要写入全局变量g_astAccounts中
|
* 存款信息要写入全局变量g_astAccounts中
|
||||||
* 返回值:无
|
* 返回值:无
|
||||||
* 存款失败怎么处理?
|
* 存款失败怎么处理?
|
||||||
*/
|
*/
|
||||||
void Deposit(int id)
|
void Deposit(int id)
|
||||||
{
|
{
|
||||||
int amount;
|
int amount;
|
||||||
int temp_password;
|
int temp_password;
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("请输入存款金额");
|
printf("请输入存款金额");
|
||||||
scanf("%d",&amount);
|
scanf("%d",&amount);
|
||||||
if (amount>0) {
|
if (amount>0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printf("?你存给我存个负的?重新说存多少");
|
printf("?你存给我存个负的?重新说存多少");
|
||||||
}
|
}
|
||||||
printf("请输入密码");
|
printf("请输入密码");
|
||||||
while (1) {
|
while (1) {
|
||||||
scanf("%d",&temp_password);
|
scanf("%d",&temp_password);
|
||||||
if (g_astAccounts[FindAccount(id)].password==temp_password) {
|
if (g_astAccounts[FindAccount(id)].password==temp_password) {
|
||||||
g_astAccounts[FindAccount(id)].balance+=amount;
|
g_astAccounts[FindAccount(id)].balance+=amount;
|
||||||
printf("success");
|
printf("success");
|
||||||
QueryBalance(id);
|
QueryBalance(id);
|
||||||
|
EnqueueLog(id, "Deposit", amount, g_astAccounts[FindAccount(id)].balance);
|
||||||
SaveData();
|
SaveData();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
printf("密码错误,请重新输入");
|
printf("密码错误,请重新输入");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 函数功能:处理用户的取款操作
|
/* 函数功能:处理用户的取款操作
|
||||||
需要什么步骤?
|
需要什么步骤?
|
||||||
* 参数:无
|
* 参数:无
|
||||||
* 取款后,账户信息要写入全局变量g_astAccounts中
|
* 取款后,账户信息要写入全局变量g_astAccounts中
|
||||||
* 返回值:无
|
* 返回值:无
|
||||||
* 取款失败怎么处理?
|
* 取款失败怎么处理?
|
||||||
*/
|
*/
|
||||||
void Withdraw(int id)
|
void Withdraw(int id)
|
||||||
{
|
{
|
||||||
int amount;
|
int amount;
|
||||||
int temp_password;
|
int temp_password;
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("请输入取款金额");
|
printf("请输入取款金额");
|
||||||
scanf("%d",&amount);
|
scanf("%d",&amount);
|
||||||
if (amount>0) {
|
if (amount>0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printf("?取款怎么能取负的呢");
|
printf("?取款怎么能取负的呢");
|
||||||
}
|
}
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("请输入密码");
|
printf("请输入密码");
|
||||||
scanf("%d",&temp_password);
|
scanf("%d",&temp_password);
|
||||||
if (g_astAccounts[FindAccount(id)].password==temp_password) {
|
if (g_astAccounts[FindAccount(id)].password==temp_password) {
|
||||||
if (g_astAccounts[FindAccount(id)].balance>amount) {
|
if (g_astAccounts[FindAccount(id)].balance>amount) {
|
||||||
g_astAccounts[FindAccount(id)].balance-=amount;
|
g_astAccounts[FindAccount(id)].balance-=amount;
|
||||||
|
EnqueueLog(id, "Withdraw", amount, g_astAccounts[FindAccount(id)].balance);
|
||||||
printf("success");
|
printf("success");
|
||||||
QueryBalance(id);
|
QueryBalance(id);
|
||||||
SaveData();
|
SaveData();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("有那么多钱吗你就取?\n");
|
printf("有那么多钱吗你就取?\n");
|
||||||
QueryBalance(id);
|
QueryBalance(id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("密码错误,请重新输入");
|
printf("密码错误,请重新输入");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 函数功能:处理用户查询余额操作
|
/* 函数功能:处理用户查询余额操作
|
||||||
需要什么步骤?
|
需要什么步骤?
|
||||||
* 参数:无
|
* 参数:无
|
||||||
* 查询后全局变量是否需要变化?
|
* 查询后全局变量是否需要变化?
|
||||||
* 返回值:无
|
* 返回值:无
|
||||||
* 查询失败怎么处理?
|
* 查询失败怎么处理?
|
||||||
*/
|
*/
|
||||||
void QueryBalance(int id)
|
void QueryBalance(int id)
|
||||||
{
|
{
|
||||||
printf("你现在还有%f块\n",g_astAccounts[FindAccount(id)].balance);
|
printf("你现在还有%f块\n",g_astAccounts[FindAccount(id)].balance);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ int GetInputInt(const char *prompt)
|
|||||||
printf("%s", prompt);
|
printf("%s", prompt);
|
||||||
while(scanf("%d", &value) != 1) {
|
while(scanf("%d", &value) != 1) {
|
||||||
ClearInput();
|
ClearInput();
|
||||||
printf("输入错误,请重新输入: ");
|
printf("输入错误,请重新输入: ");
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ double GetInputDouble(const char *prompt)
|
|||||||
printf("%s", prompt);
|
printf("%s", prompt);
|
||||||
while(scanf("%lf", &value) != 1) {
|
while(scanf("%lf", &value) != 1) {
|
||||||
ClearInput();
|
ClearInput();
|
||||||
printf("输入错误,请重新输入: ");
|
printf("输入错误,请重新输入: ");
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user