银行ATM模拟存取系统-代码量1000

前言:
这两个月没怎么写博客,都是在积累项目经验,总共写了大概有二十多个课设,但是代码量大概都在300~600行,所以希望能够写一个代码量大概在一两千行的项目挑战一下,锻炼一下自己的大项目编写能力,不过写完了才发现,这个项目完全实现代码量也差不多才一千行
简介:
这是一个大一期末课程设计,难度中等,我不怎么熟悉这个课题的实现,所以花了一些时间,用数组和链表来编写整个项目

一、题目:

> 一、设计内容完成一个管理类的综合型设计: 银行ATM模拟存取系统。

> 要求学生进行数据结构的设计、对函数进行模块化结构化设计、并灵活运用数组、结构体、指针、文件等多种数据类型设计开发系统。 通过写程序,学生应掌握用计算机程序设计语言解决实际问题的方法、步骤。 
> 
> 该系统应该具有以下功能 :

> 1)账户管理功能 
> a)开户:完成账户注册的功能。即输入账户的相关信息。 要求账户号长度12, 密码长度不得低于6, 必须使用暗码,账户信息保存到数组中, 账户信息最后保存到相关文件中;
> b)账户登录:输入账户、密码, 验证是否能够登录该系统; 
> c)密码修改:输入两次相同的密码方可修改。

> 2)账务管理功能
> a)存款:每笔存款金额大于0元小于等于1000,50元为基本单位。需记录交易日期和时间。
> b)取款:每笔取款金额大于等于100元小于等于2000,50元为基本单位。需记录交易日期和时间
> c)转账:每笔转账金额大于等于100元小于等于5000元。需记录交易日期和时间。

> 3)查询功能 
> a)存款记录查询 
> b)取款记录查询 
> c)转账记录查询 
> d)余额查询
> 
> 4)文件功能及其它功能:数据都应保存在相关文件中。

二、数据设计:

# define MAX 1000//最多能够存储100个账户链表

//时间类型
typedef struct
{
	int year;//年
	int month;//月
	int day;//日
	int hour;//时
	int min;//分
	int second;//秒
}Date;

//账户结构体
typedef struct
{
	char ID[13];//账号
	char password[20];//密码
	char name[20];//姓名
	int age;//年龄
	char sex[5];//性别
	char idNumber[20];//身份证号码
	int balance;//余额
	Date date;//开户时间
	//char date[50];//开户时间
}Account;

//封装节点中的数据
typedef struct data
{
	char tradingObject[20];//交易对象的账号
	int money;//交易金额
	Date date;//交易时间
	char type[5];//交易类型
}Data;

//交易结构体
typedef struct dealNode
{
	Data data;//数据域
	struct dealNode* next;//指针域
}dealNode;

//单链表类型
typedef struct List
{
	int size;//链表数据长度
	Account account;//链表所属账户
	dealNode* pHead;//首节点
}List;

/*全局变量*/
List LIST[MAX];
int count = 0;//当前存储的账户个数
int curIndex = -1;//登录成功的账户的下标

三、总体设计:

/*函数声明*/

//注册登录部分
void signin();//注册
int login();//登录
void modifyPassword();//修改密码
void saveListMes();//账户信息保存

/*菜单和指令输入部分*/
void menu01();
void keyDown01();
void menu02();
int keyDown02();
void menu03();
int keyDown03();

/*链表部分*/
List* creatList();								 //创建单链表
dealNode* creatHeadNode();						 //创建链表的头节点
dealNode* creatListNode(Data data);				 //创建交易信息节点
void insertByTail(List* list, dealNode* newNode);//有头链表的尾插法
void travelList(List* list);					 //遍历链表

/*账户操作部分*/
int searchList(char* ID);		//查找交易对象的账户
int isContinue();				//是否继续
void deposit();					//存款
void withdrawal();				//取款
void transferAccount();		   	//转账
void updateRecord(List * list); //更新交易记录

/*查询部分*/
void searchRecord(char * type);	//查询各种记录

四、详细设计:

注册、登录、修改数据、数据存取,其实都是考察对C语言中文件部分知识的掌握程度

①、开户注册:

代码实现:

//注册
void signin()
{
	//注册账号密码   代码块
	char ID[13], password[20];
NEXT:
	printf("请输入12位的账号:");
	scanf("%s", ID);
	getchar();
	if (strlen(ID) != 12)
	{
		printf("\n账号不符合条件!请重新输入!\n");
		system("pause");
		system("cls");
		menu01();
		printf("请输入你的选择:1\n");
		goto NEXT;
	}
	printf("请输入不少于6位的密码:");

	int passLen = 0;
	char ch;

	while ((ch = _getch()) != '\r')
	{
		if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9' || ch == 8)
		{
			if (ch == 8)//如果想删除前面输入的一个数字
			{
				if (passLen > 0)
				{
					printf("\b \b");//实现删除一个字符    退格 空格清空字符 退格
					passLen--;
				}
			}
			else if (passLen <= 19)
			{
				printf("*");
				password[passLen++] = ch;
			}
		}
	}
	password[passLen] = '\0';
	printf("\n");
	if (passLen < 6)
	{
		passLen = 0;
		printf("\n密码少于6位!请重新输入!\n");
		system("pause");
		system("cls");
		menu01();
		goto NEXT;
	}

	//用户其他相关信息注册 代码块
	char name[20];
	int age;//年龄
	char sex[5];//性别
	char idNumber[20];//身份证号码
	int balance;//余额

	printf("请输入您的姓名:");
	scanf("%s", name);
	getchar();
	printf("请输入您的年龄:");
	scanf("%d", &age);
	getchar();
	printf("请输入您的性别:");
	scanf("%s", sex);
	getchar();
	int idLen;
	do
	{
		printf("请输入您的身份证号码(18位):");
		scanf("%s", idNumber);
		getchar();
		idLen = strlen(idNumber);
		if (idLen != 18)
		{
			printf("\n身份证号码不符合18位!请重新输入!\n");
		}
	} while (idLen != 18);
	printf("请输入账户初始余额:");
	scanf("%d", &balance);
	getchar();

	time_t timep;//时间
	struct tm* p;
	time(&timep);
	p = gmtime(&timep);//获取当前时间

	//文件保存
	FILE* fp = NULL;
NEXT01:
	fp = fopen("注册信息记录.txt", "rb+");
	if (fp == NULL)//如果文件不存在,则打开文件,打印标题
	{
		fp = fopen("注册信息记录.txt", "wb+");
		fprintf(fp, "姓名   年龄    性别    身份证号    余额    账号    密码    开户时间\n");
	}
	else//如果文件已经存在,则只打印标题
	{
		fclose(fp);
		fp = fopen("注册信息记录.txt", "ab+");
	}
	
	if (fp == NULL)
	{
		goto NEXT01;
	}

	fprintf(fp, "%s\t%d\t%s\t%s\t%d\t%s\t%s\t%d-%d-%d %d:%d:%d\n", 
		name,age,sex,idNumber,balance,ID, password, 
		1900+p->tm_year, 1+p->tm_mon,p->tm_mday, 8+p->tm_hour,p->tm_min,p->tm_sec);
	printf("\n账号注册成功!\n");
	fclose(fp);

	//创建新账户的交易记录文件
	char file[50];
	strcpy(file, ID);
	strcat(file, ".txt");
	FILE* fp1 = NULL;
	fp1 = fopen(file, "w");
	if (fp1 == NULL)
	{
		printf("\n%s的交易记录文件创建失败!\n", file);
		return;
	}
	fprintf(fp1, "%s\t%s\t%d\t%d-%d-%d %d:%d:%d\n", "存款", ID, balance,
		1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, 8 + p->tm_hour, p->tm_min, p->tm_sec);
	fclose(fp1);
	//可以考虑给每个注册成功的用户创建一个文件夹,存储账户信息记录文本
	//int status;
	//status = mkdir()

	return;
}

②、账号登录和检验:

代码实现:

//登录
int login()
{
	char ID[13], password[20];
NEXT:
	printf("请输入12位的账号:");
	scanf("%s", ID);
	getchar();
	if (strlen(ID) != 12)
	{
		printf("\n账号不符合条件!请重新输入!\n");
		system("pause");
		system("cls");
		menu01();
		printf("请输入你的选择:2\n");
		goto NEXT;
	}
	printf("请输入不少于6位的密码:");

	char ch;
	int passLen = 0;

	while ((ch = _getch()) != '\r')
	{
		if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9' || ch == 8)
		{
			if (ch == 8)//如果想删除前面输入的一个数字
			{
				if (passLen > 0)
				{
					printf("\b \b");//实现删除一个字符   退格 空格清空字符 退格
					passLen--;
				}
			}
			else if (passLen <= 19)
			{
				printf("*");
				password[passLen++] = ch;
			}
		}
	}
	password[passLen] = '\0';
	printf("\n");
	if (passLen < 6)
	{
		passLen = 0;
		printf("\n密码少于6位!请重新输入!\n");
		system("pause");
		system("cls");
		menu01();
		printf("请输入你的选择:2\n");
		goto NEXT;
	}

	FILE* fp = NULL;
	if ((fp = fopen("注册信息记录.txt", "rb")) == NULL)
	{
		perror("\n账号密码文件打开错误!无法登录!\n");
		return 0;
	}  

	//清除文件的第一行
	char flash[1000];
	fgets(flash, 1000, fp);

	int flag = 0;//作为是否登录成功的标记
	count = 0;//注意每次加载文件时,都需要初始化账户的个数为0
	while (fscanf(fp, "%s\t%d\t%s\t%s\t%d\t%s\t%s\t%d-%d-%d %d:%d:%d\n",
		LIST[count].account.name, &LIST[count].account.age, LIST[count].account.sex, LIST[count].account.idNumber,
		&LIST[count].account.balance, LIST[count].account.ID, LIST[count].account.password,
		&LIST[count].account.date.year, &LIST[count].account.date.month, &LIST[count].account.date.day,
		&LIST[count].account.date.hour, &LIST[count].account.date.min, &LIST[count].account.date.second) != EOF)
	{
		if (strcmp(ID, LIST[count].account.ID) == 0 && strcmp(password, LIST[count].account.password) == 0)
		{
			/*fclose(fp);*/
			flag = 1;
		}

		//需要加载所有账户的交易记录的信息
		char file[50];
		strcpy(file, LIST[count].account.ID);
		strcat(file, ".txt");
		FILE* fp1 = NULL;
		fp1 = fopen(file, "rb");
		if (fp1 == NULL)
		{
			printf("\n%s的交易记录文件打开失败!\n", file);
			return 0;
		}

		/*自动加载所有账户的交易记录数据*/
		//加载保存在本地的文件数据
		//加载该账号的交易记录的数据到当前账户的链表中     交易类型  交易对象账户 交易金额 交易时间

		//加载当前索引的账户的交易信息
		LIST[count].pHead = creatHeadNode();
		Data data;
		while (fscanf(fp1, "%s\t%s\t%d\t%d-%d-%d %d:%d:%d\n", data.type, data.tradingObject, &data.money,
			&data.date.year, &data.date.month, &data.date.day, &data.date.hour, &data.date.min, &data.date.second) != EOF)
		{
			dealNode* newNode = creatListNode(data);
			insertByTail(&LIST[count], newNode);
		}
		fclose(fp1);

		count++;
	}
	fclose(fp);

	//判断是否登录成功,如果成功,则查找当前登录账户的索引
	if (flag == 1)
	{
		printf("\n登录成功!\n");
		int i;
		for (i = 0; i < count; i++)
		{
			if (strcmp(ID, LIST[i].account.ID) == 0)
			{
				curIndex = i;
			}
		}
		return 1;
	}
	
	printf("\n登录失败!\n");
	return 0;
}

③、修改密码:

代码实现:

//修改密码
void modifyPassword()
{
NEXT04:
	printf("\n\n请输入新密码:");
	char newPassword_1[20];
	scanf("%s", newPassword_1);
	getchar();

	printf("请再次输入新密码:");
	char newPassword_2[20];
	scanf("%s", newPassword_2);
	getchar();
	int flag = 0;
	//验证两次密码是否一致
	if (strcmp(newPassword_1, newPassword_2) != 0)
	{
		printf("\n两次输入密码不一致!无法修改!\n");
		if (isContinue())
		{
			goto NEXT04;
		}
	}
	else
	{
		//更新密码
		strcpy(LIST[curIndex].account.password, newPassword_1);
		//重新写入所有账户信息
		saveListMes();
	}
	return;
}

④、保存账户信息:

代码实现:

//保存账户信息
void saveListMes()
{
	FILE* fp = NULL;
	fp = fopen("注册信息记录.txt", "wb+");
	if (fp == NULL)
	{
		perror("\n注册信息记录文件打开错误!\n");
		return;
	}
	fprintf(fp, "姓名   年龄    性别    身份证号    余额    账号    密码    开户时间\n");

	int i;
	for (i = 0; i < count; i++)
	{
		fprintf(fp, "%s\t%d\t%s\t%s\t%d\t%s\t%s\t%d-%d-%d %d:%d:%d\n",
			LIST[i].account.name, LIST[i].account.age, LIST[i].account.sex,
			LIST[i].account.idNumber, LIST[i].account.balance, LIST[i].account.ID, LIST[i].account.password,
			LIST[i].account.date.year, LIST[i].account.date.month, LIST[i].account.date.day,
			LIST[i].account.date.hour, LIST[i].account.date.min, LIST[i].account.date.second);
	}
	//printf("\n注册信息记录重新保存成功!\n");
	//printf("\n\ncount = %d\n\n", count);
	fclose(fp);//BUG在此
	return;
}

⑤、菜单显示:

(1).登录界面

//登录界面
void menu01()
{
	printf("====================登录界面=================\n");
	printf("◆\t\t  1.注册账号\t\t   ◆\n");
	printf("◆\t\t  2.登录账号\t\t   ◆\n");
	printf("◆\t\t  3.退出程序\t\t   ◆\n");
	printf("=============================================\n");
	return;
}

(2).账务管理界面

//账务管理界面
void menu02()
{
	printf("====================账务管理=================\n");
	printf("■\t\t  0.退出登录\t\t   ■\n");
	printf("■\t\t  1.存款\t\t   ■\n");
	printf("■\t\t  2.取款\t\t   ■\n");
	printf("■\t\t  3.转账\t\t   ■\n");
	printf("■\t\t  4.账务查询\t\t   ■\n");
	printf("■\t\t  5.修改密码\t\t   ■\n");
	printf("=============================================\n");
}

(3).账户查询界面

//账户查询界面
void menu03()
{
	printf("====================账户查询=================\n");
	printf("◆\t\t  0.返回主菜单\t\t   ◆\n");
	printf("◆\t\t  1.余额查询\t\t   ◆\n");
	printf("◆\t\t  2.存款记录查询\t   ◆\n");
	printf("◆\t\t  3.取款记录查询\t   ◆\n");
	printf("◆\t\t  4.转账记录查询\t   ◆\n");
	printf("◆\t\t  5.所有记录查询\t   ◆\n");
	printf("◆\t\t  6.个人信息查询\t   ◆\n");
	printf("=============================================\n");
	return;
}

⑥、输入的指令处理:

(1).登录界面的指令处理

//登录注册界面指令处理
void keyDown01()
{
	int hit;
	printf("请输入你的选择:");
	scanf("%d", &hit);
	getchar();
	switch (hit)
	{
	case 1:
		signin();
		break;
	case 2:
		if (login() == 1)//如果登录成功,则进入子菜单二,   账务管理 --------查询部分
		{
			while (1)
			{
				system("pause");
				system("cls");
				menu02();
				if (keyDown02() == 1)//退出登录,返回登录界面
				{
					break;
				}
			}
		}
		break;
	case 3:
		printf("\n正常退出!\n");
		exit(-1);
		break;
	default:
		printf("\n输入错误指令!请重新输入!\n");
		system("pause");
		system("cls");
		menu01();
		break;
	}
}

(2).账务管理界面指令处理

//账务管理指令处理
int keyDown02()
{
	int hit;
	printf("请输入您的选择:");
	scanf("%d", &hit);
	getchar();
	switch (hit)
	{
	case 0:
		return 1;//返回主菜单的标记 
		break;
	case 1:
		deposit();//存款
		break;
	case 2:
		withdrawal();//取款
		break;
	case 3:
		transferAccount();//转账
		break;
	case 4:
		while (1)
		{
			system("pause");
			system("cls");
			menu03();
			if (keyDown03() == 1)
			{
				break;
			}
		}
		break;
	case 5:
		modifyPassword();//修改密码
		break;
	default:
		printf("\n输入错误指令!请重新输入!\n");
		system("pause");
		system("cls");
		menu02();
		break;
	}
	return 0;
}

(3).账户查询界面的指令处理

//查询指令处理
int keyDown03()
{
	int hit;
	printf("请输入你的选择:");
	scanf("%d", &hit);
	getchar();
	switch (hit)
	{
	case 0:
		return 1;//返回主菜单操作
		break;
	case 1:
		printf("\n当前账户的余额是:%d 元\n\n", LIST[curIndex].account.balance);//查询余额
		break;
	case 2:
		searchRecord("存款");//查询存款记录
		break;
	case 3:
		searchRecord("取款");//查询取款记录
		break;
	case 4:
		searchRecord("转账");//查询转账记录
		break;
	case 5:
		travelList(&LIST[curIndex]);//查询所有交易记录
		break;
	case 6:
		printf("\n当前账户的个人信息如下:\n");
		printf("\n姓名   年龄    性别    身份证号    余额    账号    密码    开户时间\n");
		printf("%s\t%d\t%s\t%s\t%d\t%s\t%s\t%d-%d-%d %d:%d:%d\n",
			LIST[curIndex].account.name, LIST[curIndex].account.age, LIST[curIndex].account.sex,
			LIST[curIndex].account.idNumber, LIST[curIndex].account.balance,
			LIST[curIndex].account.ID, LIST[curIndex].account.password,
			LIST[curIndex].account.date.year, LIST[curIndex].account.date.month, LIST[curIndex].account.date.day,
			LIST[curIndex].account.date.hour, LIST[curIndex].account.date.min, LIST[curIndex].account.date.second);		
		break;
	default:
		printf("\n输入错误指令!请重新输入!\n");
		system("pause");
		system("cls");
		menu03();
		break;
	}
	return 0;
}

⑦、链表建立部分

(1).创建单链表`

//创建单链表
List* creatList()
{
	List* list;
	do
	{
		list = (List*)malloc(sizeof(List));
	} while (list == NULL);

	list->size = 0;
	list->pHead = creatHeadNode();
	return list;
}

(2).创建链表的头节点

//创建链表的头节点
dealNode* creatHeadNode()
{
	dealNode* headNode;
	do
	{
		headNode = (dealNode*)malloc(sizeof(dealNode));
	} while (headNode == NULL);

	headNode->next = NULL;
	return headNode;
}

(3).创建交易信息记录节点

//创建交易信息记录节点
dealNode* creatListNode(Data data)
{
	dealNode* newNode = (dealNode*)malloc(sizeof(dealNode));
	newNode->data = data;
	newNode->next = NULL;
	return newNode;
}

(4).有头链表的尾插法

//有头链表的尾插法
void insertByTail(List* list, dealNode * newNode)
{
	if (list->pHead == NULL)
	{
		perror("\n链表创建失败!\n");
		return;
	}
	dealNode* pTail = list->pHead;
	while (pTail->next != NULL)
	{
		pTail = pTail->next;
	}
	pTail->next = newNode;
	list->size++;
	return;
}

⑧、账户操作部分

(1).查找账户

//查找账户
int searchList(char* ID)   
{
	int i;
	for (i = 0; i < count; i++)
	{
		if (strcmp(LIST[i].account.ID, ID) == 0)
		{
			return i;//返回链表的索引
		}
	}
	return -1;;
}

(2).是否继续

//是否继续
int isContinue()
{
	char sle;
	printf("是否继续操作(y/n):");
	scanf("%c", &sle);
	getchar();
	if (sle != 'y' && sle != 'Y')//取消操作
	{
		printf("\n操作取消!\n");
		return 0;
	}
	return 1;
}

(3).存款

//存款
void deposit()
{
NEXT03:
	printf("请输入存款金额(0<=x<=1000,以50为基本单位):");
	int money;
	scanf("%d", &money);
	getchar();
	if (money % 50 != 0 || money < 0 || money > 1000)
	{
		printf("\n存款金额不符合条件!\n");
		if (isContinue())
		{
			goto NEXT03;
		}
		return;
	}
	else
	{
		LIST[curIndex].account.balance += money;
		//进行存款,需要对登录账户的链表进行操作
		//对本账户的操作
		time_t timep;//时间
		struct tm* p;
		time(&timep);
		p = gmtime(&timep);//获取当前时间

		Data data;
		data.date.year = 1900 + p->tm_year;
		data.date.month = 1 + p->tm_mon;
		data.date.day = p->tm_mday;
		data.date.hour = 8 + p->tm_hour;
		data.date.min = p->tm_min;
		data.date.second = p->tm_sec;

		data.money = money;
		strcpy(data.tradingObject, LIST[curIndex].account.ID);
		strcpy(data.type, "存款");
		dealNode* newNode = creatListNode(data);
		insertByTail(&LIST[curIndex], newNode);
		updateRecord(&LIST[curIndex]);//更新交易记录
		saveListMes();//更新注册表信息
		printf("\n\n存款成功!\n\n");
	}
	return;
}

(4).取款

//取款
void withdrawal()
{
NEXT05:
	printf("请输入取款金额(100<=x<=2000,以50为基本单位):");
	int money;
	scanf("%d", &money);
	getchar();
	if (money % 50 != 0 || money < 100 || money > 2000)
	{
		printf("\n取款金额不符合条件!\n\n");
		if (isContinue())
		{
			goto NEXT05;
		}
	}
	else if (LIST[curIndex].account.balance < money)
	{
		printf("\n账户余额不足!无法取款!\n\n");
		if (isContinue())
		{
			goto NEXT05;
		}
	}
	else
	{
		LIST[curIndex].account.balance -= money;
		//进行取款,需要对登录账户的链表进行操作
		//对本账户的操作
		time_t timep;//时间
		struct tm* p;
		time(&timep);
		p = gmtime(&timep);//获取当前时间

		Data data;
		data.date.year = 1900 + p->tm_year;
		data.date.month = 1 + p->tm_mon;
		data.date.day = p->tm_mday;
		data.date.hour = 8 + p->tm_hour;
		data.date.min = p->tm_min;
		data.date.second = p->tm_sec;

		data.money = money;
		strcpy(data.tradingObject, LIST[curIndex].account.ID);
		strcpy(data.type, "取款");
		dealNode* newNode = creatListNode(data);
		insertByTail(&LIST[curIndex], newNode);
		updateRecord(&LIST[curIndex]);//更新交易记录
		saveListMes();//更新注册表信息
		printf("\n\n取款成功!\n\n");
	}
	return;
}

(5).转账

//转账
void transferAccount()
{
	printf("请输入交易对象的账户:");
	char tradingObject[20];
	scanf("%s", tradingObject);
	getchar();
	int index = searchList(tradingObject);
	if (index == -1)
	{
		printf("\n未找到该账户,转账失败!\n");
		return;
	}
NEXT02:
	//找到该账户后
	printf("请输入转账金额(以50为基本单位,100<=x<=5000):");
	int money;
	scanf("%d", &money);
	getchar();

	if (money % 50 != 0 || money < 100 || money > 5000)
	{
		printf("输入金额不符合条件!转账失败!\n");
		if (isContinue())//判断是否继续
		{
			goto NEXT02;
		}
	}
	else if (LIST[curIndex].account.balance < money)
	{
		printf("余额不足!当前账户余额:%d\n", LIST[curIndex].account.balance);
		if (isContinue())//判断是否继续
		{
			goto NEXT02;
		}
	}
	else
	{
		printf("交易对象的姓名是:%s\n", LIST[index].account.name);
		if (isContinue())//判断是否继续
		{
			LIST[index].account.balance += money;
			LIST[curIndex].account.balance -= money;
			printf("\n\n转账成功!\n\n");
			//进行转账,需要对两个账户链表进行操作
			//对本账户的操作
			time_t timep;//时间
			struct tm* p;
			time(&timep);
			p = gmtime(&timep);//获取当前时间

			Data data;
			data.date.year = 1900 + p->tm_year;
			data.date.month = 1 + p->tm_mon;
			data.date.day = p->tm_mday;
			data.date.hour = 8 + p->tm_hour;
			data.date.min = p->tm_min;
			data.date.second = p->tm_sec;

			data.money = money;
			strcpy(data.tradingObject, LIST[index].account.ID);
			strcpy(data.type, "转账");
			dealNode* newNode = creatListNode(data);
			insertByTail(&LIST[curIndex], newNode);
			updateRecord(&LIST[curIndex]);//更新交易记录

			//对交易对象的账户的操作
			strcpy(data.tradingObject, LIST[curIndex].account.ID);
			strcpy(data.type, "存款");
			dealNode* newNode1 = creatListNode(data);
			insertByTail(&LIST[index], newNode1);
			updateRecord(&LIST[index]);//更新交易记录
			saveListMes();//更新注册表信息
		}
	}
	return;
}

(6).查询存款、取款、转账记录

//查询存款、取款、转账记录
void searchRecord(char * type)
{
	dealNode* pMove = LIST[curIndex].pHead->next;
	if (pMove == NULL)
	{
		printf("\n\n无交易记录!\n\n");
		return;
	}
	int flag = 1;
	while (pMove != NULL)
	{
		if (strcmp(pMove->data.type, type) == 0)
		{
			printf("%s\t%s\t%d\t%d-%d-%d %d:%d:%d\n", pMove->data.type, pMove->data.tradingObject, pMove->data.money,
				pMove->data.date.year, pMove->data.date.month, pMove->data.date.day,
				pMove->data.date.hour, pMove->data.date.min, pMove->data.date.second);
			flag = 0;
		}
		pMove = pMove->next;
	}
	if (flag)
	{
		printf("\n\n无%s记录\n\n", type);
	}
	return;
}

⑨、.查询所有交易记录

(1).查询存款、取款、转账记录

//查询存款、取款、转账记录
void searchRecord(char * type)
{
	dealNode* pMove = LIST[curIndex].pHead->next;
	if (pMove == NULL)
	{
		printf("\n\n无交易记录!\n\n");
		return;
	}
	int flag = 1;
	while (pMove != NULL)
	{
		if (strcmp(pMove->data.type, type) == 0)
		{
			printf("%s\t%s\t%d\t%d-%d-%d %d:%d:%d\n", pMove->data.type, pMove->data.tradingObject, pMove->data.money,
				pMove->data.date.year, pMove->data.date.month, pMove->data.date.day,
				pMove->data.date.hour, pMove->data.date.min, pMove->data.date.second);
			flag = 0;
		}
		pMove = pMove->next;
	}
	if (flag)
	{
		printf("\n\n无%s记录\n\n", type);
	}
	return;
}

(2).查询余额

	printf("\n当前账户的余额是:%d 元\n\n", LIST[curIndex].account.balance);//查询余额

(3).查询登录账户的个人信息

		printf("\n当前账户的个人信息如下:\n");
		printf("\n姓名   年龄    性别    身份证号    余额    账号    密码    开户时间\n");
		printf("%s\t%d\t%s\t%s\t%d\t%s\t%s\t%d-%d-%d %d:%d:%d\n",
			LIST[curIndex].account.name, LIST[curIndex].account.age, LIST[curIndex].account.sex,
			LIST[curIndex].account.idNumber, LIST[curIndex].account.balance,
			LIST[curIndex].account.ID, LIST[curIndex].account.password,
			LIST[curIndex].account.date.year, LIST[curIndex].account.date.month, LIST[curIndex].account.date.day,
			LIST[curIndex].account.date.hour, LIST[curIndex].account.date.min, LIST[curIndex].account.date.second);		

(4).查询所有交易记录

//遍历链表
void travelList(List* list)
{
	dealNode* pMove = list->pHead->next;
	if (pMove == NULL)
	{
		printf("\n%s账户中无交易信息!\n",list->account.name);
		return;
	}
	else
	{
		printf("\n%s的账户交易信息如下:\n", list->account.name);
		while (pMove != NULL)
		{
			printf("\n交易对象的账号:%s, 交易金额:%d, 交易时间:%d-%d-%d %d:%d:%d, 交易类型:%s\n",
				pMove->data.tradingObject, pMove->data.money, pMove->data.date.year, pMove->data.date.month, pMove->data.date.day,
				pMove->data.date.hour, pMove->data.date.min, pMove->data.date.second,pMove->data.type);
		}
		printf("\n");
	}
	return;
}

⑩、主函数框架

代码实现:

//主函数
int main()
{
	system("color f9");
	while (1)
	{
		menu01();
		keyDown01();
		system("pause");
		system("cls");
	}
	return 0;
}

五、运行效果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

六、完整代码

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <time.h>

# define MAX 1000//最多能够存储100个账户链表

/*
	时间:2020年7月27日21:08:35
	编译器: Visual Studio 2019
	操作系统:Windows 10 
	作者:K
*/

/*
	待优化:
	1.账户注册时需要排除重复账号
	2.登录时可以返回不登录操作
*/

//时间类型
typedef struct
{
	int year;//年
	int month;//月
	int day;//日
	int hour;//时
	int min;//分
	int second;//秒
}Date;

//账户结构体
typedef struct
{
	char ID[13];//账号
	char password[20];//密码
	char name[20];//姓名
	int age;//年龄
	char sex[5];//性别
	char idNumber[20];//身份证号码
	int balance;//余额
	Date date;//开户时间
	//char date[50];//开户时间
}Account;

//封装节点中的数据
typedef struct data
{
	char tradingObject[20];//交易对象的账号
	int money;//交易金额
	Date date;//交易时间
	char type[5];//交易类型
}Data;

//交易结构体
typedef struct dealNode
{
	Data data;//数据域
	struct dealNode* next;//指针域
}dealNode;

//单链表类型
typedef struct List
{
	int size;//链表数据长度
	Account account;//链表所属账户
	dealNode* pHead;//首节点
}List;

/*全局变量*/
List LIST[MAX];
int count = 0;//当前存储的账户个数
int curIndex = -1;//登录成功的账户的下标


/*函数声明*/

//注册登录部分
void signin();//注册
int login();//登录
void modifyPassword();//修改密码
void saveListMes();//账户信息保存

/*菜单和指令输入部分*/
void menu01();
void keyDown01();
void menu02();
int keyDown02();
void menu03();
int keyDown03();

/*链表部分*/
List* creatList();									//创建单链表
dealNode* creatHeadNode();							//创建链表的头节点
dealNode* creatListNode(Data data);					//创建交易信息节点
void insertByTail(List* list, dealNode* newNode);	//有头链表的尾插法
void travelList(List* list);						//遍历链表

/*账户操作部分*/
int searchList(char* ID);	//查找交易对象的账户
int isContinue();			//是否继续
void deposit();				//存款
void withdrawal();			//取款
void transferAccount();		//转账
void updateRecord(List * list);		//更新交易记录

/*查询部分*/
void searchRecord(char * type);	//查询各种记录


/*函数定义部分*/

//查找账户
int searchList(char* ID)   
{
	int i;
	for (i = 0; i < count; i++)
	{
		if (strcmp(LIST[i].account.ID, ID) == 0)
		{
			return i;//返回链表的索引
		}
	}
	return -1;;
}

//是否继续
int isContinue()
{
	char sle;
	printf("是否继续操作(y/n):");
	scanf("%c", &sle);
	getchar();
	if (sle != 'y' && sle != 'Y')//取消操作
	{
		printf("\n操作取消!\n");
		return 0;
	}
	return 1;
}

//创建单链表
List* creatList()
{
	List* list;
	do
	{
		list = (List*)malloc(sizeof(List));
	} while (list == NULL);

	list->size = 0;
	list->pHead = creatHeadNode();
	return list;
}

//创建链表的头节点
dealNode* creatHeadNode()
{
	dealNode* headNode;
	do
	{
		headNode = (dealNode*)malloc(sizeof(dealNode));
	} while (headNode == NULL);

	headNode->next = NULL;
	return headNode;
}

//创建交易信息记录节点
dealNode* creatListNode(Data data)
{
	dealNode* newNode = (dealNode*)malloc(sizeof(dealNode));
	newNode->data = data;
	newNode->next = NULL;
	return newNode;
}

//有头链表的尾插法
void insertByTail(List* list, dealNode * newNode)
{
	if (list->pHead == NULL)
	{
		perror("\n链表创建失败!\n");
		return;
	}
	dealNode* pTail = list->pHead;
	while (pTail->next != NULL)
	{
		pTail = pTail->next;
	}
	pTail->next = newNode;
	list->size++;
	return;
}

//遍历链表
void travelList(List* list)
{
	dealNode* pMove = list->pHead->next;
	if (pMove == NULL)
	{
		printf("\n%s账户中无交易信息!\n",list->account.name);
		return;
	}
	else
	{
		printf("\n%s的账户交易信息如下:\n", list->account.name);
		while (pMove != NULL)
		{
			printf("\n交易对象的账号:%s, 交易金额:%d, 交易时间:%d-%d-%d %d:%d:%d, 交易类型:%s\n",
				pMove->data.tradingObject, pMove->data.money, pMove->data.date.year, pMove->data.date.month, pMove->data.date.day,
				pMove->data.date.hour, pMove->data.date.min, pMove->data.date.second,pMove->data.type);
		}
		printf("\n");
	}
	return;
}

//注册
void signin()
{
	//注册账号密码   代码块
	char ID[13], password[20];
NEXT:
	printf("请输入12位的账号:");
	scanf("%s", ID);
	getchar();
	if (strlen(ID) != 12)
	{
		printf("\n账号不符合条件!请重新输入!\n");
		system("pause");
		system("cls");
		menu01();
		printf("请输入你的选择:1\n");
		goto NEXT;
	}
	printf("请输入不少于6位的密码:");

	int passLen = 0;
	char ch;

	while ((ch = _getch()) != '\r')
	{
		if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9' || ch == 8)
		{
			if (ch == 8)//如果想删除前面输入的一个数字
			{
				if (passLen > 0)
				{
					printf("\b \b");//实现删除一个字符    退格 空格清空字符 退格
					passLen--;
				}
			}
			else if (passLen <= 19)
			{
				printf("*");
				password[passLen++] = ch;
			}
		}
	}
	password[passLen] = '\0';
	printf("\n");
	if (passLen < 6)
	{
		passLen = 0;
		printf("\n密码少于6位!请重新输入!\n");
		system("pause");
		system("cls");
		menu01();
		goto NEXT;
	}

	//用户其他相关信息注册 代码块
	char name[20];
	int age;//年龄
	char sex[5];//性别
	char idNumber[20];//身份证号码
	int balance;//余额

	printf("请输入您的姓名:");
	scanf("%s", name);
	getchar();
	printf("请输入您的年龄:");
	scanf("%d", &age);
	getchar();
	printf("请输入您的性别:");
	scanf("%s", sex);
	getchar();
	int idLen;
	do
	{
		printf("请输入您的身份证号码(18位):");
		scanf("%s", idNumber);
		getchar();
		idLen = strlen(idNumber);
		if (idLen != 18)
		{
			printf("\n身份证号码不符合18位!请重新输入!\n");
		}
	} while (idLen != 18);
	printf("请输入账户初始余额:");
	scanf("%d", &balance);
	getchar();

	time_t timep;//时间
	struct tm* p;
	time(&timep);
	p = gmtime(&timep);//获取当前时间

	//文件保存
	FILE* fp = NULL;
NEXT01:
	fp = fopen("注册信息记录.txt", "rb+");
	if (fp == NULL)//如果文件不存在,则打开文件,打印标题
	{
		fp = fopen("注册信息记录.txt", "wb+");
		fprintf(fp, "姓名   年龄    性别    身份证号    余额    账号    密码    开户时间\n");
	}
	else//如果文件已经存在,则只打印标题
	{
		fclose(fp);
		fp = fopen("注册信息记录.txt", "ab+");
	}
	
	if (fp == NULL)
	{
		goto NEXT01;
	}

	fprintf(fp, "%s\t%d\t%s\t%s\t%d\t%s\t%s\t%d-%d-%d %d:%d:%d\n", 
		name,age,sex,idNumber,balance,ID, password, 
		1900+p->tm_year, 1+p->tm_mon,p->tm_mday, 8+p->tm_hour,p->tm_min,p->tm_sec);
	printf("\n账号注册成功!\n");
	fclose(fp);

	//创建新账户的交易记录文件
	char file[50];
	strcpy(file, ID);
	strcat(file, ".txt");
	FILE* fp1 = NULL;
	fp1 = fopen(file, "w");
	if (fp1 == NULL)
	{
		printf("\n%s的交易记录文件创建失败!\n", file);
		return;
	}
	fprintf(fp1, "%s\t%s\t%d\t%d-%d-%d %d:%d:%d\n", "存款", ID, balance,
		1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, 8 + p->tm_hour, p->tm_min, p->tm_sec);
	fclose(fp1);
	//可以考虑给每个注册成功的用户创建一个文件夹,存储账户信息记录文本
	//int status;
	//status = mkdir()

	return;
}

//登录
int login()
{
	char ID[13], password[20];
NEXT:
	printf("请输入12位的账号:");
	scanf("%s", ID);
	getchar();
	if (strlen(ID) != 12)
	{
		printf("\n账号不符合条件!请重新输入!\n");
		system("pause");
		system("cls");
		menu01();
		printf("请输入你的选择:2\n");
		goto NEXT;
	}
	printf("请输入不少于6位的密码:");

	char ch;
	int passLen = 0;

	while ((ch = _getch()) != '\r')
	{
		if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9' || ch == 8)
		{
			if (ch == 8)//如果想删除前面输入的一个数字
			{
				if (passLen > 0)
				{
					printf("\b \b");//实现删除一个字符   退格 空格清空字符 退格
					passLen--;
				}
			}
			else if (passLen <= 19)
			{
				printf("*");
				password[passLen++] = ch;
			}
		}
	}
	password[passLen] = '\0';
	printf("\n");
	if (passLen < 6)
	{
		passLen = 0;
		printf("\n密码少于6位!请重新输入!\n");
		system("pause");
		system("cls");
		menu01();
		printf("请输入你的选择:2\n");
		goto NEXT;
	}

	FILE* fp = NULL;
	if ((fp = fopen("注册信息记录.txt", "rb")) == NULL)
	{
		perror("\n账号密码文件打开错误!无法登录!\n");
		return 0;
	}  

	//清除文件的第一行
	char flash[1000];
	fgets(flash, 1000, fp);

	int flag = 0;//作为是否登录成功的标记
	count = 0;//注意每次加载文件时,都需要初始化账户的个数为0
	while (fscanf(fp, "%s\t%d\t%s\t%s\t%d\t%s\t%s\t%d-%d-%d %d:%d:%d\n",
		LIST[count].account.name, &LIST[count].account.age, LIST[count].account.sex, LIST[count].account.idNumber,
		&LIST[count].account.balance, LIST[count].account.ID, LIST[count].account.password,
		&LIST[count].account.date.year, &LIST[count].account.date.month, &LIST[count].account.date.day,
		&LIST[count].account.date.hour, &LIST[count].account.date.min, &LIST[count].account.date.second) != EOF)
	{
		if (strcmp(ID, LIST[count].account.ID) == 0 && strcmp(password, LIST[count].account.password) == 0)
		{
			/*fclose(fp);*/
			flag = 1;
		}

		//需要加载所有账户的交易记录的信息
		char file[50];
		strcpy(file, LIST[count].account.ID);
		strcat(file, ".txt");
		FILE* fp1 = NULL;
		fp1 = fopen(file, "rb");
		if (fp1 == NULL)
		{
			printf("\n%s的交易记录文件打开失败!\n", file);
			return 0;
		}

		/*自动加载所有账户的交易记录数据*/
		//加载保存在本地的文件数据
		//加载该账号的交易记录的数据到当前账户的链表中     交易类型  交易对象账户 交易金额 交易时间

		//加载当前索引的账户的交易信息
		LIST[count].pHead = creatHeadNode();
		Data data;
		while (fscanf(fp1, "%s\t%s\t%d\t%d-%d-%d %d:%d:%d\n", data.type, data.tradingObject, &data.money,
			&data.date.year, &data.date.month, &data.date.day, &data.date.hour, &data.date.min, &data.date.second) != EOF)
		{
			dealNode* newNode = creatListNode(data);
			insertByTail(&LIST[count], newNode);
		}
		fclose(fp1);

		count++;
	}
	fclose(fp);

	//判断是否登录成功,如果成功,则查找当前登录账户的索引
	if (flag == 1)
	{
		printf("\n登录成功!\n");
		int i;
		for (i = 0; i < count; i++)
		{
			if (strcmp(ID, LIST[i].account.ID) == 0)
			{
				curIndex = i;
			}
		}
		return 1;
	}
	
	printf("\n账号或密码错误!登录失败!\n");
	return 0;
}

//修改密码
void modifyPassword()
{
NEXT04:
	printf("\n\n请输入新密码:");
	char newPassword_1[20];
	scanf("%s", newPassword_1);
	getchar();

	printf("请再次输入新密码:");
	char newPassword_2[20];
	scanf("%s", newPassword_2);
	getchar();
	int flag = 0;
	//验证两次密码是否一致
	if (strcmp(newPassword_1, newPassword_2) != 0)
	{
		printf("\n两次输入密码不一致!无法修改!\n");
		if (isContinue())
		{
			goto NEXT04;
		}
	}
	else
	{
		//更新密码
		strcpy(LIST[curIndex].account.password, newPassword_1);
		//重新写入所有账户信息
		saveListMes();
	}
	return;
}

//保存账户信息
void saveListMes()
{
	FILE* fp = NULL;
	fp = fopen("注册信息记录.txt", "wb+");
	if (fp == NULL)
	{
		perror("\n注册信息记录文件打开错误!\n");
		return;
	}
	fprintf(fp, "姓名   年龄    性别    身份证号    余额    账号    密码    开户时间\n");

	int i;
	for (i = 0; i < count; i++)
	{
		fprintf(fp, "%s\t%d\t%s\t%s\t%d\t%s\t%s\t%d-%d-%d %d:%d:%d\n",
			LIST[i].account.name, LIST[i].account.age, LIST[i].account.sex,
			LIST[i].account.idNumber, LIST[i].account.balance, LIST[i].account.ID, LIST[i].account.password,
			LIST[i].account.date.year, LIST[i].account.date.month, LIST[i].account.date.day,
			LIST[i].account.date.hour, LIST[i].account.date.min, LIST[i].account.date.second);
	}
	//printf("\n注册信息记录重新保存成功!\n");
	//printf("\n\ncount = %d\n\n", count);
	fclose(fp);//BUG在此
	return;
}

//保存交易信息
void updateRecord(List * list)
{
	char file[50];
	strcpy(file, list->account.ID);
	strcat(file, ".txt");
	FILE* fp = NULL;
	fp = fopen(file, "ab+");
	if (fp == NULL)
	{
		printf("\n%s的交易记录文件创建失败!\n", file);
		return;
	}
	dealNode* pMove = list->pHead->next;
	while (pMove->next != NULL)
	{
		pMove = pMove->next;
	}
	fprintf(fp, "%s\t%s\t%d\t%d-%d-%d %d:%d:%d\n", pMove->data.type, pMove->data.tradingObject, pMove->data.money,
		pMove->data.date.year, pMove->data.date.month, pMove->data.date.day,
		pMove->data.date.hour, pMove->data.date.min, pMove->data.date.second);
	fclose(fp);
	return;
}

//存款
void deposit()
{
NEXT03:
	printf("请输入存款金额(0<=x<=1000,以50为基本单位):");
	int money;
	scanf("%d", &money);
	getchar();
	if (money % 50 != 0 || money < 0 || money > 1000)
	{
		printf("\n存款金额不符合条件!\n");
		if (isContinue())
		{
			goto NEXT03;
		}
		return;
	}
	else
	{
		LIST[curIndex].account.balance += money;
		//进行存款,需要对登录账户的链表进行操作
		//对本账户的操作
		time_t timep;//时间
		struct tm* p;
		time(&timep);
		p = gmtime(&timep);//获取当前时间

		Data data;
		data.date.year = 1900 + p->tm_year;
		data.date.month = 1 + p->tm_mon;
		data.date.day = p->tm_mday;
		data.date.hour = 8 + p->tm_hour;
		data.date.min = p->tm_min;
		data.date.second = p->tm_sec;

		data.money = money;
		strcpy(data.tradingObject, LIST[curIndex].account.ID);
		strcpy(data.type, "存款");
		dealNode* newNode = creatListNode(data);
		insertByTail(&LIST[curIndex], newNode);
		updateRecord(&LIST[curIndex]);//更新交易记录
		saveListMes();//更新注册表信息
		printf("\n\n存款成功!\n\n");
	}
	return;
}

//取款
void withdrawal()
{
NEXT05:
	printf("请输入取款金额(100<=x<=2000,以50为基本单位):");
	int money;
	scanf("%d", &money);
	getchar();
	if (money % 50 != 0 || money < 100 || money > 2000)
	{
		printf("\n取款金额不符合条件!\n\n");
		if (isContinue())
		{
			goto NEXT05;
		}
	}
	else if (LIST[curIndex].account.balance < money)
	{
		printf("\n账户余额不足!无法取款!\n\n");
		if (isContinue())
		{
			goto NEXT05;
		}
	}
	else
	{
		LIST[curIndex].account.balance -= money;
		//进行取款,需要对登录账户的链表进行操作
		//对本账户的操作
		time_t timep;//时间
		struct tm* p;
		time(&timep);
		p = gmtime(&timep);//获取当前时间

		Data data;
		data.date.year = 1900 + p->tm_year;
		data.date.month = 1 + p->tm_mon;
		data.date.day = p->tm_mday;
		data.date.hour = 8 + p->tm_hour;
		data.date.min = p->tm_min;
		data.date.second = p->tm_sec;

		data.money = money;
		strcpy(data.tradingObject, LIST[curIndex].account.ID);
		strcpy(data.type, "取款");
		dealNode* newNode = creatListNode(data);
		insertByTail(&LIST[curIndex], newNode);
		updateRecord(&LIST[curIndex]);//更新交易记录
		saveListMes();//更新注册表信息
		printf("\n\n取款成功!\n\n");
	}
	return;
}

//转账
void transferAccount()
{
	printf("请输入交易对象的账户:");
	char tradingObject[20];
	scanf("%s", tradingObject);
	getchar();
	int index = searchList(tradingObject);
	if (index == -1)
	{
		printf("\n未找到该账户,转账失败!\n");
		return;
	}
NEXT02:
	//找到该账户后
	printf("请输入转账金额(以50为基本单位,100<=x<=5000):");
	int money;
	scanf("%d", &money);
	getchar();

	if (money % 50 != 0 || money < 100 || money > 5000)
	{
		printf("输入金额不符合条件!转账失败!\n");
		if (isContinue())//判断是否继续
		{
			goto NEXT02;
		}
	}
	else if (LIST[curIndex].account.balance < money)
	{
		printf("余额不足!当前账户余额:%d\n", LIST[curIndex].account.balance);
		if (isContinue())//判断是否继续
		{
			goto NEXT02;
		}
	}
	else
	{
		printf("交易对象的姓名是:%s\n", LIST[index].account.name);
		if (isContinue())//判断是否继续
		{
			LIST[index].account.balance += money;
			LIST[curIndex].account.balance -= money;
			printf("\n\n转账成功!\n\n");
			//进行转账,需要对两个账户链表进行操作
			//对本账户的操作
			time_t timep;//时间
			struct tm* p;
			time(&timep);
			p = gmtime(&timep);//获取当前时间

			Data data;
			data.date.year = 1900 + p->tm_year;
			data.date.month = 1 + p->tm_mon;
			data.date.day = p->tm_mday;
			data.date.hour = 8 + p->tm_hour;
			data.date.min = p->tm_min;
			data.date.second = p->tm_sec;

			data.money = money;
			strcpy(data.tradingObject, LIST[index].account.ID);
			strcpy(data.type, "转账");
			dealNode* newNode = creatListNode(data);
			insertByTail(&LIST[curIndex], newNode);
			updateRecord(&LIST[curIndex]);//更新交易记录

			//对交易对象的账户的操作
			strcpy(data.tradingObject, LIST[curIndex].account.ID);
			strcpy(data.type, "存款");
			dealNode* newNode1 = creatListNode(data);
			insertByTail(&LIST[index], newNode1);
			updateRecord(&LIST[index]);//更新交易记录
			saveListMes();//更新注册表信息
		}
	}
	return;
}

//查询存款、取款、转账记录
void searchRecord(char * type)
{
	dealNode* pMove = LIST[curIndex].pHead->next;
	if (pMove == NULL)
	{
		printf("\n\n无交易记录!\n\n");
		return;
	}
	int flag = 1;
	while (pMove != NULL)
	{
		if (strcmp(pMove->data.type, type) == 0)
		{
			printf("%s\t%s\t%d\t%d-%d-%d %d:%d:%d\n", pMove->data.type, pMove->data.tradingObject, pMove->data.money,
				pMove->data.date.year, pMove->data.date.month, pMove->data.date.day,
				pMove->data.date.hour, pMove->data.date.min, pMove->data.date.second);
			flag = 0;
		}
		pMove = pMove->next;
	}
	if (flag)
	{
		printf("\n\n无%s记录\n\n", type);
	}
	return;
}


//登录注册界面
void keyDown01()
{
	int hit;
	printf("请输入你的选择:");
	scanf("%d", &hit);
	getchar();
	switch (hit)
	{
	case 1:
		signin();
		break;
	case 2:
		if (login() == 1)//如果登录成功,则进入子菜单二,   账务管理 --------查询部分
		{
			while (1)
			{
				system("pause");
				system("cls");
				menu02();
				if (keyDown02() == 1)//退出登录,返回登录界面
				{
					break;
				}
			}
		}
		break;
	case 3:
		printf("\n正常退出!\n");
		exit(-1);
		break;
	default:
		printf("\n输入错误指令!请重新输入!\n");
		system("pause");
		system("cls");
		menu01();
		break;
	}
}

//账务管理指令处理
int keyDown02()
{
	int hit;
	printf("请输入您的选择:");
	scanf("%d", &hit);
	getchar();
	switch (hit)
	{
	case 0:
		return 1;//返回主菜单的标记 
		break;
	case 1:
		deposit();//存款
		break;
	case 2:
		withdrawal();//取款
		break;
	case 3:
		transferAccount();//转账
		break;
	case 4:
		while (1)
		{
			system("pause");
			system("cls");
			menu03();
			if (keyDown03() == 1)
			{
				break;
			}
		}
		break;
	case 5:
		modifyPassword();//修改密码
		break;
	default:
		printf("\n输入错误指令!请重新输入!\n");
		system("pause");
		system("cls");
		menu02();
		break;
	}
	return 0;
}

//查询指令处理
int keyDown03()
{
	int hit;
	printf("请输入你的选择:");
	scanf("%d", &hit);
	getchar();
	switch (hit)
	{
	case 0:
		return 1;//返回主菜单操作
		break;
	case 1:
		printf("\n当前账户的余额是:%d 元\n\n", LIST[curIndex].account.balance);//查询余额
		break;
	case 2:
		searchRecord("存款");//查询存款记录
		break;
	case 3:
		searchRecord("取款");//查询取款记录
		break;
	case 4:
		searchRecord("转账");//查询转账记录
		break;
	case 5:
		travelList(&LIST[curIndex]);//查询所有交易记录
		break;
	case 6:
		printf("\n当前账户的个人信息如下:\n");
		printf("\n姓名   年龄    性别    身份证号    余额    账号    密码    开户时间\n");
		printf("%s\t%d\t%s\t%s\t%d\t%s\t%s\t%d-%d-%d %d:%d:%d\n",
			LIST[curIndex].account.name, LIST[curIndex].account.age, LIST[curIndex].account.sex,
			LIST[curIndex].account.idNumber, LIST[curIndex].account.balance,
			LIST[curIndex].account.ID, LIST[curIndex].account.password,
			LIST[curIndex].account.date.year, LIST[curIndex].account.date.month, LIST[curIndex].account.date.day,
			LIST[curIndex].account.date.hour, LIST[curIndex].account.date.min, LIST[curIndex].account.date.second);		
		break;
	default:
		printf("\n输入错误指令!请重新输入!\n");
		system("pause");
		system("cls");
		menu03();
		break;
	}
	return 0;
}

//登录界面
void menu01()
{
	printf("====================登录界面=================\n");
	printf("◆\t\t  1.注册账号\t\t   ◆\n");
	printf("◆\t\t  2.登录账号\t\t   ◆\n");
	printf("◆\t\t  3.退出程序\t\t   ◆\n");
	printf("=============================================\n");
	return;
}

//账务管理界面
void menu02()
{
	printf("====================账务管理=================\n");
	printf("■\t\t  0.退出登录\t\t   ■\n");
	printf("■\t\t  1.存款\t\t   ■\n");
	printf("■\t\t  2.取款\t\t   ■\n");
	printf("■\t\t  3.转账\t\t   ■\n");
	printf("■\t\t  4.账务查询\t\t   ■\n");
	printf("■\t\t  5.修改密码\t\t   ■\n");
	printf("=============================================\n");
}

//账户查询界面
void menu03()
{
	printf("====================账户查询=================\n");
	printf("◆\t\t  0.返回主菜单\t\t   ◆\n");
	printf("◆\t\t  1.余额查询\t\t   ◆\n");
	printf("◆\t\t  2.存款记录查询\t   ◆\n");
	printf("◆\t\t  3.取款记录查询\t   ◆\n");
	printf("◆\t\t  4.转账记录查询\t   ◆\n");
	printf("◆\t\t  5.所有记录查询\t   ◆\n");
	printf("◆\t\t  6.个人信息查询\t   ◆\n");
	printf("=============================================\n");
	return;
}

//主函数
int main()
{
	system("color f9");
	while (1)
	{
		menu01();
		keyDown01();
		system("pause");
		system("cls");
	}
	return 0;
}

如果有啥问题可以留言交流,我一定及时回复;

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值