G6 自定義 DOM 節點
阿新 • • 發佈:2020-11-18
ATM管理系統
部落格班級 | AHPU軟體工程 |
---|---|
作業要求 | ATM管理系統 |
作業目標 | |
學號 | 3180701214 |
目錄
題目要求
編寫一個ATM管理系統,語言不限,要求應包括以下主要功能:
(1)開戶,銷戶
(2)查詢賬戶餘額
(3)存款
(4)取款
(5)轉賬(一個賬戶轉到另一個賬戶)等...
程式碼
標頭檔案部分
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<time.h>
結構體部分(定義一個銀行賬戶的基本資訊)
//定義一個銀行賬戶基本資訊 typedef struct tagPerson{ char szUsername[20];//使用者名稱 char szPassword[7];//密碼 char szAccountNumber[20];//銀行賬戶 float fMoney;//餘額 }Person;
連結串列部分
//連結串列的一個節點
typedef struct tagNode{
Person per;//資料域
struct tagNode *pNext;//指標域
}Node;
Node *g_pHead=NULL;//連結串列頭結點
宣告函式
//開戶 int CreateAccount(); //登入 int Login(); //銷戶 int CancelAccount(); //選單 void Menu(Node *pNode); //取款 int WithDrawal(Node *pNode); //存款 int Deposits(Node *pNode); //轉賬 int TransFer(Node *pNode); //修改密碼 int ChangePa(Node *pNode); //查詢 int find(Node *pNode);
開戶
int CreateAccount(){
printf("\n\t\t\t\t\t請輸入您的姓名:");
char szUsername[20];
scanf("%s",szUsername);//szUsername指標 地址
printf("\n\t\t\t\t\t請設定您的銀行卡密碼:");
char szPassword[7];
scanf("%s",szPassword);
printf("\n\t\t\t\t\t請再次輸入您的銀行卡密碼:");
char szRePassword[7];
scanf("%s",szRePassword);
//判斷兩次輸入的密碼是否一致
if(strcmp(szPassword,szRePassword)!=0){//相同為0,不同不為0
printf("\n\t\t\t\t\t兩次輸入的密碼不一致!\n");
return 0;
}
//隨機生成銀行賬號
char szAccountNum[20];//0000 0000 0000 0000 0 0
//1000~9999
srand((unsigned int)time(NULL));
sprintf(szAccountNum,"%d%d%d%d%d%d",rand()%9000+1000,
rand()%9000+1000,rand()%9000+1000,rand()%9000+1000,rand()%10,rand()%10);//sprintf格式化字串
//迴圈找到連結串列的尾結點
Node *p=g_pHead;
while(g_pHead!=NULL&&p->pNext!=NULL){
p = p->pNext;
}
//開闢一個新節點
Node *pNewNode=(Node*)malloc(sizeof(Node));
strcpy(pNewNode->per.szUsername,szUsername);
strcpy(pNewNode->per.szPassword,szPassword);
strcpy(pNewNode->per.szAccountNumber,szAccountNum);
pNewNode->per.fMoney=0.0f;
pNewNode->pNext=NULL;
//新增到尾結點後面
if(g_pHead==NULL){
g_pHead=pNewNode;
}
else{
p->pNext=pNewNode;
}
//列印資訊
printf("\n\t\t\t\t\t您的賬戶資訊如下:\n");
printf("\n\t\t\t\t\t\t姓名:%s\n",pNewNode->per.szUsername);
printf("\n\t\t\t\t\t\t卡號:%s\n",pNewNode->per.szAccountNumber);
printf("\n\t\t\t\t\t\t餘額:%0.2f\n",pNewNode->per.fMoney);
printf("\n\t\t\t\t\t恭喜!賬戶申請成功!\n");
return 1;
}
登入
int Login(){
char szAccountNum[20];//賬號
char szPassword[7];//密碼
printf("\n\t\t\t\t\t請輸入您的卡號:");
scanf("%s",szAccountNum);
//遍歷連結串列尋找當前賬號
Node *p=g_pHead;
while(p!=NULL){
if(strcmp(p->per.szAccountNumber,szAccountNum)!=0){
p=p->pNext;
continue;
}
else{
int i=0;
for(i=0;i<3;i++){
printf("\n\t\t\t\t\t請輸入您的密碼:");
scanf("%s",szPassword);
if(strcmp(szPassword,p->per.szPassword)!=0){
printf("\n\t\t\t\t\t密碼輸入錯誤,請重新輸入密碼,剩餘次數:%d\n",2-i);
system("pause");
system("cls");
continue;
}
else{
system("cls");
//進入選單頁面
Menu(p);
return 1;
}
}
}
}
printf("\n\t\t\t\t\t請輸入您的密碼:");
return 1;
}
銷戶
int CancelAccount(){
char Number[20],passWord[7];
printf("\n\t\t\t\t\t請輸入所需要登出的賬戶卡號:");
scanf("%s",Number);
Node *p=g_pHead,*q=g_pHead;
while(p!=NULL){
if(strcmp(p->per.szAccountNumber,Number)!=0){
q=p;
p=p->pNext;
continue;
}
else{
int i=0;
for(i=0;i<3;i++){
printf("\n\t\t\t\t\t請輸入所需要登出的賬戶卡號密碼:");
scanf("%s",passWord);
if(strcmp(passWord,p->per.szPassword)!=0){
printf("\n\t\t\t\t\t密碼輸入錯誤,請重新輸入密碼,剩餘次數:%d\n",2-i);
system("pause");
system("cls");
continue;
}
else{
q->pNext=p->pNext;
free(p);
printf("\n\t\t\t\t\t登出賬戶成功!\n");
return 1;
}
printf("\n\t\t\t\t\t登出賬戶失敗!\n");
return 0;
}
}
}
return 1;
}
取款
int WithDrawal(Node *pNode){
float fMoney;
printf("\n\t\t\t\t\t請輸入要取款的金額:");
fflush(stdin);
scanf("%f",&fMoney);
while(fMoney<=0||fMoney>pNode->per.fMoney){
printf("\n\t\t\t\t\t取款額不能小於等於零或者大於餘額,請重新輸入!\n");
scanf("%f",&fMoney);
}
pNode->per.fMoney-=fMoney;
printf("\n\t\t\t\t\t您的賬戶成功取出%.2f元!\n",fMoney);
return 1;
}
存款
int Deposits(Node *pNode){
float fMoney;
printf("\n\t\t\t\t\t請輸入要存款的金額:");
fflush(stdin);
scanf("%f",&fMoney);
while(fMoney<=0){
printf("\n\t\t\t\t\t存款額不能小於等於零,請重新輸入!\n");
printf("\n\t\t\t\t\t請輸入要存款的金額:");
scanf("%f",&fMoney);
}
pNode->per.fMoney+=fMoney;
printf("\n\t\t\t\t\t您的賬戶成功存入%.2f元!\n",fMoney);
return 1;
}
轉賬
int TransFer(Node *pNode){
char szAccountNum[20];
float fMoney;
printf("\n\t\t\t\t\t請輸入要轉入的賬戶卡號:");
fflush(stdin);
scanf("%s",szAccountNum);
printf("\n\t\t\t\t\t請輸入要轉入的金額:");
fflush(stdin);
scanf("%f",&fMoney);
//遍歷尋找需要轉入的賬號
Node *p=g_pHead;
while(p!=NULL){
if(strcmp(p->per.szAccountNumber,szAccountNum)!=0){
p=p->pNext;
continue;
}
else{
pNode->per.fMoney-=fMoney;
p->per.fMoney+=fMoney;
printf("\n\t\t\t\t\t轉賬成功!\n");
return 1;
}
}
printf("\n\t\t\t\t\t轉出賬戶不存在!\n");
return 1;
}
修改密碼
int ChangePa(Node *pNode){
char passWord1[7],passWord2[7];
printf("\n\t\t\t\t\t請輸入原密碼:");
scanf("%s",passWord1);
printf("\n\t\t\t\t\t請輸入新密碼:");
scanf("%s",passWord2);
for(int i=0;i<3;i++){
if(strcmp(passWord1,pNode->per.szPassword)!=0){
printf("\n\t\t\t\t\t原密碼輸入錯誤!還有%d次輸入機會,請重新輸入:\n",2-i);
scanf("%s",passWord1);
}
else{
strcpy(pNode->per.szPassword,passWord2);
printf("\n\t\t\t\t\t密碼修改完成!\n");
return 1;
}
}
return 1;
}
查詢餘額
int Find(Node *pNode){
printf("\n\t\t\t\t\t當前賬戶餘額為%.2f\n",pNode->per.fMoney);
return 1;
}
主選單
void Menu(Node *pNode){
char ch;
start:
printf("\n\n\t\t\t\t\t\t\t請選擇您需要的業務:\n\n\n");
printf("\n\t\t\t\t\t 1>取款\t\t\t2>查詢\n");
printf("\n\t\t\t\t\t 3>轉賬\t\t\t4>修改密碼\n");
printf("\n\t\t\t\t\t 5>存款\t\t\t6>退出\n");
ch=getch();
switch(ch){
case '1'://取款
WithDrawal(pNode);
system("pause");
system("cls");
break;
case '2'://查詢
Find(pNode);
system("pause");
system("cls");
break;
case '3'://轉賬
TransFer(pNode);
system("pause");
system("cls");
break;
case '4'://修改密碼
ChangePa(pNode);
system("pause");
system("cls");
break;
case '5'://存款
Deposits(pNode);
system("pause");
system("cls");
break;
case '6'://退出
return;
}
goto start;
}
主函式
int main(){
//設定文字和背景顏色
system("color F2");
start:
printf("\n\n\t\t\t\t\t\t\tATM管理系統\n\n\n");
printf("\t\t\t\t\t\t\t 1.開戶\n");
printf("\t\t\t\t\t\t\t 2.登入\n");
printf("\t\t\t\t\t\t\t 3.銷戶\n");
printf("\t\t\t\t\t\t\t 4.退出\n");
char ch = getch();
switch(ch){
case '1'://開戶
CreateAccount();
system("pause");
system("cls");
break;
case '2'://登入
Login();
system("pause");
system("cls");
break;
case '3'://銷戶
CancelAccount();
system("pause");
system("cls");
break;
case '4'://退出
exit(0);
break;
}
goto start;
return 0;
}
執行介面
主介面截圖
開戶介面
登入介面
存款介面
取款介面
轉賬介面
查詢餘額介面
修改密碼介面
退出登入介面
銷戶介面
作業小結
1.psp表格
psp2.1 | 任務內容 | 計劃完成需要的時間(min) | 實際完成需要的時間(min) |
---|---|---|---|
Planning | 計劃 | 100 | 90 |
Development | 開發 | 90 | 100 |
Analysis | 需求分析(包括學習新技術) | 60 | 80 |
Design Spec | 生成設計文件 | 30 | 40 |
Design Review | 設計複審 | 5 | 10 |
Coding Standard | 程式碼規範 | 60 | 70 |
Design | 具體設計 | 10 | 12 |
Coding | 具體編碼 | 240 | 240 |
Code Review | 程式碼複審 | 5 | 7 |
Test | 測試(自我測試,修改程式碼,提交修改) | 50 | 50 |
Reporting | 報告 | 9 | 6 |
Test Report | 測試報告 | 3 | 10 |
Size Measurement | 計算工作量 | 20 | 40 |
Postmortem & Process Improvement Plan | 事後總結,並提出過程改進計劃 | 30 | 30 |
2.心得和經驗
通過本次作業,我複習了指標、連結串列、結構體的相關知識,對指標的傳參方式有了更深入的掌握,同時也學習了很多新的知識,包括getch()函式的使用,使用scanf時在執行介面上會有顯示輸入的資料,但是使用getch()函式鍵盤在接受輸入之後不會顯示輸入的資料,對介面的優化起到了很好的效果;第二個就是sprintf()函式,它可以將字串進行格式化。總之,本次作業收穫很多,也感受到了程式設計的樂趣,相信接下來的時間還能學到更多的東西。