commit 59113dd185726a40eaf1c2a4f422423aa2e5ba7e Author: Idiot <2777566203@qq.com> Date: Mon Apr 6 21:36:26 2026 +0800 1.0 Signed-off-by: Idiot <2777566203@qq.com> diff --git a/README.md b/README.md new file mode 100644 index 0000000..06d7405 Binary files /dev/null and b/README.md differ diff --git a/account.c b/account.c new file mode 100644 index 0000000..4a99369 --- /dev/null +++ b/account.c @@ -0,0 +1,185 @@ +#include +#include +#include +#include "bank.h" + +extern STACCOUNT g_astAccounts[]; +extern int g_iAccCount; + +/* 函数功能:处理用户的创建账户操作 + 思考处理步骤,写到函数体内注释 + * 参数:无 + * 存款信息要写入全局变量g_astAccounts中 + * 返回值:无 + * 存款失败怎么处理? + */ +void InitAdminAccount() { + printf("初始化默认管理员账户"); + g_astAccounts[0].id = 1000; + strcpy(g_astAccounts[0].name, "admin"); + g_astAccounts[0].balance = 0.0; + g_astAccounts[0].password = 123456; + g_astAccounts[0].quanxian = 1; + SaveData(); +} + +void CreateAccount(int quanxian) +{ + // (1)合法性检查 + if(MAX_ACCOUNTS < g_iAccCount) + { + printf("账户数量已达上限!\n"); + return; + } + + // (2)定义局部变量(函数内使用的变量) + STACCOUNT stNewAcc; //账户变量,结构体变量定义 + //char cInput[NAME_LEN]; //接输入的名字字符串 + + // (3)功能实现 + printf("请输入姓名(最多30个字符): "); + + //这里有风险,怎么改进? + scanf("%30s", stNewAcc.name); + //stNewAcc.name[NAME_LEN - 1] = '\0'; // 确保null终止 + //输密码 + int temp_password; + while (1) { + printf("请输入密码\n"); + scanf("%d",&temp_password); + if (99999 +#include +#include +#include "bank.h" + +STACCOUNT g_astAccounts[MAX_ACCOUNTS]; + +int g_iAccCount = 1; +int quanxian =0;//1,admin:2,user +int user_id; +int d_id; +int main(void) +{ + LoadData(); + //(1)导入数据 + // which fuction? + + //应该先导入数据再欢迎?还是欢迎了再导入数据? + printf("=== 简易银行账户管理系统 ===\n"); + printf("欢迎使用! 系统已加载%d个账户\n", g_iAccCount); + InitAdminAccount();//初始化管理员账号 + int iChoice=-1; //选择标志 + int pChoice=-1; + while (1) { + //持续显示菜单的秘诀 + //(2)显示主菜单,并且处理用户的选择 + if (quanxian==-2){break;} + printf("\n=== 简易银行账户管理系统 ===\n"); + switch(quanxian) { + case 0: + printf("1. 开户\n2. 登录 \n0. 退出\n"); + //printf("1. 开户\n2. 存款\n3. 取款\n4. 查询\n5. 显示所有账户\n6. 退出\n"); + printf("请选择: "); + iChoice=-1; + scanf("%d", &iChoice); + switch(iChoice) { + case 1://CREATE + //调用创建账号的函数 + CreateAccount(2); + quanxian=0; + break; + case 2://LOGIN + printf("请输入账户id"); + scanf("%d", &user_id); + quanxian=LoginAccount(user_id); + break; + case 0://EXIT + printf("谢谢使用!\n按任意键退出\n"); + getchar(); + quanxian=-2; + exit(0); + + //还要实现哪些菜单吗? + //如果要做排序展示,要做什么? + default: //好的编码习惯,对无效值做处理 + printf("无效选择!\n"); + break; //好的编码加上break,万一default挪了个位置呢? + } + break; + case 1: + printf("1. 存款\n2. 取款\n3. 查询\n4. 显示所有账户\n5. 删除账户\n6. 创建管理员账户\n0. 退出账户"); + pChoice=-1; + scanf("%d", &pChoice); + + switch(pChoice) { + case 1: + Deposit(user_id); + break; + case 2: + Withdraw(user_id); + break; + case 3: + QueryBalance(user_id); + break; + case 4: + ShowAccounts(); + break; + case 5: + printf("请输入要删除的id"); + scanf("%d", &d_id); + DeleteAccount(d_id); + g_iAccCount--; + break; + case 6: + CreateAccount(1); + break; + case 0://EXIT + printf("谢谢使用!\n按任意键退出"); + getchar(); + quanxian=-2; + //还要实现哪些菜单吗? + //如果要做排序展示,要做什么? + default: //好的编码习惯,对无效值做处理 + printf("无效选择!\n"); + break; //好的编码加上break,万一default挪了个位置呢? + + } + break; + case 2: + printf("1. 存款\n2. 取款\n3. 查询\n0.退出账户"); + pChoice=-1; + scanf("%d", &pChoice); + switch(pChoice) { + case 1: + Deposit(user_id); + break; + case 2: + Withdraw(user_id); + break; + case 3: + QueryBalance(user_id); + break; + case 0://EXIT + printf("谢谢使用!\n按任意键退出"); + getchar(); + quanxian=-2; + break; + //还要实现哪些菜单吗? + //如果要做排序展示,要做什么? + default: //好的编码习惯,对无效值做处理 + printf("无效选择!\n"); + break; //好的编码加上break,万一default挪了个位置呢? + } + break; + } + } + + + //(3)调用保存数据的函数 + // which fuction? + + return 0; +} diff --git a/transaction.c b/transaction.c new file mode 100644 index 0000000..a871f25 --- /dev/null +++ b/transaction.c @@ -0,0 +1,100 @@ +#include +#include +#include "bank.h" + +extern STACCOUNT g_astAccounts[]; +extern int g_iAccCount; + +/* 函数功能:处理用户的存款操作 + 需要什么步骤? + * 参数:无 + * 存款信息要写入全局变量g_astAccounts中 + * 返回值:无 + * 存款失败怎么处理? + */ +void Deposit(int id) +{ + int amount; + int temp_password; + while (1) { + printf("请输入存款金额"); + scanf("%d",&amount); + if (amount>0) { + break; + } + printf("?你存给我存个负的?重新说存多少"); + } + printf("请输入密码"); + while (1) { + scanf("%d",&temp_password); + if (g_astAccounts[FindAccount(id)].password==temp_password) { + g_astAccounts[FindAccount(id)].balance+=amount; + printf("success"); + QueryBalance(id); + SaveData(); + break; + } + else + { + { + printf("密码错误,请重新输入"); + } + } + } + } + +/* 函数功能:处理用户的取款操作 + 需要什么步骤? + * 参数:无 + * 取款后,账户信息要写入全局变量g_astAccounts中 + * 返回值:无 + * 取款失败怎么处理? + */ +void Withdraw(int id) +{ + int amount; + int temp_password; + while (1) { + printf("请输入取款金额"); + scanf("%d",&amount); + if (amount>0) { + break; + } + printf("?取款怎么能取负的呢"); + } + while (1) { + printf("请输入密码"); + scanf("%d",&temp_password); + if (g_astAccounts[FindAccount(id)].password==temp_password) { + if (g_astAccounts[FindAccount(id)].balance>amount) { + g_astAccounts[FindAccount(id)].balance-=amount; + printf("success"); + QueryBalance(id); + SaveData(); + return; + } + else { + printf("有那么多钱吗你就取?\n"); + QueryBalance(id); + return; + } + } + else { + printf("密码错误,请重新输入"); + } + } + +} + +/* 函数功能:处理用户查询余额操作 + 需要什么步骤? + * 参数:无 + * 查询后全局变量是否需要变化? + * 返回值:无 + * 查询失败怎么处理? + */ +void QueryBalance(int id) +{ + printf("你现在还有%f块\n",g_astAccounts[FindAccount(id)].balance); + return; +} diff --git a/utils.c b/utils.c new file mode 100644 index 0000000..be8ea24 --- /dev/null +++ b/utils.c @@ -0,0 +1,30 @@ +#include +#include +#include "bank.h" + +void ClearInput() +{ + while(getchar() != '\n'); +} + +int GetInputInt(const char *prompt) +{ + int value; + printf("%s", prompt); + while(scanf("%d", &value) != 1) { + ClearInput(); + printf("输入错误,请重新输入: "); + } + return value; +} + +double GetInputDouble(const char *prompt) +{ + double value; + printf("%s", prompt); + while(scanf("%lf", &value) != 1) { + ClearInput(); + printf("输入错误,请重新输入: "); + } + return value; +}