Course Training (banking system)

Source: Internet
Author: User
Tags strcmp

/*
*copyright (c) 2015, College of Computer Science, Yantai University
*all rights reserved.
* File name: 19th week (banking system)

* Wangzhong
* Completion Date: 2015.7.17

* Version Number: v1.0
*
* Problem Description: Make a simple, similar program to the current bank ATM

* Input Description: Follow the menu bar prompts to enter

* Program output:

#ifndef head_h_included#define head_h_included#include <fstream> #include <cstdlib> #include <conio.h > #include <cstring>using namespace std;class bank;class user{public:void setuser (int acc,string nam,int Pw,do    Uble bal,int Sta,char id[18],string Add);    void Showuser ();//Display name void Showbalance (String prompt);//Show balance bool Passwordright ();//Verify password bool Staisnor ();//Validation status    Friend class Bank;private:int account;    String name;    int password;    Double balance;    int status;    Char userid[18]; string address;};    Class Bank{public:bank ();    ~bank (); void work ();//working void OPENACC ();//account void Cancelacc ();//PIN void Save ();//deposit void withdraw ();//withdrawal void Showa CC ();//check balance void Transferacc ();//Transfer void Reloss ();//Loss of void Cancelloss ();//cancellation of void Repassword ();/Change Password in T GetUser ();p rivate:int num;//number of users user *users;}; int Inputpassword ();//input password int pass ();//salesman int choosemenu ();//Service list #endif//head_h_included


#include <iostream> #include "head.h" using namespace Std;int Main () {    cout<< "+----------------------+ \ n ";    cout<< "+  »¶ó¹âáù¿óäãµãòøðð  +\n";    cout<< "+----------------------+\n";    if (pass ())    {        Bank b;        B.work ();    }    return 0;}


#include <iostream> #include "head.h" using namespace std;void user::setuser (int acc,string nam,int pw,double Bal, int Sta,char id[18],string Add) {    ACCOUNT=ACC;    Name=nam;    PASSWORD=PW;    Balance=bal;    Status=sta;    for (int i=0;i<10;i++)      userid[i]=id[i];    Address=add;} void User::showuser () {    cout<< "user name:" <<NAME<<ENDL;} void User::showbalance (String prompt) {    cout<<prompt<< "" <<balance<< "meta" <<ENDL;} BOOL User::p asswordright () {    bool t=true;    int pass;    cout<< "Please enter password:";    Pass=inputpassword ();    if (Pass!=password)    {        t=false;        cout<< "Password Error" <<endl;    }    return t;} BOOL User::staisnor () {    bool nor=true;    if (status!=0)    {        nor=false;        cout<< "The account is in" << (status==1? ") Reporting ":") << status <<endl;    }    return nor;}


#include <iostream> #include "head.h" using namespace std;    Bank::bank () {ifstream infile ("Account.txt", ios::in);        if (!infile) {cerr<< "account open Error" <<endl;    Exit (1);    } int i=0;    Users=new user[i+2000];    int acc;    String Nam;    int pw;    Double bal;    int STA;    Char id[18];    string add; while (Infile>>acc>>nam>>pw>>bal>>sta>>id>>add) {Users[i].setuser (ACC,        Nam,pw,bal,sta,id,add);    i++;    } num=i; Infile.close ();}    Bank::~bank () {ofstream outfile ("Account.txt", ios::out);        if (!outfile) {cerr<< "account open Error" <<endl;    Exit (1);        } for (int i=0; i<num; i++) {outfile<<users[i].account<< "";        outfile<<users[i].name<< "";        outfile<<users[i].password<< "";        outfile<<users[i].balance<< "";        outfile<<users[i].status<< ""; Outfile<<users[i].userid<< "";    outfile<<users[i].address<<endl;    } outfile.close (); Delete[]users;}    void Bank::work ()//work {int choose;        do {choose=choosemenu ();            Switch (choose) {case 1:OPENACC ();        Break            Case 2:CANCELACC ();        Break            Case 3:save ();        Break            Case 4:withdraw ();        Break            Case 5:SHOWACC ();        Break            Case 6:TRANSFERACC ();        Break            Case 7:reloss ();        Break            Case 8:cancelloss ();        Break            Case 9:repassword ();        Break        Case 0:cout<< "Welcome to next time" <<endl; }} while (choose);}    void Bank::openacc ()//Open Account {Bank ();    int acc;    String Nam;    int pw;    Double bal;    int STA;    Char id[18];    string add; cout<< "is opening an account ..." << Endl;    Acc=10001+num;    cout<< "account name:" <<acc<<endl;    cout<< "User name:";    cin>>nam;    cout<< "ID number:";    cin>>id;    cout<< "Home address:";    cin>>add;    int pass1,pass2;    cout<< "Please enter password:";    Pass1=inputpassword ();    cout<< "Please Confirm password:";    Pass2=inputpassword ();        if (pass1==pass2) {pw=pass1;        sta=0;        cout<< "Deposit Amount:";        cin>>bal;        Users[num].setuser (Acc,nam,pw,bal,sta,id,add);        num++;    cout<< "Successful opening" <<endl; } else cout<< "two times input password inconsistent, open account not successful" &LT;&LT;ENDL;}    void Bank::cancelacc ()//PIN household {int who;    Who=getuser ();        if (who>=0) {users[who].showuser ();            if (Users[who].passwordright ()) {users[who].showbalance ("balance");            cout<< "Confirm pin (y/n)?";                if (ToLower (GetChar ()) = = ' Y ') {users[who].showbalance ("The account is successful, the withdrawal amount is:");                users[who].balance=0; Users[who].status=2; } else cout<< "The user has canceled the operation and the pin has failed."            <<endl;        Fflush (stdin);    }}}void Bank::save ()//deposit {int who;    Double money;    Who=getuser ();            if (who>=0) {if (users[who].status==0) {users[who].showuser ();            cout<< "Please enter the deposit amount:";            cin>>money;            Ofstream file ("Save.txt", Ios::app);                if (!file) {cerr<< "Save open Error" <<endl;            Exit (1);            } file<<users[who].account<< "Deposit" <<money<<endl;            File.close ();            int D;            Double S;            cout<< "Please enter the number of days you wish to deposit:";            cin>>d;            S=0.036/365*d*money;            cout<< "Your interest after expiry:" <<s<<endl;            Money+=s;            Users[who].balance+=money;        Users[who].showbalance ("Deposit success, Balance:");       } else if (users[who].status==1)     cout<< "The user is in a lost state and the deposit failed."        <<endl; Else cout<< "The user has sold the account and the deposit failed."    <<endl; } return;    void Bank::withdraw ()//withdrawals {int who;    Double money;    Who=getuser ();            if (who>=0) {if (Users[who].staisnor ()) {users[who].showuser ();                if (Users[who].passwordright ()) {cout<< "Please enter the withdrawal amount:";                cin>>money; if (money>users[who].balance) cout<< "Insufficient balance, withdrawal failed."                <<endl;                    else {Users[who].balance-=money;                    Ofstream file ("Save.txt", Ios::app);                        if (!file) {cerr<< "Save open Error" <<endl;                    Exit (1);                    } file<<users[who].account<< "Remove" <<money<<endl;                    File.close (); Users[who].showbalance("After the withdrawal, the balance is:"); }}}} return;}    void Bank::showacc ()//query {int who,a;    String rep;    Char b;    String sta[3]= {"Normal", "Report Loss", "has been distributed"};    Who=getuser ();        if (who>=0) {users[who].showuser ();            if (Users[who].passwordright ()) {users[who].showbalance ("balance:");            cout<< "Status:" <<sta[users[who].status]<<endl;            cout<< "ID Number:" <<users[who].userID<<endl;            cout<< "Home Address:" <<users[who].address<<endl;            cout<< "Do you want to check your account history? (y/n)" <<endl;            cin>>b;                if (b== ' y ') {ifstream file ("Save.txt", ios::in);                    if (!file) {cerr<< "Save open Error" <<endl;                Exit (1);                        } while (File>>a) {if (A==users[who].account) { File>>rep;                    cout<<rep<< "";                } else file>>rep;            } file.close (); }}} return;}    void Bank::transferacc ()//transfer {int whoout,whoin;    Double money;    cout<< "Transfer out account:";    Whoout=getuser ();            if (whoout>=0) {if (Users[whoout].staisnor ()) {users[whoout].showuser ();                if (Users[whoout].passwordright ()) {cout<< "Enter the transfer amount:";                cin>>money; if (money>users[whoout].balance) cout<< "Insufficient balance, transfer failed."                <<endl;                    else {cout<< "transfer to:";                    Whoin=getuser ();                            if (whoin>=0) {if (Users[whoin].staisnor ()) {        Users[whoout].balance-=money;                    Users[whoin].balance+=money;                            Ofstream file ("Save.txt", Ios::app);                                if (!file) {cerr<< "Save open Error" <<endl;                            Exit (1); } file<<users[whoout].account<< "Transfer to" &LT;&LT;USERS[WHOIN].ACCOUNT&LT;&LT;MONEY&LT;&L                            T;endl;                            file<<users[whoin].account<< "Received" <<users[whoout].account<<money<<endl;                            File.close ();                        Users[whoout].showbalance ("After the transfer, the balance is:"); }}}}}} return;}    void Bank::reloss ()//report loss {int who;    Who=getuser ();        if (who>=0) {users[who].showuser ();              if (Users[who].passwordright ()) {if (users[who].status==0) {  Users[who].status=1;                cout<< "loss Success" <<endl; cout<< "If the bank withdraws the card, it will be mailed to:" <<users[who].address<< ", please confirm the information, please contact the bank."            <<endl; } else if (users[who].status==1) cout<< "The account is already in the reporting State."            <<endl; Else cout<< "The account has been sold and the report has failed."        <<endl; }} return;    void Bank::cancelloss ()//cancellation of loss of the report {int who;    Who=getuser ();        if (who>=0) {users[who].showuser (); if (Users[who].passwordright ()) {if (users[who].status==0) cout<< "The account is in a normal state without having to cancel the report."            <<endl;                else if (users[who].status==1) {users[who].status=0; cout<< "To cancel the loss of success."            <<endl; } else cout<< "The account has been distributed and the loss of the report has failed."        <<endl; }} return;    void Bank::repassword ()//change Password {int who;    int pass1,pass2;    Who=getuser (); if (who>=0) {        Users[who].showuser ();            if (Users[who].passwordright ()) {cout<< "New password:";            Pass1=inputpassword ();            cout<< "re-enter:";            Pass2=inputpassword ();                if (pass1==pass2) {users[who].password=pass1; cout<< "Change password successfully, remember the new password."            <<endl; } else cout<< "two times the password is different, the modification failed."        <<endl; }} return;    int Bank::getuser () {int id;    cout<< "account number:";    cin>>id;    int index=-1;    int low=0,high=num-1,mid;        while (Low<=high) {mid= (Low+high)/2;            if (users[mid].account==id) {index=mid;        Break        } else if (users[mid].account>id) high=mid-1;    else low=mid+1; } if (index<0) cout<< "The account does not exist."    <<endl; return index;}


 

#include <iostream> #include "head.h" using namespace Std;int Inputpassword () {char ch;    int ipass=0;    int i;            while (1) {for (i=0; i<6; i++) {ch=getch ();            Putchar (' * ');            if (IsDigit (CH)) ipass=ipass*10+ (ch-' 0 ');                else {ipass=0;            Break        }} fflush (stdin);        cout<<endl; if (ipass==0) {cout<< "Password requirements are all numbers, but not all 0."            <<endl;        cout<< "Please re-enter:";    } else break; } return ipass;}    int Pass () {char namefile[20];    Char passfile[20];    Ifstream infile ("Password.txt", ios::in); if (!infile) {cout<< "Password.txt open error."        <<endl;    Exit (1);    } infile>>namefile>>passfile;    Infile.close ();    Char sname[20];    Char spass[20];    Char ch;    int itry=3;    int right=0;  Do {cout<< "Please enter the clerk's name:";      cin>>sname;        cout<< "Please enter password:";        int i=0;            while ((Ch=getch ()) = ' \ r ') {spass[i++]=ch;        Putchar (' * ');        } spass[i]= ' + ';        Fflush (stdin);        cout<<endl;            if (strcmp (spass,passfile) ==0&&strcmp (sname,namefile) ==0) {right=1;        Break            } else {itry--; if (itry>0) cout<< "More than three times will exit, you can also try" <<itry<< "Times!"            <<endl; else cout<< "Sorry, you can't get into the system."        <<endl;    }} while (Itry); return right;}    int Choosemenu () {int i;        while (1) {cout<<endl<<endl;        cout<< "+-------------------+" <<endl;        cout<< "1 account opening 2 Sales 3 deposit" <<endl;        cout<< "4 Withdrawals 5 Enquiry 6 Transfer" <<endl;        cout<< "7 Report loss 8 9 change to Secret" <<endl;        cout<< "0 Exit" <<endl;    cout<< "Please enter operation instruction:";    cout<<endl<<endl;        cin>>i;        if (i>=0&&i<=9) break;    else cout<< "Please re-select:" <<endl; } return i;}


After a series of inspection, testing, bugs, garbled layers of challenges, and finally completed this simple program, in fact, not simple, haha haha

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Course Training (banking system)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.