更改编码为 utf8

This commit is contained in:
idiot
2026-04-22 17:32:22 +08:00
parent fcc7aa959f
commit ae99d48eda
5 changed files with 138 additions and 138 deletions
+57 -57
View File
@@ -6,15 +6,15 @@
extern STACCOUNT g_astAccounts[];
extern int g_iAccCount;
/* 函数功能:处理用户的创建账户操作
思考处理步骤,写到函数体内注释
* 参数:无
* 存款信息要写入全局变量g_astAccounts中
* 返回值:无
* 存款失败怎么处理?
/* 函数功能:处理用户的创建账户操作
思考处理步骤,写到函数体内注释
* 参数:无
* 存款信息要写入全局变量g_astAccounts中
* 返回值:无
* 存款失败怎么处理?
*/
void InitAdminAccount() {
printf("初始化默认管理员账户");
printf("初始化默认管理员账户");
g_astAccounts[0].id = 1000;
strcpy(g_astAccounts[0].name, "admin");
g_astAccounts[0].balance = 0.0;
@@ -25,73 +25,73 @@ void InitAdminAccount() {
void CreateAccount(int quanxian)
{
// (1)合法性检查
// (1)合法性检查
if(MAX_ACCOUNTS < g_iAccCount)
{
printf("账户数量已达上限!\n");
printf("账户数量已达上限!\n");
return;
}
// (2)定义局部变量(函数内使用的变量)
STACCOUNT stNewAcc; //账户变量,结构体变量定义
//char cInput[NAME_LEN]; //接输入的名字字符串
// (2)定义局部变量(函数内使用的变量)
STACCOUNT stNewAcc; //账户变量,结构体变量定义
//char cInput[NAME_LEN]; //接输入的名字字符串
// (3)功能实现
printf("请输入姓名(最多30个字符): ");
// (3)功能实现
printf("请输入姓名(最多30个字符): ");
//这里有风险,怎么改进?
//这里有风险,怎么改进?
scanf("%30s", stNewAcc.name);
//stNewAcc.name[NAME_LEN - 1] = '\0'; // 确保null终止
//输密码
//stNewAcc.name[NAME_LEN - 1] = '\0'; // 确保null终止
//输密码
int temp_password;
while (1) {
printf("请输入密码\n");
printf("请输入密码\n");
scanf("%d",&temp_password);
if (99999<temp_password&&temp_password<999999) {
printf("设置成功\n");
printf("设置成功\n");
stNewAcc.password=temp_password;
SaveData();
break;
}
printf("密码不符合规范!请重新输入\n");
printf("密码不符合规范!请重新输入\n");
}
//需求中要求账户ID从1000开始,初始化账户余额
//需求中要求账户ID从1000开始,初始化账户余额
stNewAcc.id = 1000 + g_iAccCount;
stNewAcc.balance = 0.0;
stNewAcc.quanxian = quanxian;
g_astAccounts[g_iAccCount] = stNewAcc;
//把记录账户数量的全局变量自增。加过之后自增,所以下标0占用,数量是1个
//把记录账户数量的全局变量自增。加过之后自增,所以下标0占用,数量是1个
g_iAccCount++;
printf("开户成功! 账户ID: %d\n", stNewAcc.id);
printf("开户成功! 账户ID: %d\n", stNewAcc.id);
SaveData();
}
/* 函数功能:处理用户的显示所有用户信息的操作
思考处理步骤,写到函数体内注释
* 参数:无
* 从全局变量g_astAccounts中取信息,并显示
* 返回值:无
* 存款失败怎么处理?
/* 函数功能:处理用户的显示所有用户信息的操作
思考处理步骤,写到函数体内注释
* 参数:无
* 从全局变量g_astAccounts中取信息,并显示
* 返回值:无
* 存款失败怎么处理?
*/
void ShowAccounts()
{
//(1)输出用户内容提示
printf("\n所有账户信息:\n");
//(1)输出用户内容提示
printf("\n所有账户信息:\n");
//(2)检查是否有账户了?异常情况无账户的处理
//(2)检查是否有账户了?异常情况无账户的处理
if (0 == g_iAccCount)
{
printf("暂无账户信息\n");
printf("暂无账户信息\n");
return;
}
//(3)打印表头
printf("%-8s %-30s %-10s %-3s\n", "ID", "姓名", "余额","权限");
//(3)打印表头
printf("%-8s %-30s %-10s %-3s\n", "ID", "姓名", "余额","权限");
printf("------------------------------------------------------\n");
//(4)循环打印每一行
//(4)循环打印每一行
for(int i = 0; i < g_iAccCount; i++)
{
printf("%-8d %-30s %-10.2f %-10d\n",
@@ -99,37 +99,37 @@ void ShowAccounts()
}
}
//登录账户,返回权限
//登录账户,返回权限
int LoginAccount(int temp_id) {
int temp_password;
if (FindAccount(temp_id)==-1) {
printf("没有找到账户\n");
printf("没有找到账户\n");
return 0;
}
else {
while (1) {
printf("请输入密码");
printf("请输入密码");
scanf("%d", &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) {
printf("您目前以管理员身份登录");
printf("您目前以管理员身份登录");
return 1;
}
else {return 2;}
}
else {
printf("密码错误,请重新输入\n");
printf("密码错误,请重新输入\n");
}
}
}
}
/* 函数功能:根据输入的用户ID找到
思考处理步骤,写到函数体内注释
* 参数:无
* 用户ID跟数组ID
* 返回值:无
* 存款失败怎么处理?
/* 函数功能:根据输入的用户ID找到
思考处理步骤,写到函数体内注释
* 参数:无
* 用户ID跟数组ID
* 返回值:无
* 存款失败怎么处理?
*/
int FindAccount(int id)
{
@@ -140,15 +140,15 @@ int FindAccount(int id)
return -1;
}
//删除账户
//删除账户
void DeleteAccount(int id) {
printf("正在删除\n");
printf("正在删除\n");
int i=FindAccount(id);
if (i==-1) {
printf("有这个账户吗你就删");
printf("有这个账户吗你就删");
}
else {
printf("正在删除一下账户...");
printf("正在删除一下账户...");
printf("%-8d %-30s %-10.2f %-3d\n",
g_astAccounts[i].id, g_astAccounts[i].name, g_astAccounts[i].balance,g_astAccounts[i].quanxian);
for (; i < g_iAccCount-i; i++)
@@ -162,24 +162,24 @@ void DeleteAccount(int id) {
void ChangePassword(int id) {
int temp_password;
while (1) {
printf("请输入原密码");
printf("请输入原密码");
scanf("%d",&temp_password);
if (g_astAccounts[FindAccount(id)].password==temp_password) {
while (1) {
printf("请输入新密码\n");
printf("请输入新密码\n");
scanf("%d",&temp_password);
if (99999<temp_password&&temp_password<999999) {
printf("修改成功\n");
printf("修改成功\n");
g_astAccounts[FindAccount(id)].password=temp_password;
SaveData();
break;
}
printf("密码不符合规范!请重新输入\n");
printf("密码不符合规范!请重新输入\n");
}
}
else {
printf("密码错误,请重新输入");
printf("密码错误,请重新输入");
}
}
}
+36 -36
View File
@@ -12,53 +12,53 @@ int d_id;
int main(void)
{
LoadData();
//(1)导入数据
//(1)导入数据
// which fuction?
//应该先导入数据再欢迎?还是欢迎了再导入数据?
printf("=== 简易银行账户管理系统 ===\n");
printf("欢迎使用! 系统已加载%d个账户\n", g_iAccCount);
InitAdminAccount();//初始化管理员账号
int iChoice=-1; //选择标志
//应该先导入数据再欢迎?还是欢迎了再导入数据?
printf("=== 简易银行账户管理系统 ===\n");
printf("欢迎使用! 系统已加载%d个账户\n", g_iAccCount);
InitAdminAccount();//初始化管理员账号
int iChoice=-1; //选择标志
int pChoice=-1;
while (1) {
//持续显示菜单的秘诀
//(2)显示主菜单,并且处理用户的选择
//持续显示菜单的秘诀
//(2)显示主菜单,并且处理用户的选择
if (quanxian==-2){break;}
printf("\n=== 简易银行账户管理系统 ===\n");
printf("\n=== 简易银行账户管理系统 ===\n");
switch(quanxian) {
case 0:
printf("1. 开户\n2. 登录 \n0. 退出\n");
//printf("1. 开户\n2. 存款\n3. 取款\n4. 查询\n5. 显示所有账户\n6. 退出\n");
printf("请选择: ");
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");
printf("请输入账户id");
scanf("%d", &user_id);
quanxian=LoginAccount(user_id);
break;
case 0://EXIT
printf("谢谢使用!\n按任意键退出\n");
printf("谢谢使用!\n按任意键退出\n");
getchar();
quanxian=-2;
exit(0);
//还要实现哪些菜单吗?
//如果要做排序展示,要做什么?
default: //好的编码习惯,对无效值做处理
printf("无效选择!\n");
break; //好的编码加上break,万一default挪了个位置呢?
//还要实现哪些菜单吗?
//如果要做排序展示,要做什么?
default: //好的编码习惯,对无效值做处理
printf("无效选择!\n");
break; //好的编码加上break,万一default挪了个位置呢?
}
break;
case 1:
printf("1. 存款\n2. 取款\n3. 查询\n4. 显示所有账户\n5. 删除账户\n6. 创建管理员账户\n0. 退出账户");
printf("1. 存款\n2. 取款\n3. 查询\n4. 显示所有账户\n5. 删除账户\n6. 创建管理员账户\n0. 退出账户");
pChoice=-1;
scanf("%d", &pChoice);
@@ -76,7 +76,7 @@ int main(void)
ShowAccounts();
break;
case 5:
printf("请输入要删除的id");
printf("请输入要删除的id");
scanf("%d", &d_id);
DeleteAccount(d_id);
g_iAccCount--;
@@ -85,19 +85,19 @@ int main(void)
CreateAccount(1);
break;
case 0://EXIT
printf("谢谢使用!\n按任意键退出");
printf("谢谢使用!\n按任意键退出");
getchar();
quanxian=-2;
//还要实现哪些菜单吗?
//如果要做排序展示,要做什么?
default: //好的编码习惯,对无效值做处理
printf("无效选择!\n");
break; //好的编码加上break,万一default挪了个位置呢?
//还要实现哪些菜单吗?
//如果要做排序展示,要做什么?
default: //好的编码习惯,对无效值做处理
printf("无效选择!\n");
break; //好的编码加上break,万一default挪了个位置呢?
}
break;
case 2:
printf("1. 存款\n2. 取款\n3. 查询\n0.退出账户");
printf("1. 存款\n2. 取款\n3. 查询\n0.退出账户");
pChoice=-1;
scanf("%d", &pChoice);
switch(pChoice) {
@@ -111,22 +111,22 @@ int main(void)
QueryBalance(user_id);
break;
case 0://EXIT
printf("谢谢使用!\n按任意键退出");
printf("谢谢使用!\n按任意键退出");
getchar();
quanxian=-2;
break;
//还要实现哪些菜单吗?
//如果要做排序展示,要做什么?
default: //好的编码习惯,对无效值做处理
printf("无效选择!\n");
break; //好的编码加上break,万一default挪了个位置呢?
//还要实现哪些菜单吗?
//如果要做排序展示,要做什么?
default: //好的编码习惯,对无效值做处理
printf("无效选择!\n");
break; //好的编码加上break,万一default挪了个位置呢?
}
break;
}
}
//(3)调用保存数据的函数
//(3)调用保存数据的函数
// which fuction?
return 0;
+15 -15
View File
@@ -1,10 +1,10 @@
#ifndef BANK_H
#define BANK_H
#define MAX_ACCOUNTS 50 //系统规格为50个账户
#define NAME_LEN 31 //用户名字最长30字符,因此需要多1个字符串结束符
#define MAX_ACCOUNTS 50 //系统规格为50个账户
#define NAME_LEN 31 //用户名字最长30字符,因此需要多1个字符串结束符
// 账户信息,每个账户id对应了名字、账户余额等信息,是不是用数据结构定义比较合适?
// 账户信息,每个账户id对应了名字、账户余额等信息,是不是用数据结构定义比较合适?
typedef struct strAccount
{
int id;
@@ -16,37 +16,37 @@ typedef struct strAccount
// strAccount STACCOUNT;
// 函数声明,main函数中调用的各模块函数需要在程序公用的.h中声明
// 公开出来被其他模块调用的函数,也应该在公用的.h中声明
// 函数声明,main函数中调用的各模块函数需要在程序公用的.h中声明
// 公开出来被其他模块调用的函数,也应该在公用的.h中声明
//创建账户的函数
//创建账户的函数
void CreateAccount(int quanxian);
//实现存款的函数
//实现存款的函数
void Deposit(int id);
//实现取款的函数
//实现取款的函数
void Withdraw(int id);
//查询余额的函数
//查询余额的函数
void QueryBalance(int id);
//显示全部账户的函数
//显示全部账户的函数
void ShowAccounts();
//数据持久化函数
//数据持久化函数
void SaveData();
//加载数据的函数
//加载数据的函数
void LoadData();
//根据ID查找账户数组id的函数
//根据ID查找账户数组id的函数
int FindAccount(int iD);
//登录函数,返回用户权限
//登录函数,返回用户权限
int LoginAccount(int temp_id);
//销户
//销户
void DeleteAccount(int id);
void InitAdminAccount();
+28 -28
View File
@@ -5,26 +5,26 @@
extern STACCOUNT g_astAccounts[];
extern int g_iAccCount;
/* 函数功能:处理用户的存款操作
需要什么步骤?
* 参数:无
* 存款信息要写入全局变量g_astAccounts中
* 返回值:无
* 存款失败怎么处理?
/* 函数功能:处理用户的存款操作
需要什么步骤?
* 参数:无
* 存款信息要写入全局变量g_astAccounts中
* 返回值:无
* 存款失败怎么处理?
*/
void Deposit(int id)
{
int amount;
int temp_password;
while (1) {
printf("请输入存款金额");
printf("请输入存款金额");
scanf("%d",&amount);
if (amount>0) {
break;
}
printf("?你存给我存个负的?重新说存多少");
printf("?你存给我存个负的?重新说存多少");
}
printf("请输入密码");
printf("请输入密码");
while (1) {
scanf("%d",&temp_password);
if (g_astAccounts[FindAccount(id)].password==temp_password) {
@@ -37,33 +37,33 @@ void Deposit(int id)
else
{
{
printf("密码错误,请重新输入");
printf("密码错误,请重新输入");
}
}
}
}
/* 函数功能:处理用户的取款操作
需要什么步骤?
* 参数:无
* 取款后,账户信息要写入全局变量g_astAccounts中
* 返回值:无
* 取款失败怎么处理?
/* 函数功能:处理用户的取款操作
需要什么步骤?
* 参数:无
* 取款后,账户信息要写入全局变量g_astAccounts中
* 返回值:无
* 取款失败怎么处理?
*/
void Withdraw(int id)
{
int amount;
int temp_password;
while (1) {
printf("请输入取款金额");
printf("请输入取款金额");
scanf("%d",&amount);
if (amount>0) {
break;
}
printf("?取款怎么能取负的呢");
printf("?取款怎么能取负的呢");
}
while (1) {
printf("请输入密码");
printf("请输入密码");
scanf("%d",&temp_password);
if (g_astAccounts[FindAccount(id)].password==temp_password) {
if (g_astAccounts[FindAccount(id)].balance>amount) {
@@ -74,27 +74,27 @@ void Withdraw(int id)
return;
}
else {
printf("有那么多钱吗你就取?\n");
printf("有那么多钱吗你就取?\n");
QueryBalance(id);
return;
}
}
else {
printf("密码错误,请重新输入");
printf("密码错误,请重新输入");
}
}
}
/* 函数功能:处理用户查询余额操作
需要什么步骤?
* 参数:无
* 查询后全局变量是否需要变化?
* 返回值:无
* 查询失败怎么处理?
/* 函数功能:处理用户查询余额操作
需要什么步骤?
* 参数:无
* 查询后全局变量是否需要变化?
* 返回值:无
* 查询失败怎么处理?
*/
void QueryBalance(int id)
{
printf("你现在还有%f块\n",g_astAccounts[FindAccount(id)].balance);
printf("你现在还有%f块\n",g_astAccounts[FindAccount(id)].balance);
return;
}
+2 -2
View File
@@ -13,7 +13,7 @@ int GetInputInt(const char *prompt)
printf("%s", prompt);
while(scanf("%d", &value) != 1) {
ClearInput();
printf("输入错误,请重新输入: ");
printf("输入错误,请重新输入: ");
}
return value;
}
@@ -24,7 +24,7 @@ double GetInputDouble(const char *prompt)
printf("%s", prompt);
while(scanf("%lf", &value) != 1) {
ClearInput();
printf("输入错误,请重新输入: ");
printf("输入错误,请重新输入: ");
}
return value;
}