ATM管理系统

这个作业属于哪个课程 计算机18级
这个作业要求在哪里 ATM管理系统
学号 3180301230

目录

题目要求

编写一个ATM管理系统,语言不限,要求应包括以下主要功能:

(1)开户,销户

(2)查询账户余额

(3)存款

(4)取款

(5)转账(一个账户转到另一个账户)等...

允许网上查询参考,但请注意不要直接抄袭,可以理解看懂别人的代码,再自己编写

函数说明

账户结构体

typedef struct									//定义账户结构体
{
	int id;
	int password;
	float money;
}account;

创建账户

void create(account user[],int n)				//创建账户
{	
	user[n].id = user[n - 1].id + 1;			//自动生成用户卡号
	printf("卡号为:%d\n", user[n].id);
	printf("请输入密码:");
	scanf_s("%d", &user[n].password);
	user[n].money = 0;							//初始化存款为0;
}

注销账户

int cancel(account user[], int n)			    //注销账户
{
	int cancelid, cancelpw;
	printf("请输入需要注销的账号:");
	scanf_s("%d", &cancelid);
	for (int i = 0; i <= n + 1; i++)
	{
		if (user[i].id == cancelid)				//寻找需要注销的账户
		{
			for (int j = 0; j != 1;)
			{
				printf("请输入密码:");
				scanf_s("%d", &cancelpw);		//密码匹配
				if (user[i].password == cancelpw)
				{
					user[i].id = 0;				//重置账户状态
					user[i].password = 0;
					user[i].money = 0;
					printf("销户成功!\n");
					return 0;
				}
				else
				{
					printf("密码错误!\n");				//输错密码提示及反馈
					printf("是否重输密码?Y/N\n");
					char flag;
					scanf_s("%c", &flag, 1);
					if (flag == 'n' || flag == 'N') return 1;
				}
			}
		}
	}
}

查询余额

int query(account user[], int n)				//查询余额
{
	int queryid, querypw;
	printf("请输入需要查询余额的账号:");
	scanf_s("%d", &queryid);
	for (int i = 0; i <= n + 1; i++)
	{
		if (user[i].id == queryid)
		{
			for (int j = 0; j != 1;)
			{
				printf("请输入密码:");
				scanf_s("%d", &querypw);
				if (user[i].password == querypw)
				{
					printf("账户的余额为:%f\n", user[i].money);
					return 0;
				}
				else
				{
					printf("密码错误!\n");
					printf("是否重输密码?Y/N\n");
					char flag;
					scanf_s("%c", &flag, 1);
					if (flag == 'n' || flag == 'N') return 1;
				}
			}
		}
	}
}

存款函数

int save(account user[], int n)				//存款函数
{
	int saveid, savepw;
	printf("请输入需要存款的账号:");
	scanf_s("%d", &saveid);
	for (int i = 0; i <= n + 1; i++)
	{
		if (user[i].id == saveid)
		{
			for (int j = 0; j != 1;)
			{
				printf("请输入密码:");
				scanf_s("%d", &savepw);
				if (user[i].password == savepw)
				{
					printf("请输入存款数额:\n");
					float addmoney;
					scanf_s("%f", &addmoney);
					user[i].money += addmoney;				//将存入钱款加入存款中
					printf("存款成功!,当前余额为:%f", user[i].money);
					return 0;
				}
				else
				{
					printf("密码错误!\n");
					printf("是否重输密码?Y/N\n");
					char flag;
					scanf_s("%c", &flag, 1);
					if (flag == 'n' || flag == 'N') return 1;
				}
			}
		}
	}
}

取款函数

int draw(account user[], int n)							//取款函数
{
	int drawid, drawpw;
	printf("请输入需要取款的账号:");
	scanf_s("%d", &drawid);
	for (int i = 0; i <= n + 1; i++)
	{
		if (user[i].id == drawid)
		{
			for (int j = 0; j != 1;)
			{
				printf("请输入密码:");
				scanf_s("%d", &drawpw);
				if (user[i].password == drawpw)
				{
					printf("请输入取款数额:\n");
					float addmoney;
					scanf_s("%f", &addmoney);
					user[i].money -= addmoney;				//将存款中的取款金额减去
					printf("取款成功!,当前余额为:%f", user[i].money);
					return 0;
				}
				else
				{
					printf("密码错误!\n");
					printf("是否重输密码?Y/N\n");
					char flag;
					scanf_s("%c", &flag,1);
					if (flag == 'n' || flag == 'N') return 1;
				}
			}
		}
	}
}

转存钱款

int transfer(account user[], int n)							//转存钱款
{
	int transferid1, transferid2,transferpw;
	printf("请输入需要取款的账号:");
	scanf_s("%d", &transferid1);
	for (int i = 0; i <= n + 1; i++)
	{
		if (user[i].id == transferid1)
		{
			for (int j = 0; j != 1;)
			{
				printf("请输入密码:");
				scanf_s("%d", &transferpw);
				if (user[i].password == transferpw)
				{
					printf("请输入所要转入的账户卡号:\n");
					scanf_s("%d", &transferid2);
					printf("请输入转入数额:\n");
					float tranmoney;
					scanf_s("%f", &tranmoney);
					user[i].money -= tranmoney;
					for (int k = 0; k <= n + 1; k++)				//寻找被转入账户
					{
						if (user[k].id == transferid2)
						{
							user[k].money += tranmoney;
							k = n + 2;
						}
					}
					printf("转钱成功!,当前账户余额为:%f", user[i].money);
					return 0;
				}
				else
				{
					printf("密码错误!\n");
					printf("是否重输密码?Y/N\n");
					char flag;
					scanf_s("%c", &flag, 1);
					if (flag == 'n' || flag == 'N') return 1;
				}
			}
		}
	}
}

主函数

int main()
{
	int n = 1,choose;
	account user[100];
	user[0].id = 1000000;				//初始化第一个账户
	user[0].password = 0;
	user[0].money = 0;
	int end = 0;					 //是否结束,0记为不结束
	do {
		printf("请选择您需要进行的操作:\n1.开户\t2.销户\n3.查询当前余额\n4.存款\t5.取款\n6.转账\t0.退出\n");
		scanf_s("%d", &choose);
		switch (choose)
		{
		case 0:
			exit(0);
		case 1:
			create(user, n); n++; break;
		case 2:
			if (cancel(user, n) == 0) {
				n--; break;			//n相当于指针,此处能让下次开户正常进行
			}
			else n++; break;
		case 3:
			query(user, n); n++; break;
		case 4:
			save(user, n); n++; break;
		case 5:
			draw(user, n); n++; break;
		case 6:
			transfer(user, n); n++; break;
		default:
			break;
		}printf("请问您是否需要继续进行其他操作?输入1继续进行其他操作,输入0则退出\n");
		scanf_s("%d", &end);
		if (end == 1)system("cls");
	} while (end);
}

小结

psp 任务内容 计划完成需要的时间(min) 实际完成需要的时间(min)
Planning 计划 5 5
Estimate 估计这个任务需要多少时间,并规划大致工作步骤 10 10
Development 开发 200 180
Analysis 需求分析(包括学习新技术) 20 40
Design Spec 生成设计文档 15 10
Design Review 设计复审 10 15
Coding Standard 代码规范 5 5
Design 具体设计 20 40
Coding 具体编码 200 180
Code Review 代码复审 20 15
Test 测试(自我测试,修改代码,提交修改) 60 60
Reporting 报告 5 5
Test Report 测试报告 5 5
Size Measurement 计算工作量 20 25
Postmortem & Process Improvement Plan 事后总结,并提出过程改进计划 40 90

源码

#include <iostream>
#include <vector>
typedef struct									//定义账户结构体
{
	int id;
	int password;
	float money;
}account;
void create(account user[],int n)				//创建账户
{	
	user[n].id = user[n - 1].id + 1;			//自动生成用户卡号
	printf("卡号为:%d\n", user[n].id);
	printf("请输入密码:");
	scanf_s("%d", &user[n].password);
	user[n].money = 0;							//初始化存款为0;
}
int cancel(account user[], int n)			    //注销账户
{
	int cancelid, cancelpw;
	printf("请输入需要注销的账号:");
	scanf_s("%d", &cancelid);
	for (int i = 0; i <= n + 1; i++)
	{
		if (user[i].id == cancelid)				//寻找需要注销的账户
		{
			for (int j = 0; j != 1;)
			{
				printf("请输入密码:");
				scanf_s("%d", &cancelpw);		//密码匹配
				if (user[i].password == cancelpw)
				{
					user[i].id = 0;				//重置账户状态
					user[i].password = 0;
					user[i].money = 0;
					printf("销户成功!\n");
					return 0;
				}
				else
				{
					printf("密码错误!\n");				//输错密码提示及反馈
					printf("是否重输密码?Y/N\n");
					char flag;
					scanf_s("%c", &flag, 1);
					if (flag == 'n' || flag == 'N') return 1;
				}
			}
		}
	}
}
int query(account user[], int n)				//查询余额
{
	int queryid, querypw;
	printf("请输入需要查询余额的账号:");
	scanf_s("%d", &queryid);
	for (int i = 0; i <= n + 1; i++)
	{
		if (user[i].id == queryid)
		{
			for (int j = 0; j != 1;)
			{
				printf("请输入密码:");
				scanf_s("%d", &querypw);
				if (user[i].password == querypw)
				{
					printf("账户的余额为:%f\n", user[i].money);
					return 0;
				}
				else
				{
					printf("密码错误!\n");
					printf("是否重输密码?Y/N\n");
					char flag;
					scanf_s("%c", &flag, 1);
					if (flag == 'n' || flag == 'N') return 1;
				}
			}
		}
	}
}
int save(account user[], int n)				//存款函数
{
	int saveid, savepw;
	printf("请输入需要存款的账号:");
	scanf_s("%d", &saveid);
	for (int i = 0; i <= n + 1; i++)
	{
		if (user[i].id == saveid)
		{
			for (int j = 0; j != 1;)
			{
				printf("请输入密码:");
				scanf_s("%d", &savepw);
				if (user[i].password == savepw)
				{
					printf("请输入存款数额:\n");
					float addmoney;
					scanf_s("%f", &addmoney);
					user[i].money += addmoney;				//将存入钱款加入存款中
					printf("存款成功!,当前余额为:%f", user[i].money);
					return 0;
				}
				else
				{
					printf("密码错误!\n");
					printf("是否重输密码?Y/N\n");
					char flag;
					scanf_s("%c", &flag, 1);
					if (flag == 'n' || flag == 'N') return 1;
				}
			}
		}
	}
}
int draw(account user[], int n)							//取款函数
{
	int drawid, drawpw;
	printf("请输入需要取款的账号:");
	scanf_s("%d", &drawid);
	for (int i = 0; i <= n + 1; i++)
	{
		if (user[i].id == drawid)
		{
			for (int j = 0; j != 1;)
			{
				printf("请输入密码:");
				scanf_s("%d", &drawpw);
				if (user[i].password == drawpw)
				{
					printf("请输入取款数额:\n");
					float addmoney;
					scanf_s("%f", &addmoney);
					user[i].money -= addmoney;				//将存款中的取款金额减去
					printf("取款成功!,当前余额为:%f", user[i].money);
					return 0;
				}
				else
				{
					printf("密码错误!\n");
					printf("是否重输密码?Y/N\n");
					char flag;
					scanf_s("%c", &flag,1);
					if (flag == 'n' || flag == 'N') return 1;
				}
			}
		}
	}
}
int transfer(account user[], int n)							//转存钱款
{
	int transferid1, transferid2,transferpw;
	printf("请输入需要取款的账号:");
	scanf_s("%d", &transferid1);
	for (int i = 0; i <= n + 1; i++)
	{
		if (user[i].id == transferid1)
		{
			for (int j = 0; j != 1;)
			{
				printf("请输入密码:");
				scanf_s("%d", &transferpw);
				if (user[i].password == transferpw)
				{
					printf("请输入所要转入的账户卡号:\n");
					scanf_s("%d", &transferid2);
					printf("请输入转入数额:\n");
					float tranmoney;
					scanf_s("%f", &tranmoney);
					user[i].money -= tranmoney;
					for (int k = 0; k <= n + 1; k++)				//寻找被转入账户
					{
						if (user[k].id == transferid2)
						{
							user[k].money += tranmoney;
							k = n + 2;
						}
					}
					printf("转钱成功!,当前账户余额为:%f", user[i].money);
					return 0;
				}
				else
				{
					printf("密码错误!\n");
					printf("是否重输密码?Y/N\n");
					char flag;
					scanf_s("%c", &flag, 1);
					if (flag == 'n' || flag == 'N') return 1;
				}
			}
		}
	}
}
int main()
{
	int n = 1,choose;
	account user[100];
	user[0].id = 1000000;				//初始化第一个账户
	user[0].password = 0;
	user[0].money = 0;
	int end = 0;					 //是否结束,0记为不结束
	do {
		printf("请选择您需要进行的操作:\n1.开户\t2.销户\n3.查询当前余额\n4.存款\t5.取款\n6.转账\t0.退出\n");
		scanf_s("%d", &choose);
		switch (choose)
		{
		case 0:
			exit(0);
		case 1:
			create(user, n); n++; break;
		case 2:
			if (cancel(user, n) == 0) {
				n--; break;			//n相当于指针,此处能让下次开户正常进行
			}
			else n++; break;
		case 3:
			query(user, n); n++; break;
		case 4:
			save(user, n); n++; break;
		case 5:
			draw(user, n); n++; break;
		case 6:
			transfer(user, n); n++; break;
		default:
			break;
		}printf("请问您是否需要继续进行其他操作?输入1继续进行其他操作,输入0则退出\n");
		scanf_s("%d", &end);
		if (end == 1)system("cls");
	} while (end);
}
上一篇:ATM管理系统


下一篇:ATM管理系统