C語言實(shí)現(xiàn)ATM系統(tǒng)程序的完整代碼
更新時間:2021年05月02日 08:48:49 作者:weixin_53391957
這篇文章主要介紹了C語言實(shí)現(xiàn)ATM系統(tǒng)程序的完整代碼,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
實(shí)現(xiàn)效果如圖:
代碼如下:
#include<stdio.h> #include<string.h> #include<conio.h> #include<stdlib.h> //開戶信息 typedef struct _Person { char name[20]; char account[20]; char password[7]; float money; }Person; //結(jié)點(diǎn) typedef struct _Node { Person P; //客戶 struct _Node* next; }Node; Node* HeadNode = NULL;//鏈表頭 /*----------------函數(shù)--------------------*/ void Login(); void Menu(); void Register(); void LoginMenu(Node* pNode); void FindAccount(Node* pNode); void DrawMoney(Node* pNode); void Deposit(Node* pNode); void Transfer(Node* pNode); void LoginMenu(Node* pNode); //主菜單 void Menu() { printf("\n\t\t\t歡迎進(jìn)入ATM銀行管理系統(tǒng)\n"); printf("\t\t 1. 注冊\n"); printf("\t\t 2. 登錄\n"); printf("\t\t 3. 系統(tǒng)幫助\n"); printf("\t\t 4. 查詢賬號\n"); printf("\t\t 5. 退出\n"); } //注冊 void Register() { Node* NewNode = (Node*)malloc(sizeof(Node)); NewNode->next = NULL; NewNode->P.money = 0; printf("請輸入您的名字:"); scanf("%s", NewNode->P.name); printf("請輸入您的密碼:"); scanf("%s", NewNode->P.password); char Password[7]; printf("請再次輸入您的密碼:"); scanf("%s", Password); for (int i = 1; i < 4; i++) { if (strcmp(NewNode->P.password, Password) != 0) { printf("您輸入的密碼有誤,還有%d次機(jī)會.\n", 3 - i); printf("請再次輸入您的密碼:"); scanf("%s", Password); } else { srand((unsigned int)time(NULL)); sprintf(NewNode->P.account, "%d%d%d%d%d", rand() % 9000 + 1000, rand() % 9000 + 1000, rand() % 9000 + 1000, rand() % 9000 + 1000, rand() % 900 + 100); //頭插法 if (HeadNode == NULL) { HeadNode = NewNode; } else { NewNode->next = HeadNode; HeadNode = NewNode; } printf("\n\n\n\n\t\t\t\t恭喜你已經(jīng)成功注冊賬戶,以下是您的賬戶信息.\n"); printf("\t\t\t\t姓名:%s\n", NewNode->P.name); printf("\t\t\t\t賬戶:%s\n", NewNode->P.account); printf("\t\t\t\t余額:%.2f\n", NewNode->P.money); getch(); return 1; } } printf("您的賬號已被鎖定,請稍后再試."); return 1; } //取款 void DrawMoney(Node* pNode) { Node* mNode = pNode; float Money = 0; printf("歡迎進(jìn)入ATM銀行管理系統(tǒng)\n"); printf("請選擇你取款金額\n"); printf("100\t\t2000\n"); printf("500\t\t5000\n"); printf("10000\t\t其他金額\n"); scanf("%f", &Money); mNode->P.money = mNode->P.money - Money; return mNode; } //存款 void Deposit(Node* pNode) { Node* mNode = pNode; float Money = 0; printf("請存取您的金額:"); scanf("%f", &Money); mNode->P.money = mNode->P.money + Money; return mNode; } //轉(zhuǎn)賬 void Transfer(Node* pNode) { Node* TNode = HeadNode; char Account[20]; printf("請輸入轉(zhuǎn)賬的號碼:"); scanf("%s", Account); while (TNode != NULL) { if (strcmp(TNode->P.account, Account) != 0) { TNode = TNode->next; continue; } else { float Money = 0; printf("請輸入您要轉(zhuǎn)賬的金額:"); printf("100\t\t2000\n"); printf("500\t\t5000\n"); printf("10000\t\t其他金額\n"); scanf("%f", &Money); TNode->P.money = TNode->P.money + Money; pNode->P.money = pNode->P.money - Money; return 1; } } return 1; } //登錄菜單 void LoginMenu(Node * pNode) { while (1) { printf("歡迎進(jìn)入ATM銀行管理系統(tǒng)\n"); printf("請選擇以下服務(wù):\n"); printf("1.取款\t\t2.查詢\n"); printf("3.存款\t\t4.轉(zhuǎn)賬\n"); printf("5.修改密碼\t6.退出\n"); char ch = getch(); switch (ch) { case '1': DrawMoney(pNode); break; case '2': printf("您的賬戶余額為:%.2f", pNode->P.money); getch(); break; case '3': Deposit(pNode); break; case '4': Transfer(pNode); break; case '5': break; case '6': return 0; break; default: break; } system("cls"); } } //登錄 void Login() { system("cls"); Node* pNode = HeadNode; char P_account[20]; char P_password[7]; printf("請輸入您的卡號:"); scanf("%s", P_account); while (pNode != NULL) { if (strcmp(P_account,pNode->P.account) != 0) { pNode = pNode->next; continue; } else { for (int i = 1; i < 4; i++) { printf("請輸入您的密碼:"); scanf("%s", P_password); if (strcmp(P_password, pNode->P.password) != 0) { printf("您輸入的密碼有誤,還有%d次機(jī)會.\n", 3 - i); } else { system("cls"); LoginMenu(pNode); return 1; } } printf("\n對不起,您輸入的密碼有誤,請重新登錄.\n"); system("pause"); return 1; } } return 1; } //系統(tǒng)幫助信息 void Help() { system("cls"); printf( "\n\n\n\n\t——————————-----—---——ATM系統(tǒng)幫助----------------------------------------\n" "\t1、初始界面:客戶插卡前或者退卡后ATM顯示的界面,提示客戶插卡操作及銀行廣告.\n" "\t2、身份認(rèn)證:需要客戶插入銀行卡后輸入密碼來驗(yàn)證所有權(quán).\n" "\t3、吞卡:客服若連續(xù)輸入密碼3次錯誤后,則將卡吞入ATM內(nèi).\n" "\t4、賬戶:賬戶由銀行卡的卡號、密碼、銀行系統(tǒng)用戶信息組成.\n" "\t5、業(yè)務(wù)操作:由查詢余額、取款、存款、轉(zhuǎn)賬、取卡等事項組成.\n" "\t6、查詢余額:顯示該賬戶中剩余金額.\n" "\t7、取款:根據(jù)客戶輸入的金額從賬戶中扣除相應(yīng)的金額,客戶可以提取相應(yīng)數(shù)額的現(xiàn)金.\n" "\t8、存款:客戶存入現(xiàn)金,賬戶根據(jù)現(xiàn)金數(shù)額增加剩余金額.\n" "\t9、轉(zhuǎn)賬:客戶輸入另外一個賬戶號碼和金額,從本賬戶的余額中減去該金額,增加到那個賬號中.\n" "\t10、打印憑條:憑條由日期,銀行卡的卡號,交易流水號組成.\n" "\t11、取卡:客戶取回銀行卡.\n" "\t————————————————-------------------------------------------------------\n" ); getch(); return 1; } //查詢賬號 void FindAccount(Node* pNode) { Node* FNode = pNode; char AccountName[7]; printf("請輸入賬號姓名:"); scanf("%s", AccountName); while (FNode != NULL) { if (strcmp(AccountName, FNode->P.name) != 0) { FNode = FNode->next; continue; } else { printf("該姓名的賬戶為:%s", FNode->P.account); return 1; } } printf("抱歉!該姓名未注冊賬號."); return 1; } int main() { system("color b0"); while (1) { system("cls"); Menu(); char ch = _getch(); switch (ch) { case '1': Register(); break; case '2': Login(); break; case '3': Help(); break; case '4': FindAccount(HeadNode); getch(); break; case '5': exit(0); default: break; } } return 0; }
到此這篇關(guān)于C語言實(shí)現(xiàn)ATM系統(tǒng)程序的完整代碼的文章就介紹到這了,更多相關(guān)c語言ATM系統(tǒng)程序內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C++?std::array實(shí)現(xiàn)編譯器排序
這篇文章主要介紹了C++?std::array實(shí)現(xiàn)編譯器排序,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-06-06c語言_構(gòu)建一個靜態(tài)二叉樹實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄猚語言_構(gòu)建一個靜態(tài)二叉樹實(shí)現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-05-05C++ 基礎(chǔ)教程之虛函數(shù)實(shí)例代碼詳解
虛函數(shù)在 c++ 的繼承體系中是一個非常重要概念,讓我們可以在子類中復(fù)寫父類的方法。這篇文章主要介紹了C++ 基礎(chǔ)教程之虛函數(shù)實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2020-02-02深入分析C++中兩個大數(shù)相乘結(jié)果不正確的問題
本篇文章是對C++中兩個大數(shù)相乘結(jié)果不正確的問題進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05