ATM管理系统

一、作业信息
[博客班级] 软件工程
[作业要求] 作业要求
[作业目标] 熟悉ATM机的运行系统并创建;
[学号] 318071334
二、题目要求
编写一个ATM管理系统,语言不限,要求应包括以下主要功能:
(1)开户,销户
(2)查询账户余额
(3)存款
(4)取款
(5)转账(一个账户转到另一个账户)等...
三、代码提交

#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;

typedef struct
{
	string name;			//用户名
	string password;		//密码
	string account;	 //账户
	float money;			//余额
}AccountNode;

typedef struct node
{
	AccountNode acc;
	struct node* next;
}Node;

void Menu();					//主菜单
void CreateAccount(Node*& head);		//注册账户
void Login(Node* head);				//登录
bool CloseAccount(Node*& head);			//注销账户
void LoginMenu();				//登录菜单
Node* Find(Node* head, string accountNumber);	//根据账号找客户

void Menu()//主菜单
{
	printf("\n\n\n\t\t\t\t\t *************************\n");
	printf("\t\t\t\t\t*\tATM管理系统\t *\n");
	printf("\t\t\t\t\t*\t  1.注册账户\t *\n");
	printf("\t\t\t\t\t*\t  2.登录\t *\n");
	printf("\t\t\t\t\t*\t  3.注销账户\t *\n");
	printf("\t\t\t\t\t*\t  4.退出\t *\n");
	printf("\t\t\t\t\t *************************\n");
	printf("\t\t\t\t\t\t\t请选择:");
}

void CreateAccount(Node*& head)
{
	printf("\n\n\n\t\t\t\t\t请输入您的姓名:");
	string name;
	cin >> name;

	printf("\n\t\t\t\t\t请设置您的银行卡密码:");
	string password;
	cin >> password;

	printf("\n\t\t\t\t\t请再次输入您的银行卡密码:");
	string repassword;
	cin >> repassword;

	//判断两次输入的密码是否一致
	while (password != repassword) 
	{
		printf("\n\t\t\t\t\t两次输入密码不一致,请重新输入:");
		cin >> repassword;
	}

	//随机生成银行账号
	char temp[20];//0000 0000 0000 0000 0 0
	string account;
	srand((unsigned int)time(NULL));
	sprintf(temp, "%d%d%d%d%d%d", rand() % 9000 + 1000, rand() % 9000 + 1000, rand() % 9000 + 1000, rand() % 9000 + 1000, rand() % 10, rand() % 10);//sprintf格式化字符串 
	account = temp;

	Node* pNode = new Node;
	pNode->acc.name = name;
	pNode->acc.password = password;
	pNode->acc.account = account;
	pNode->acc.money = 0;
	pNode->next = NULL;

	Node* p = head;
	while (p != NULL && p->next != NULL)
		p = p->next;
	if (head == NULL)
		head = pNode;
	else
		p->next = pNode;

	printf("\n\n\t\t\t\t\t恭喜您,开户成功!\n");
	cout << "\n\t\t\t\t\t您的账号为:" << account << endl;
}

void LoginMenu()
{
	printf("\n\n\n\t\t\t********************\n");
	printf("\t\t\t\t\t*\t  1.存款\t *\n");
	printf("\t\t\t\t\t*\t  2.取款\t *\n");
	printf("\t\t\t\t\t*\t  3.转账\t *\n");
	printf("\t\t\t\t\t*\t  4.查询余额\t *\n");
	printf("\t\t\t\t\t*\t  5.修改密码\t *\n");
	printf("\t\t\t\t\t*\t  6.退出\t *\n");
	printf("\t\t\t\t\t ********************\n");
	printf("\t\t\t\t\t\t\t请选择:");
}

void Login(Node* head)
{
	string account;
	string password;
	printf("\n\n\n\t\t\t\t\t请输入您的账号:");
	cin >> account;
	Node* p = Find(head, account);
	if (!p)
	{
		printf("\n\t\t\t\t\t账号输入有误!");
		return;
	}
	printf("\n\t\t\t\t\t请输入您的密码:");
	cin >> password;
	while (p->acc.password != password) 
	{
		printf("\n\t\t\t\t\t密码错误,请重新输入:");
		cin >> password;
	}
	while (1)
	{
		system("cls");
		LoginMenu();
		int choice;
		string otheraccount;
		double money;
		string newPassword;
		Node* temp;
		cin >> choice;
		switch (choice)
		{
		case 1:
			printf("\n\n\t\t\t\t\t请输入您的存款金额:");
			cin >> money;
			p->acc.money += money;
			printf("\n\t\t\t\t\t\t存款成功!\n");
			break;
		case 2:
			printf("\n\n\t\t\t\t\t请输入您的取款金额:");
			cin >> money;
			if (money > p->acc.money)
				printf("\n\t\t\t\t\t\t余额不足!\n");
			else {
				p->acc.money -= money;
				printf("\n\t\t\t\t\t\t取款成功!\n");
			}
			break;
		case 3:
			printf("\n\n\t\t\t\t\t请输入您的转账的账号:");
			cin >> otheraccount;
			printf("\n\t\t\t\t\t请输入您的转账金额:");
			cin >> money;
			temp = Find(head, otheraccount);
			if (!temp) {
				printf("\n\t\t\t\t\t账号输入有误!");
				system("pause");
				return;
			}
			p->acc.money -= money;
			temp->acc.money += money;
			printf("\n\t\t\t\t\t\t转账成功!\n");
			break;
		case 4:
			printf("\n\n\t\t\t\t\t您的余额为:%.2f\n", p->acc.money);
			break;
		case 5:
			printf("\n\n\t\t\t\t\t请输入您的新密码:");
			cin >> newPassword;
			p->acc.password = newPassword;
			printf("\n\t\t\t\t\t\t密码修改成功!\n");
			break;
		case 6:
			return;
		default:
			printf("\t\t\t\t\t\t\t输入有误!\n");
		}
		system("pause");
	}
}

Node* Find(Node* head, string account)
{
	Node* p = head;
	while (p != NULL) 
	{
		if (p->acc.account == account)
			break;
		p = p->next;
	}
	return p;
}

bool closeaccount(Node*& head)
{
	string account;
	printf("\n\n\t\t\t\t\t请输入您要注销的账号:");
	cin >> account;
	Node* p = head, * q;
	if (p != NULL && p->acc.account == account)
	{
		head = p->next;
		free(p);
		printf("\t\t\t\t\t\t\t注销成功!\n");
		return true;
	}
	q = p;
	p = p->next;
	while (p != NULL) {
		if (p->acc.account == account) 
		{
			q->next = p->next;
			free(p);
			printf("\t\t\t\t\t\t\t注销成功!\n");
			return true;
		}
		q = p;
	}
	return false;
}

int main()
{
	Node* head = NULL;

	while (1) 
	{
		system("cls");
		Menu();
		int choice;
		cin >> choice;
		switch (choice)
		{
		case 1:
			CreateAccount(head);
			break;
		case 2:
			Login(head);
			break;
		case 3:
			CloseAccount(head);
			break;
		case 4:
			return 0;
		default:
			printf("\t\t\t\t\t\t\t输入有误!\n");
		}
		system("pause");
	}
	return 0;
}

运行截图:





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

四、小结
本次aTm系统设计真是煞费苦心,大体的思路很清晰,但遇到文件的使用就直接gg了,通过这次的编码学到了很多。

posted @ 2020-11-18 23:47  Rasend  阅读(148)  评论(0编辑  收藏  举报