一、作业信息
[博客班级] 软件工程
[作业要求] 作业要求
[作业目标] 熟悉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("
*************************
");
printf(" * ATM管理系统 *
");
printf(" * 1.注册账户 *
");
printf(" * 2.登录 *
");
printf(" * 3.注销账户 *
");
printf(" * 4.退出 *
");
printf(" *************************
");
printf(" 请选择:");
}
void CreateAccount(Node*& head)
{
printf("
请输入您的姓名:");
string name;
cin >> name;
printf("
请设置您的银行卡密码:");
string password;
cin >> password;
printf("
请再次输入您的银行卡密码:");
string repassword;
cin >> repassword;
//判断两次输入的密码是否一致
while (password != repassword)
{
printf("
两次输入密码不一致,请重新输入:");
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("
恭喜您,开户成功!
");
cout << "
您的账号为:" << account << endl;
}
void LoginMenu()
{
printf("
********************
");
printf(" * 1.存款 *
");
printf(" * 2.取款 *
");
printf(" * 3.转账 *
");
printf(" * 4.查询余额 *
");
printf(" * 5.修改密码 *
");
printf(" * 6.退出 *
");
printf(" ********************
");
printf(" 请选择:");
}
void Login(Node* head)
{
string account;
string password;
printf("
请输入您的账号:");
cin >> account;
Node* p = Find(head, account);
if (!p)
{
printf("
账号输入有误!");
return;
}
printf("
请输入您的密码:");
cin >> password;
while (p->acc.password != password)
{
printf("
密码错误,请重新输入:");
cin >> password;
}
while (1)
{
system("cls");
LoginMenu();
int choice;
string otheraccount;
double money;
string newPassword;
Node* temp;
cin >> choice;
switch (choice)
{
case 1:
printf("
请输入您的存款金额:");
cin >> money;
p->acc.money += money;
printf("
存款成功!
");
break;
case 2:
printf("
请输入您的取款金额:");
cin >> money;
if (money > p->acc.money)
printf("
余额不足!
");
else {
p->acc.money -= money;
printf("
取款成功!
");
}
break;
case 3:
printf("
请输入您的转账的账号:");
cin >> otheraccount;
printf("
请输入您的转账金额:");
cin >> money;
temp = Find(head, otheraccount);
if (!temp) {
printf("
账号输入有误!");
system("pause");
return;
}
p->acc.money -= money;
temp->acc.money += money;
printf("
转账成功!
");
break;
case 4:
printf("
您的余额为:%.2f
", p->acc.money);
break;
case 5:
printf("
请输入您的新密码:");
cin >> newPassword;
p->acc.password = newPassword;
printf("
密码修改成功!
");
break;
case 6:
return;
default:
printf(" 输入有误!
");
}
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("
请输入您要注销的账号:");
cin >> account;
Node* p = head, * q;
if (p != NULL && p->acc.account == account)
{
head = p->next;
free(p);
printf(" 注销成功!
");
return true;
}
q = p;
p = p->next;
while (p != NULL) {
if (p->acc.account == account)
{
q->next = p->next;
free(p);
printf(" 注销成功!
");
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(" 输入有误!
");
}
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了,通过这次的编码学到了很多。