實訓:銀行系統(終結版)

來源:互聯網
上載者:User
#include <iostream>#include <string.h>#include <iomanip>#include <stdio.h>using namespace std;#define MAXACCOUNTNUMBER 20000//銀行中初始卡號#define INITNUMBER 10001//定義開戶系統結構體struct Account{    long accNumber;             //卡號    char accName[20];          //戶名    char accPwd[10];          //密碼    double balance;          //餘額    char flag[6];           //卡的狀態};//結構體結束符(切記,別漏掉!!!)//歡迎函數void Welcome();//登陸函數void Denglu();//主介面void Mainmenu();//選擇函數void Chose();//退出函數void Exit();//開戶函數void OpenAnAccount();//進入開戶void GoOpenAnAccount();//存款函數void Deposit();//進入存款void GoDeposit();//改密函數void ChangeCipher();//進入改密void GoChangeCipher();//查詢函數void Query();//進入查詢void GoQuery();//取款函數void Withdraw();//進入取款void GoWithdraw();//銷戶函數void CloseAnAccount();//進入銷戶void GoCloseAnAccount();//校正密碼必須是6-8位,而且是純數字bool isPassLegal(char pass[]);//輸出指定卡的資訊void printAccount(Account acc);//根據卡號尋找卡在數組中的下標int searchAccount(long accNumber);//銀行中所有卡Account array[MAXACCOUNTNUMBER];//銀行中卡的數量(全域變數)int size=0;//產生銀行中自增卡號long autoCreament();//定義全域變數用作密碼、使用者名稱const char Mima[10]="admin";const char Yonghuming[10]="admin";int main(){    Welcome();    Denglu();    return 0;}//歡迎介面void Welcome(){    cout<<"*********************************************"<<endl;    cout<<"**                                         **"<<endl;    cout<<"**       歡迎使用儲蓄綜合業務平台          **"<<endl;    cout<<"**              V1.0版                     **"<<endl;    cout<<"*********************************************"<<endl;}//登陸系統void Denglu(){    int i;    char str1[10],str2[10];//用於輸入使用者名稱和密碼    cout<<"請輸入使用者名稱:";    cin>>str1;//輸入使用者名稱    if(strcmp(str1,Yonghuming)==0)    {        cout<<endl;        cout<<"請輸入登陸密碼:";        cin>>str2;        if(strcmp(str2,Mima)==0)//判斷密碼是否正確        {            cout<<"*********************************************"<<endl;            cout<<"**         歡迎登陸儲蓄綜合業務平台        **"<<endl;            cout<<"*********************************************"<<endl;            Mainmenu();             //正確,進入系統        }        else        {            for(i=2;i>0;--i)            {                cout<<"密碼錯誤,請重新輸入:(您還有"<<i<<"次機會)";//密碼不正確,三次輸入機會,三次不正確,退出                cin>>str2;                cout<<endl;                if(strcmp(str2,Mima)==0)                {                    cout<<"*********************************************"<<endl;                    cout<<"**         歡迎登陸儲蓄綜合業務平台        **"<<endl;                    cout<<"*********************************************"<<endl;                    Mainmenu();                    break;                }                if(i==1)//三次沒輸正確                {                    cout<<"您連續三次輸錯密碼,請到前台找回密碼,謝謝合作!";                    break;                }            }        }    }    else    {        cout<<"該使用者名稱不存在."<<endl;   //使用者名稱錯誤        Denglu();//重新返回登陸介面    }}//主菜單void Mainmenu(){    cout<<"*********************************************"<<endl;    cout<<"**      *1.開戶    *4.改密     *0.退出     **"<<endl;    cout<<"**      *2.存款    *5.查詢                 **"<<endl;    cout<<"**      *3.取款    *6.銷戶                 **"<<endl;    cout<<"*********************************************"<<endl;    Chose();}//選擇進入其他業務void Chose(){    int choice;    cout<<"請輸入您要進行的業務代號:";//輸入選擇    cin>>choice;    if(choice>=0&&choice<=6)    {        switch(choice)//分別進入不同業務        {            case 0:                   Exit();                   break;            case 1:                   OpenAnAccount();                   break;            case 2:                   Deposit();                   break;            case 3:                   Withdraw();                   break;            case 4:                   ChangeCipher();                   break;            case 5:                   Query();                   break;            case 6:                  CloseAnAccount();                  break;        }    }    else    {        cout<<"輸入有誤,請核實後重新輸入!"<<endl;//輸入有誤        Mainmenu();    }}//開戶介面void OpenAnAccount(){    cout<<"*********************************************"<<endl;    cout<<"**           歡迎進入開戶系統              **"<<endl;    cout<<"*********************************************"<<endl;    GoOpenAnAccount();}//存款介面void Deposit(){    cout<<"*********************************************"<<endl;    cout<<"**           歡迎進入存款系統              **"<<endl;    cout<<"*********************************************"<<endl;    GoDeposit();}//取款介面void Withdraw(){    cout<<"*********************************************"<<endl;    cout<<"**           歡迎進入取款系統              **"<<endl;    cout<<"*********************************************"<<endl;    GoWithdraw();}//改密介面void ChangeCipher(){    cout<<"*********************************************"<<endl;    cout<<"**           歡迎進入改密系統              **"<<endl;    cout<<"*********************************************"<<endl;    GoChangeCipher();}//銷戶介面void CloseAnAccount(){    cout<<"*********************************************"<<endl;    cout<<"**           歡迎進入銷戶系統              **"<<endl;    cout<<"*********************************************"<<endl;    GoCloseAnAccount();}//查詢介面void Query(){    cout<<"*********************************************"<<endl;    cout<<"**           歡迎進入查詢系統              **"<<endl;    cout<<"*********************************************"<<endl;    GoQuery();}//退出介面void Exit(){    cout<<"*********************************************"<<endl;    cout<<"**謝謝您使用儲蓄綜合業務平台,歡迎下次光臨 **"<<endl;    cout<<"*********************************************"<<endl;}//進入開戶void GoOpenAnAccount(){    char pwd1[10];    char pwd2[10];    int j;    cout<<"請輸入戶名:";    cin>>array[size].accName;    cout<<"請輸入密碼:";        //輸入並儲存資料    cin>>pwd1;    cout<<"請再次輸入密碼:";    cin>>pwd2;    if(strcmp(pwd1,pwd2)==0)//strcmp的使用    {        if(isPassLegal(pwd1))//密碼合法        {            strcpy(array[size].accPwd,pwd1);//strcpyd的使用            cout<<"請輸入金額:";            cin>>array[size].balance;            strcpy(array[size].flag,"正常");//*******記住            array[size].accNumber=autoCreament();            printAccount(array[size]);            size++;            cout<<"開戶成功,按任意鍵返回...";            fflush(stdin);            getchar();            Mainmenu();//返回主菜單        }        else        {            cout<<"密碼必須是純數字,並且是6-8位"<<endl;            GoOpenAnAccount();        }    }    else    {        cout<<"兩次密碼不一致!";        cout<<"是否繼續進行開戶?"<<endl;        cout<<"繼續請按1...返回主菜單請按其他數字鍵";        cin>>j;        if(j==1)           GoOpenAnAccount();//繼續開戶        else           Mainmenu();//返回主菜單    }}//進入存款void GoDeposit(){    int j;    long accNum;//存款的卡號    double money;//存款的金額    int pos;    cout<<"請輸入存款的卡號:";    cin>>accNum;    pos=searchAccount(accNum);    if(pos==-1)    {        //卡號有誤        cout<<"卡號不存在!"<<endl;        Mainmenu();//返回主菜單    }else    {        cout<<"請輸入存款金額:";        cin>>money;        //展示下存款前卡的資訊        cout<<"存款前卡的資訊:"<<endl;        printAccount(array[pos]);        //存款後的餘額        array[pos].balance+=money;         //展示存款後卡的資訊        cout<<"存款後卡的資訊:"<<endl;        printAccount(array[pos]);        cout<<"存款成功,按任意鍵返回...";        fflush(stdin);        getchar();        Mainmenu();//返回主菜單    }}//進入取款void GoWithdraw(){    int j;    long accNum;//取款的卡號    char accnum[10];//密碼一定要定義成char數組,注意!!!    double money;//取款的金額    int pos;    cout<<"請輸入取款的卡號:";    cin>>accNum;    pos=searchAccount(accNum);    if(pos==-1)    {        //卡號有誤        cout<<"卡號不存在!"<<endl;        Mainmenu();//返回主菜單    }    else//卡號正確,進入    {        cout<<"請輸入密碼:";        cin>>accnum;//輸入密碼        if(strcmp(array[pos].accPwd,accnum)==0)        {            cout<<"請輸入取款金額:";            cin>>money;            if(array[pos].balance<money)            {                cout<<"您的餘額不足,無法取出!!!"<<endl;                GoWithdraw();            }            else            {                //展示下取款前卡的資訊                cout<<"取款前卡的資訊:"<<endl;                printAccount(array[pos]);                //取款後的餘額                array[pos].balance-=money;                //展示取款後卡的資訊                cout<<"取款後卡的資訊:"<<endl;                printAccount(array[pos]);                cout<<"取款成功,按任意鍵返回...";                fflush(stdin);                getchar();                Mainmenu();//返回主菜單            }        }        else        {            cout<<"輸入密碼有誤!"<<endl;            cout<<"是否繼續要進行取款?"<<endl;            cout<<"繼續請按1...返回主菜單請按其他數字鍵";            cin>>j;            if(j==1)               GoWithdraw();//繼續取款            else               Mainmenu();//返回主菜單        }    }}//進入改密void GoChangeCipher(){    char pwd1[10];    char pwd2[10];    int j;    long accNum;//要修改的帳號    char accnum[10];//密碼一定要定義成char數組,注意!!!    int pos;    cout<<"請輸入您要修改密碼的卡號:";    cin>>accNum;    pos=searchAccount(accNum);    if(pos==-1)    {        //卡號有誤        cout<<"該卡號不存在!"<<endl;        Mainmenu();//返回主菜單    }    else//卡號正確,進入    {        cout<<"請輸入密碼:";        cin>>accnum;    //輸入密碼        if(strcmp(array[pos].accPwd,accnum)==0)        {            cout<<"請輸入新密碼:";        //輸入並儲存資料            cin>>pwd1;            cout<<"請再次輸入新密碼:";            cin>>pwd2;            if(strcmp(pwd1,pwd2)==0)//strcmp的使用            {                if(isPassLegal(pwd1))//密碼合法                {                    strcpy(array[pos].accPwd,pwd1);//strcpyd的使用                    printAccount(array[pos]);                    cout<<"修改密碼成功,按任意鍵返回...";                    fflush(stdin);                    getchar();                    Mainmenu();//返回主菜單                }                else                {                    cout<<"密碼必須是純數字,並且是6-8位"<<endl;                    GoChangeCipher();                }            }            else            {                cout<<"兩次密碼不一致!";//兩次密碼不一致                cout<<"是否繼續進行改密?"<<endl;                cout<<"繼續請按1...返回主菜單請按其他數字鍵";                cin>>j;                if(j==1)                    GoChangeCipher();//繼續改密                else                    Mainmenu();//返回主菜單            }        }        else        {            cout<<"輸入密碼有誤!"<<endl;            cout<<"是否繼續要進行改密?"<<endl;            cout<<"繼續請按1...返回主菜單請按其他數字鍵";            cin>>j;            if(j==1)               GoChangeCipher();//繼續改密            else               Mainmenu();//返回主菜單        }    }}//進入銷戶void GoCloseAnAccount(){    int j,i;    int pos;    long CloseAccount;//銷戶的卡號    char accnum[10];//密碼一定要定義成char數組,注意!!!    cout<<"請輸入您要銷戶的卡號:";    cin>>CloseAccount;    pos=searchAccount(CloseAccount);//尋找卡號    if(pos==-1)    {        //卡號有誤        cout<<"該卡號不存在!"<<endl;        Mainmenu();//返回主菜單    }    else//卡號正確,進入    {        cout<<"請輸入密碼:";        cin>>accnum;//輸入密碼        if(strcmp(array[pos].accPwd,accnum)==0)        {            cout<<"是否確認要進行銷戶?"<<endl;            cout<<"繼續請按1...返回主菜單請按其他數字鍵";            cin>>j;            if(j==1)//確認銷戶            {                array[pos].balance=0;//餘額為零                strcpy(array[pos].flag,"銷戶");//狀態為銷戶                printAccount(array[pos]);//列印                cout<<"銷戶成功,按任意鍵返回...";                fflush(stdin);                getchar();                Mainmenu();//返回主菜單            }            else            {                Mainmenu();//返回主菜單            }        }        else        {            cout<<"密碼輸入錯誤!";            cout<<"是否繼續要進行銷戶?"<<endl;            cout<<"繼續請按1...返回主菜單請按其他數字鍵";            cin>>j;            if(j==1)               GoCloseAnAccount();//繼續銷戶            else               Mainmenu();//返回主菜單        }    }}//進入查詢void GoQuery(){    int j;    long accNum;//查詢的帳號    char accnum[10];//密碼一定要定義成char數組,注意!!!    int pos;    cout<<"請輸入您要查詢的卡號:";    cin>>accNum;    pos=searchAccount(accNum);    if(pos==-1)    {        //卡號有誤        cout<<"該卡號不存在!"<<endl;        Mainmenu();//返回主菜單    }    else//卡號正確,進入    {        cout<<"請輸入密碼:";        cin>>accnum;//輸入密碼        if(strcmp(array[pos].accPwd,accnum)==0)        {            cout<<"您的卡的資訊為:"<<endl;            printAccount(array[pos]);            cout<<"查詢成功,按任意鍵返回...";            fflush(stdin);            getchar();            Mainmenu();//返回主菜單        }        else        {            cout<<"輸入密碼有誤!"<<endl;            cout<<"是否繼續要進行查詢?"<<endl;            cout<<"繼續請按1...返回主菜單請按其他數字鍵";            cin>>j;            if(j==1)               GoQuery();//繼續查詢            else               Mainmenu();//返回主菜單        }    }}//判斷密碼是否規範bool isPassLegal(char pass[]){    bool flag=true;    int len=strlen(pass),i;    if(len<9&&len>=6){        //滿足6-8位        for(i=0;i<len;i++){            if(pass[i]<48||pass[i]>57){                flag=false;                break;            }        }    }else{        //不滿足6-8位        flag=false;    }    return flag;}//產生銀行中自增卡號long autoCreament(){    if(size==0)    {        return INITNUMBER;    }    else    {        return array[size-1].accNumber+1;//以前前一位戶主的卡號加1作為新戶主的卡號    }}//輸出指定卡的資訊void printAccount(Account acc){    cout<<"+--------------------------------------------+"<<endl;    cout<<"|"<<setiosflags(ios::left)<<setw(8)<<"卡號"<<"|"<<setw(8)<<"戶名"<<"|"<<setw(8)<<"密碼"<<"|"<<setw(8)<<"金額"<<"|"<<setw(8)<<"狀態"<<"|"<<endl;    cout<<"+--------------------------------------------+"<<endl;    cout<<"|"<<setiosflags(ios::left)<<setw(8)<<acc.accNumber<<"|"<<setw(8)<<acc.accName<<"|"<<setw(8)<<acc.accPwd<<"|"<<setw(8)<<acc.balance<<"|"<<setw(8)<<acc.flag<<"|"<<endl;    cout<<"+--------------------------------------------+"<<endl;}/*根據卡號尋找卡的下標* 若傳回值>=0,卡號是正確* 若傳回值=-1,卡號有誤*/int searchAccount(long accNumber){    int i,pos=-1;    for(i=0;i<size;i++)    {        if(array[i].accNumber==accNumber&&strcmp(array[i].flag,"銷戶")!=0)        {            //找到了這張卡            pos=i;            break;        }    }    return pos;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.