• Bank Simulation Program银行管理系统C++ :)


    设计并实现简单的银行存取款系统,系统主界面包括登录和注册两个选项,选择登录,提示用户输入银行帐号和密码,验证通过后进入主界面,主界面包括:存款、取款、查询余额、历史记录、修改密码等功能。注册功能让用户输入账号和密码,在注册时要验证账号是否已经存在。所有数据能够保存在文件中,退出系统后再次运行系统,之前注册的用户和存款信息都存在。








    #include <iostream>
    #include <fstream>
    #include <queue>
    #include <stdlib.h>
    using namespace std;
    struct user;
    typedef user T;
    queue <T> uu;
    int count=0;
    struct user
    {
        string id;
        string pass;
        int n;
        double *money;
        user() {}
        user(string id,string pass,int n,double *money):id(id),pass(pass),n(n),money(money) {}
    };
    
    
    int gongshow();
    int gong(string newid);
    int save(string newid, string newpass);
    int setid(string newid,string newpass);
    
    
    int main()
    {
        system("color 0A");
        while(1)
        {
            int m;
            string newid,newpass;
            cout << "			    *************************" << endl;
            cout << "			    *Bank Simulation Program*" << endl;
            cout << "			    *************************" << endl;
            cout << "			    *                       *" << endl;
            cout << "			    *        1.LOG IN       *" << endl;
            cout << "			    *        2.ENROLL       *" << endl;
            cout << "			    *        3.ESC          *" << endl;
            cout << "			    *                       *" << endl;
            cout << "			    *************************" << endl<<endl;
            cout << "			 Please enter the serial number:";
            cin  >> m;
            if(m==3)
                return 0;
            system("cls");
            cout << "			    *************************" << endl;
            cout << "			    *Bank Simulation Program*" << endl;
            cout << "			    *************************" << endl<<endl;
            cout << "			    ID:";
            cin  >> newid;
            cout << "			    PASSWORD:";
            cin  >> newpass;
            int x=save(newid,newpass);// id 1 password 0 no_id 2
            if(m==1)
                if(x==1)
                {
                    cout << "			    LOGIN SUCCESSFUL";
                    system ("pause>nul");
                    system("cls");
                    while(1)
                    {
                        if(gong(newid)==0) break;
                        int x=save(newid,newpass);
                        system ("pause>nul");
                        system("cls");
                    }
                }
                else if(x==2)
                {
                    cout << "			    ACCOUNT DOS'T EXIST";
                    system ("pause>nul");
                    system("cls");
                }
                else
                {
                    cout << "			    WRONG PASSWORD";
                    system ("pause>nul");
                    system("cls");
                }
            else if(m==2)
            {
                if(x==2)
                {
                    if(setid(newid,newpass))
                    {
                        cout << "			    ENROLL SUCCESS";
                        while(1)
                        {
                            while(!uu.empty()) uu.pop();
                            int x=save(newid,newpass);
                            system ("pause>nul");
                            system("cls");
                            if(gong(newid)==0) break;
                        }
                    }
                    else
                    {
                        cout << "			    ENROLL FAILURE";
                        system ("pause>nul");
                        system("cls");
    
                    }
                }
                else if(x==1)
                {
                    cout << "			    ACCOUNT ALREADY EXISTS";
                    system ("pause>nul");
                    system("cls");
    
                }
                system("cls");
            }
        }
        return 0;
    }
    
    
    
    int gongshow()
    {
        cout << "			    *************************" << endl;
        cout << "			    *Bank Simulation Program*" << endl;
        cout << "			    *************************" << endl;
        cout << "			    *                       *" << endl;
        cout << "			    *     1.DPOSIT          *" << endl;
        cout << "			    *     2.WITHDRAWALS     *" << endl;
        cout << "			    *     3.CHECK BALANCES  *" << endl;
        cout << "			    *     4.HISTORY RECORD  *" << endl;
        cout << "			    *     5.CHANGE PASSWORD *" << endl;
        cout << "			    *     6.ESC             *" << endl;
        cout << "			    *                       *" << endl;
        cout << "			    *************************" << endl;
        cout << endl << "			 Please enter the serial number:";
        int n;
        cin >>n;
        return n;
    }
    
    int gong(string newid)
    {
    
        int n=gongshow();
        if(n==2||n==1||n==5)
        {
            fstream f("ios.txt",ios::out);
            if(n==1)
            {
                double n=0;
                cout << "			    Enter deposit amount:";
                cin >> n;
                while(!uu.empty())
                {
                    if(uu.front().id==newid)
                    {
                        f<<uu.front().id<<' '<<uu.front().pass<<' '<<uu.front().n+1<<' ';
                        for(int i=0; i<uu.front().n; i++)
                        {
                            f<< uu.front().money[i]<<' ';
                        }
                        f<< uu.front().money[uu.front().n-1]+n<< endl;
                        cout << "			    Deposit has been successful";
                    }
                    else
                    {
                        f<<uu.front().id<<' '<<uu.front().pass<<' '<<uu.front().n<<' ';
                        for(int i=0; i<uu.front().n; i++)
                        {
                            f<< uu.front().money[i]<<' ';
                        }
                        f<<endl;
                    }
                    uu.pop();
                    count--;
                    if(count==1)
                        uu.pop();
                }
            }
            if(n==2)
            {
                double n=0;
                cout << "			    Enter the withdrawal amount:";
                cin >> n;
                while(!uu.empty())
                {
                    if(uu.front().id==newid&&uu.front().money[uu.front().n-1]-n>=0)
                    {
                        f<<uu.front().id<<' '<<uu.front().pass<<' '<<uu.front().n+1<<' ';
                        for(int i=0; i<uu.front().n; i++)
                        {
                            f<< uu.front().money[i]<<' ';
                        }
                        f<< uu.front().money[uu.front().n-1]-n<< endl;
                        f<< endl;
                        cout << "			    Withdrawals success";
                    }
                    else if(uu.front().id!=newid)
                    {
                        f<<uu.front().id<<' '<<uu.front().pass<<' '<<uu.front().n<<' ';
                        for(int i=0; i<uu.front().n; i++)
                        {
                            f<< uu.front().money[i]<<' ';
                        }
                        f<<endl;
                    }
                    else if(uu.front().id==newid&&uu.front().money[uu.front().n-1]-n<0)
                    {
                        f<<uu.front().id<<' '<<uu.front().pass<<' '<<uu.front().n<<' ';
                        for(int i=0; i<uu.front().n; i++)
                        {
                            f<< uu.front().money[i]<<' ';
                        }
                        f<<endl;
                        cout << "			    INSUFFICIENT BALANCE
    ";
                    }
                    uu.pop();
                    count--;
                    if(count==1)
                        uu.pop();
                }
    
            }
            else if(n==5)
            {
                string newpass;
                cout << "			    Please enter a new password:";
                cin >> newpass;
                while(!uu.empty())
                {
                    if(uu.front().id==newid)
                    {
                        f<<uu.front().id<<' '<<newpass<<' '<<uu.front().n<<' ';
                        for(int i=0; i<uu.front().n; i++)
                        {
                            f<< uu.front().money[i]<<' ';
                        }
                        f<< uu.front().money[uu.front().n-1]<< endl;
                    }
                    uu.pop();
                    count--;
                    if(count==1)
                        uu.pop();
                }
                cout << "			    PASSWORD RESET COMPLETE
    ";
            }
            f.close();
        }
        else if(n==3)
        {
            while(!uu.empty())
            {
                if(uu.front().id==newid)
                {
                    cout << "			    BALANCES:" << uu.front().money[uu.front().n-1]<<endl;
                }
                uu.pop();
            }
        }
        else if(n==4)
        {
            while(!uu.empty())
            {
                if(uu.front().id==newid)
                {
                    cout<<"			    ID:"<<uu.front().id<<endl;
                    for(int i=1; i<uu.front().n; i++)
                    {
                        cout<<"			    ";
                        double difference=uu.front().money[i]-uu.front().money[i-1];
                        if(difference>0)
                            cout<<'+';
                        cout<<difference<<endl;
                    }
                    if(uu.front().n==1) cout<<"			    NO RECORD";
                }
                uu.pop();
            }
        }
        else if(n==6)
        {
            system("cls");
            return 0;
        }
        return 1;
    }
    
    int save(string newid, string newpass)
    {
        count=0;
        int flog=2;
        fstream fi;
        fi.open("ios.txt",ios::in);
        if(!fi)
        {
            fi.open("ios.txt",ios::out);
            fi.close();
            fi.open("ios.txt",ios::in);
        }
        while(!fi.eof())
        {
            double *money=new double;
            user a;
            fi >> a.id >> a.pass >> a.n;
            if(a.id==newid)
                if(a.pass==newpass)
                    flog=1;
                else
                    return 0;
            for(int j =0; j<a.n; j++)
            {
                fi >> money[j];
            }
            a.money=money;
            uu.push(a);
            count++;
        }
        fi.close();
        return flog;
    }
    
    int setid(string newid,string newpass)
    {
        fstream fi("ios.txt",ios::app|ios::out);
        int n=1;
        double x=0.0;
        fi<< newid << ' ' << newpass << ' '  << n << ' ' << x <<endl ;
        fi.close();
        return 1;
    }
    
    

    到这里就写完了 :) .

  • 相关阅读:
    将springboot安装成windows服务启动。
    jackson将json数组转成List、普通数组。
    maven编译正常,运行报错:中没有主清单属性
    [SQL]SUTFF内置函数的用法 (删除指定长度的字符并在指定的起始点插入另一组字符)
    sql语句中charindex的用法 可用于截取字符串
    C# 中怎么将string转换成int型
    C#判断奇偶数的函數
    asp.net 下载Excel (数据流,不保存)--客户端
    C# DateTime 日期加1天 减一天 加一月 减一月 等方法(转)
    ASP.NET jquery ajax传递参数
  • 原文地址:https://www.cnblogs.com/chinashenkai/p/9451395.html
Copyright © 2020-2023  润新知