ATM管理系统
这个作业属于哪个课程 | https://edu.cnblogs.com/campus/ahgc/AHPU-SE-19/ |
---|---|
这个作业要求在哪里 | https://edu.cnblogs.com/campus/ahgc/AHPU-SE-19/homework/11477 |
这个作业的目标 | <编写一个ATM管理系统,语言不限> |
学号 | <3190704205> |
include
include
include
using namespace std;
struct Bank
{
char name[20];
char ID[20];
char password[20];
double money=0;
}User[100];
/定义用户人数/
int person = 0;
/定义当前用户的编号/
int use = 0;
int Startpage()
{
system("cls");
printf("\n 欢迎进入atm管理系统!\n\n");
printf("你可进行如下的操作\n\n\n\n");
printf("\t\t1.开户\n\n");
printf("\t\t2.销户\n\n");
printf("\t\t3.进入个人页面\n\n");
printf("\t\t4.退出\n\n");
return 0;
}
int Personpape()
{
system("cls");
printf("\n 你已进入个人界面,请进行你想要的操作!\n\n\n\n");
printf("\t\t1.存款\n\n");
printf("\t\t2.取款\n\n");
printf("\t\t3.转账\n\n");
printf("\t\t4.修改密码\n\n");
printf("\t\t5.返回上一级\n\n");
return 0;
}
void Newaccount()
{
system("cls");
int t=0;
person++;
char tpassword[20];
cout << "请输入新用户的姓名:" << endl;
cin >> User[person].name;
cout << "请输入新用户的身份证号码:" << endl;
cin >> User[person].ID;
while (strlen(User[person].ID) != 18)
{
cout << "你输入的身份证号不符合规格,请重新输入新用户的身份证号!" << endl;
cin >> User[person].ID;
}
cout << "请输入新用户的密码:" << endl;
cin >> tpassword;
while (strlen(tpassword)!=6)
{
cout << "你输入的密码不是六位数,请重新输入新用户的密码!" << endl;
cin >>tpassword;
}
strcpy_s(User[person].password, tpassword);
cout << "开户成功" << endl;
system("pause");
}
void Cancelaccount()
{
system("cls");
int a = 1,b=0,t=1;
double c = 0;
char tname[20];
char tpassword[20];
while (a==1)
{
cout << "请输入你想注销的用户姓名:" << endl;
cin >> tname;
for (int i = 1; i <= person; i++)
{
if (strcmp(User[i].name, tname) == 0)
{
a = 0;
t = i;
}
}
if (a==1)
{
cout << "无法查询你想注册的用户姓名:" << endl;
}
}
cout << "请输入用户的密码:" << endl;
cin >> tpassword;
while (strcmp(User[t].password,tpassword)!=0)
{
cout << "输入密码错误!" << endl;
cout << "请重新输入用户的密码:" << endl;
cin >> tpassword;
}
for (int j = 1; j <= person; j++)//通过循环删去数据
{
strcpy_s(User[j].name, User[j + 1].name);
strcpy_s(User[j].ID, User[j + 1].ID);
strcpy_s(User[j].password, User[j + 1].password);
c = User[j].money;
User[j].money = User[j + 1].money;
User[j + 1].money = c;
}
person--;
cout << "销户成功!" << endl;
system("pause");
}
void record()
{
system("cls");
int a = 1, b = 0, t = 1;
char tname[20];
char tpassword[20];
while (a == 1)
{
cout << "请输入你的用户姓名:" << endl;
cin >> tname;
for (int i = 1; i <= person; i++)
{
if (strcmp(User[i].name, tname) == 0)
{
a = 0;
t = i;
break;
}
}
if (a == 1)
{
cout << "无法查询你的用户姓名:" << endl;
continue;
}
cout << "请输入用户的密码:" << endl;
cin >> tpassword;
while (strcmp(User[t].password, tpassword) != 0)
{
cout << "输入密码错误!" << endl;
cout << "请重新输入用户的密码:" << endl;
cin >> tpassword;
}
}
use = t;
}
void deposit()
{
system("cls");
double t;
cout << "请输入你要存入的金额:" << endl;
cin >> t;
User[use].money += t;
cout << "存款成功!";
system("pause");
}
void withdrawit()
{
system("cls");
double t;
cout << "请输入你要取走的金额:" << endl;
cin >> t;
if (User[use].money >= t)
{
cout << "取款成功!";
User[use].money -= t;
}
else
{
cout << "输入金额超过存款,取款失败!";
}
system("pause");
}
void carryover()
{
system("cls");
int a = 0, b = 0, t = 1;
char tname[20];
cout << "请输入你转账用户姓名:" << endl;
cin >> tname;
for (int i = 1; i <= person; i++)
{
if (strcmp(User[i].name, tname) == 0)
{
a = 1;
t = i;
break;
}
}
if (a == 0)
{
cout << "你所输入的姓名不在用户之中,转账失败!" << endl;
}
else if (t == use)
{
cout << "不可以进行给自己转账的操作!";
}
else
{
double n;
cout << "请输入你要转账的金额:" << endl;
cin >> n;
if (User[use].money >= n)
{
cout << "转账成功!";
User[use].money -= n;
User[t].money += n;
}
else
{
cout << "输入金额超过转账金额,转账失败!";
}
}
system("pause");
}
void revise()
{
system("cls");
char tpassword[20];
cout << "请输入新的密码:" << endl;
cin >> tpassword;
while (strlen(tpassword) != 6)
{
cout << "输入密码不是六位数!" << endl;
cout << "请重新输入用户的密码。" << endl;
cin >> tpassword;
}
strcpy_s(User[use].password, tpassword);
system("pause");
}
int personmain()
{
record();
int menu,a=1;
while (a)
{
Personpape();
cout << "请输入你的命令:";
cin >> menu;
switch (menu)
{
case 1:deposit(); break;
case 2:withdrawit(); break;
case 3:carryover(); break;
case 4:revise(); break;
case 5:a = 0; break;
}
}
return 0;
}
int main()
{
int menu;
while (1)
{
Startpage();
cout << "请输入你的命令:";
cin >> menu;
switch (menu)
{
case 1:Newaccount(); break;
case 2: Cancelaccount(); break;
case 3: personmain(); break;
case 4:exit(1);
}
}
return 0;
}