程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> 銀行管理系統

銀行管理系統

編輯:C++入門知識

//

//  main.cpp

//  銀行管理系統

//

//  Created by 丁小未 on 13-7-23.

//  Copyright (c) 2013年 dingxiaowei. All rights reserved.

//

//項目:銀行管理系統

//系統實現的主要有管理,取款機管理,用戶查詢等功能:

//*管理模塊:存款、取款、開戶、銷戶、修改信息、辦卡、掛失卡;

//*用戶查詢模塊;

//*取款機信息管理模塊:管理員管理查詢和維護、客戶查詢和取款等功能;

//可以考慮利率

#include <iostream>

using namespace std;

#include <string>

#include <fstream>

#include <time.h>

#include <vector>

#define MAX 20

 

 

 

 


class Person

{

public:

    string cardNum;//卡號

    string cardName;//用戶名

    double money;//余額

    string beginTime;//開戶日期

    bool useState=false;//是否掛失

 


    /*******用戶的功能***********/

    //查詢我當前用戶的賬戶余額

    double SelectMoney()

    {

        return money;

    }

    //選擇掛失和解鎖卡

    bool ChooseUseState(bool f)

    {

        useState = f;

        return useState;

    }

   

    //取錢

    double GetMoney(double m)

    {

        if (m>money) {

            cout<<"您的余額不足!"<<endl;

        }

        return money -= m;

    }

    //存錢

    double AddMoney(double m)

    {

        return money += m;

    }

    //構造函數

    Person(string cardnum,string cardname,double money,string begintime,bool usestate)

    {

        this->cardNum = cardnum;

        this->cardName = cardname;

        this->money = money;

        this->beginTime = begintime;

        this->useState = usestate;

    }

    //默認構造函數

    Person(){};

    //運算符重載

//    Person&person = (const Person &other)

//    {

//       

//    }

 


};

int total=0;//記錄總數

Person person[MAX];//定義一個person數組

double price=0.1;//默認匯率

 

 

 

/*******************函數申明******************************************/

void set_psw();//設置密碼

int psw_check();//密碼驗證

void Show_menu();//顯示菜單

int get_managermenu_choice();//接受管理員菜單選擇

void PrintPersonTitle();//打印頭信息

 


char* GetTime();//獲取系統當前時間

void Show_Iden_menu();//身份選擇菜單

int get_Idemenu_choice();//接受身份菜單選擇

void inputInfile(Person person[],int n);//將類數組寫入文件

void Show_PersonMenu();//顯示普通用戶功能菜單

void Show_Managermenu();//顯示管理員功能菜單

int get_personmenu_choice();//普通用戶接受功能菜單

int findPerson(Person *person,int n,string findName);//查找名字返回序列號

bool ISManager(string &name,string &pwd);//驗證管理員身份

bool ISPerson(string &name,string &pwd);//驗證用戶信息

/**********************************************************************/

//查找名字返回序列號

int findPerson(Person *person,int n,string findName)

{

    int i;

    int m=-1;

    for (i=0; i<n; i++) {

        if (person[i].cardName == findName) {

            m=i;

            break;

        }

    }

    return m;//返回person的下標

}

 


//將類數組寫入文件,數組本身就是地址傳遞

void inputInfile(Person person[],int &n)

{

    ofstream onfile;//寫入文件類

    onfile.open("Person.txt");

    for (int i=0; i<n; i++) {

        onfile<<person[i].cardNum<<"    "<<person[i].cardName<<"    "<<person[i].money<<"   "<<person[i].beginTime<<"   "<<person[i].useState<<"\n"<<endl;

    }

    onfile.close();

}

//管理員共有繼承自普通人

class Manager:public Person

{

public:

    //開戶

    void addPerson(Person person[],int &n)

    {

        char f='y';

        string sTemp;

        char *t=GetTime();

        ofstream onfile;//寫入文件

        onfile.open("person.txt");

        do {

            cout<<"輸入卡號:";

            cin>>sTemp;

            onfile<<sTemp<<"    ";

            person[n].cardNum = sTemp;

            cout<<"請輸入用戶名:";

            cin>>sTemp;

            onfile<<sTemp;

            onfile<<sTemp<<"    ";

            person[n].cardName = sTemp;

            onfile<<0<<"    ";//余額默認是0

            person[n].money = 0;

            sTemp = t;

            onfile<<sTemp<<"  ";//開戶時間

            person[n].beginTime = sTemp;

            onfile<<0;//0代表沒有掛失,正常使用

            person[n].useState = false;

            onfile<<"\n";

            ++n;

            cout<<"還要繼續開戶嗎?(y/n)";

            cin>>f;

        } while (f=='y');

    }

    //銷戶

    void deletePerson(Person person[],int &n,string delname)

    {

        int i;

        int j=0;

        for (i = 0; i<n; i++) {

            if (person[i].cardName == delname) {

                for (j=i; j<n-1; j++) {

                    person[j].cardName = person[j+1].cardName;

                    person[j].cardNum = person[j+1].cardNum;

                    person[j].money = person[j+1].money;

                    person[j].beginTime = person[j+1].beginTime;

                    person[j].useState = person[j+1].useState;

                }

                n--;

                i--;

            }

        }

        //從寫入文件

        ofstream onfile;//寫入文件類

        onfile.open("Person.txt");

        for (int i=0; i<n; i++) {

            onfile<<person[i].cardNum<<"    "<<person[i].cardName<<"    "<<person[i].money<<"   "<<person[i].beginTime<<"   "<<person[i].useState<<"\n"<<endl;

        }

        onfile.close();

    }

    //修改卡的信息

    void alterPerson(string name,Person person[],int &n)

    {

        int i=findPerson(person, total, name);

        if(i<0)

        {

            cout<<"對不起,沒有該賬戶!"<<endl;

        }

        else

        {

            double _money;

            string sTemp;

            int jj;

            cout<<"從新修改賬戶信息:"<<endl;

            cout<<"修改賬戶號:";

            cin>>sTemp;

            person[i].cardNum = sTemp;

            cout<<"修改賬戶名:";

            cin>>sTemp;

            person[i].cardName = sTemp;

            cout<<"修改賬戶余額:";

            cin>>_money;

            person[i].money = _money;

            cout<<"修改掛失/解鎖(1.掛失 2.解鎖)";

            cin>>jj;

            if (jj==1) {

                person[i].useState = true;

            }

            else

            {

                person[i].useState = false;

            }

        }

        //將信息重寫入文檔

        ofstream onfile;//寫入文件類

        onfile.open("Person.txt");

        for (int i=0; i<n; i++) {

            onfile<<person[i].cardNum<<"    "<<person[i].cardName<<"    "<<person[i].money<<"   "<<person[i].beginTime<<"   "<<person[i].useState<<"\n"<<endl;

        }

        onfile.close();

       

    }

    //選擇某用戶卡的掛失和解鎖

    void chooseUseFunction(string name,Person person[],int &n)

    {

        int i=findPerson(person, total, name);

        if(i<0)

        {

            cout<<"對不起,沒有該賬戶!"<<endl;

        }

        else

        {

            int jj;

            cout<<"修改掛失/解鎖(1.掛失 2.解鎖)";

            cin>>jj;

            if (jj==1) {

                person[i].useState = true;

            }

            else

            {

                person[i].useState = false;

            }

        }

        //將信息重寫入文檔

        ofstream onfile;//寫入文件類

        onfile.open("Person.txt");

        for (int i=0; i<n; i++) {

            onfile<<person[i].cardNum<<"    "<<person[i].cardName<<"    "<<person[i].money<<"   "<<person[i].beginTime<<"   "<<person[i].useState<<"\n"<<endl;

        }

        onfile.close();

 


    }

    //用戶查詢(查詢所有的卡信息)

    void showAllCard(Person person[],int &n)

    {

        cout<<"當前有"<<n<<"條記錄:"<<endl;

        PrintPersonTitle();

        for (int i=0; i<n; i++) {

            cout<<person[i].cardNum<<"   "<<person[i].cardName<<"   "<<person[i].money<<"   "<<person[i].beginTime<<"   "<<person[i].useState<<endl;

        }

    }

};

 


/*********************************************************************/

 


void IdMenu(Manager &manager);//身份菜單響應

void managermenu(Manager &manager);//管理員菜單相應

void personmenu();//用戶菜單

 


/********************函數定義*****************************************/

//獲取當前系統時間

char* GetTime()

{

    {

        time_t now;

        struct tm *timenow;

        time(&now);

        timenow = localtime(&now);

    char *p = asctime(timenow);

    return p;

    }

}

//身份菜單響應

void IdMenu(Manager &manager)

{

    Show_Iden_menu();//菜單顯示

    switch (get_Idemenu_choice())

    {

        case 1:

        {

            //進入管理員身份驗證

            string n,s;

            cout<<"請輸入管理員賬號:";

            cin>>n;

            cout<<"請輸入管理員密碼:";

            cin>>s;

            if (ISManager(n, s)) {

                managermenu(manager);

            }

            else

            {

                cout<<"驗證錯誤"<<endl;

            }

        }

            break;

        case 2:

            //進入客戶身份驗證

           

        {

            string n,s;

            cout<<"請輸入賬戶名:";

            cin>>n;

            cout<<"請輸入賬戶密碼:";

            cin>>s;

//            if (ISManager(n, s)) {

//                managermenu(manager);

//            }

            if (ISPerson(n,s)) {

                cout<<"驗證用戶成功"<<endl;

               

            }

            else{

                cout<<"驗證用戶失敗";

            }

        }

            break;

        default:

            cout<<"選擇錯誤"<<endl;

            break;

    }

   

   

}

//驗證客戶信息

bool ISPerson(string &name,string &pwd)

{

    int i=0;

    string password="dingxiaowei";

    for (i=0; i<total; i++) {

        if(person[i].cardName == name&&password==pwd);

        {

            return true;

            break;

        }

    }

    if (i==total) {

        return false;

    }

}

//驗證管理員身份

bool ISManager(string &name,string &pwd)

{

    string n,p;

    ifstream infile;//讀取文件類

    infile.open("manager.txt");

    if(infile.is_open())

    {

        infile>>n>>p;

    }

    else

    {

        cout<<"打開失敗!";

    }

    if (n==name&&p==pwd)

    {

        return true;

    }

    else

    {

        return false;

    }

}

//管理員菜單相應

void managermenu(Manager &manager)

{

    bool flag = false;

    do

    {

        Show_Managermenu();//顯示菜單

        switch (get_managermenu_choice()) {

            case 1://增加記錄

                manager.addPerson(person, total);

                break;

            case 2://刪除記錄

            {

                cout<<"請輸入您要銷戶的名字:";

                string name;

                cin>>name;

                manager.deletePerson(person, total, name);

            }

                break;

            case 3://查詢記錄

            {

                cout<<"請輸入您要修改的賬戶名:";

                string name;

                cin>>name;

                manager.alterPerson(name, person, total);

            }

                break;

            case 4://修改記錄

            {

                cout<<"請輸入您修改掛失或解鎖的賬戶名:";

                string name;

                cin>>name;

                manager.chooseUseFunction(name, person, total);

            }

                break;

            case 5://查詢所有記錄

                manager.showAllCard(person, total);

                break;

            case 0:

                flag = true;

                IdMenu(manager);//返回上一級

                break;

            default:

                printf("*************************\n");

                printf("  歡迎再次使用本系統,謝謝    \n");

                printf("*************************\n");

                break;

        }

    }while (flag==false);

}

//打印個體用戶頭信息

void PrintPersonTitle()

{

    cout<<"--------------------------------------------------------\n";

    cout<<"  卡號        用戶名       余額      開戶日期      是否掛失  \n";

    cout<<"--------------------------------------------------------\n";

}

 

 

 

//設置密碼

void set_psw()

{

    ofstream onfile;//寫入文件類

    string psw_set ,psw_check;

    do

    {

        cout<<"You must set password first!\n";

        cin>>psw_set;

        cout<<"conform password:";

        cin>>psw_check;

        if(psw_check == psw_check)

        {

            cout<<"set password success!\n";

        }

        else

        {

            cout<<"error!\n";

        }

    }

    while(psw_check != psw_set);

    onfile.open("password.txt",ios::out);

    onfile<<psw_set;

    onfile.close();

}

 

 

 

//密碼驗證

int psw_check()

{

    ifstream infile;//讀取文件類

    ofstream onfile;//文件寫入類

    unsigned int j=1;

    string pword;

    string password;

    infile.open("password.txt",ios::in);

    if (!infile.is_open())//如果打開失敗,則重新設置密碼

    {

        set_psw();//重新設置密碼

    }

    //取值

    infile>>password;

    //打開成功驗證密碼

    do {

        cout<<"輸入密碼,你將有三次機會:"<<j<<"/3次機會"<<endl;

        cin>>pword;

        j++;

    } while (password != pword && j<=3);

    if (j<=3) {

        cout<<"恭喜登陸成功!"<<endl;

        return 1;//打開成功

    }

    else

    {

        cout<<"你已經輸入了三次了,打開文件失敗!"<<endl;

        return 0;

    }

 


}

//身份選擇菜單

void Show_Iden_menu()

{

    cout<<">>>>>>>>>>>>>>>>>歡迎您使用銀行管理系統<<<<<<<<<<<<<<<<<<<<\n";

    cout<<"*******************************************************\n";

    cout<<"          1.銀行管理員     |         2.普通用戶            \n";

    cout<<"*******************************************************\n";

}

//顯示管理員菜單

void Show_Managermenu()

{

    cout<<">>>>>>>>>>>>>>>歡迎您使用銀行管理員管理系統<<<<<<<<<<<<<<<<\n";

    cout<<"******************************************************\n";

    cout<<"          1.開戶          |        2.銷戶              \n";

    cout<<"          3.修改卡號信息   |        4.掛失/解鎖           \n";

    cout<<"          5.查詢所有記錄   |        0.返回上級            \n";

    cout<<"******************************************************\n";

}

//顯示普通用戶功能菜單

void Show_PersonMenu()

{

    cout<<">>>>>>>>>>>>>>歡迎您使用銀行客戶管理系統<<<<<<<<<<<<<<<<<<<<\n";

    cout<<"******************************************************\n";

    cout<<"          1.查詢余額       |        2.掛失/解鎖          \n";

    cout<<"          3.存款          |        4.取款              \n";

    cout<<"          0.返回上級       |                            \n";

    cout<<"******************************************************\n";

}

//普通用戶接受菜單

int get_personmenu_choice()

{

    int personmenu_ch;//菜單選項

    do {

        cout<<"請選擇功能:";

        cin>>personmenu_ch;

        if (personmenu_ch<0||personmenu_ch>4) {

            cout<<"輸入有誤!"<<endl;

        }

    } while (personmenu_ch<0||personmenu_ch>4);

    return personmenu_ch;

}

//接受身份菜單選擇

int get_Idemenu_choice()

{

    int idmenu_ch;//菜單選項

    do {

        cout<<"請選擇身份:";

        cin>>idmenu_ch;

        if (idmenu_ch<1||idmenu_ch>2) {

            cout<<"輸入有誤!"<<endl;

        }

    } while (idmenu_ch<1||idmenu_ch>2);

    return idmenu_ch;

}

//接受菜單選擇

int get_managermenu_choice()

{

    int menu_ch;//菜單選項

    do {

        cout<<"請選擇菜單:";

        cin>>menu_ch;

        if (menu_ch<0||menu_ch>5) {

            cout<<"error";

        }

    } while (menu_ch<0||menu_ch>5);

    return menu_ch;

}

int main(int argc, const char * argv[])

{

    Manager manager;

    if (psw_check()) {

        IdMenu(manager);

    }

    return 0;

}

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved