Files
BankManager/bank.h
T

81 lines
2.3 KiB
C
Raw Permalink Normal View History

2026-04-06 21:37:41 +08:00
#ifndef BANK_H
#define BANK_H
2026-05-08 11:46:09 +08:00
#define MAX_LOGS 100 // 日志队列最大容量,防止无限增长
2026-04-22 17:32:22 +08:00
#define MAX_ACCOUNTS 50 //系统规格为50个账户
#define NAME_LEN 31 //用户名字最长30字符,因此需要多1个字符串结束符
2026-04-06 21:37:41 +08:00
2026-04-22 17:32:22 +08:00
// 账户信息,每个账户id对应了名字、账户余额等信息,是不是用数据结构定义比较合适?
2026-04-06 21:37:41 +08:00
typedef struct strAccount
{
int id;
char name[NAME_LEN];
double balance;
int password;
int quanxian;//1,admin:2,user
} STACCOUNT;
// strAccount STACCOUNT;
2026-04-22 17:32:22 +08:00
// 函数声明,main函数中调用的各模块函数需要在程序公用的.h中声明
// 公开出来被其他模块调用的函数,也应该在公用的.h中声明
2026-04-06 21:37:41 +08:00
2026-04-22 17:32:22 +08:00
//创建账户的函数
2026-04-06 21:37:41 +08:00
void CreateAccount(int quanxian);
2026-04-22 17:32:22 +08:00
//实现存款的函数
2026-04-06 21:37:41 +08:00
void Deposit(int id);
2026-04-22 17:32:22 +08:00
//实现取款的函数
2026-04-06 21:37:41 +08:00
void Withdraw(int id);
2026-04-22 17:32:22 +08:00
//查询余额的函数
2026-04-06 21:37:41 +08:00
void QueryBalance(int id);
2026-04-22 17:32:22 +08:00
//显示全部账户的函数
2026-04-06 21:37:41 +08:00
void ShowAccounts();
2026-04-22 17:32:22 +08:00
//数据持久化函数
2026-04-06 21:37:41 +08:00
void SaveData();
2026-04-22 17:32:22 +08:00
//加载数据的函数
2026-04-06 21:37:41 +08:00
void LoadData();
2026-04-22 17:32:22 +08:00
//根据ID查找账户数组id的函数
2026-04-06 21:37:41 +08:00
int FindAccount(int iD);
2026-04-22 17:32:22 +08:00
//登录函数,返回用户权限
2026-04-06 21:37:41 +08:00
int LoginAccount(int temp_id);
2026-04-22 17:32:22 +08:00
//销户
2026-04-06 21:37:41 +08:00
void DeleteAccount(int id);
void InitAdminAccount();
2026-05-08 11:46:09 +08:00
// 日志条目结构
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(); // 显示所有日志
2026-04-06 21:37:41 +08:00
#endif