JavaScript ES6語法
這個作業屬於哪個課程 | 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;
}