Simulation of ATM Teller machine--The data structure course set

Source: Internet
Author: User

Today to help people write. second lesson set, ;-) The nest of Wit

requirements: Probably say, is to create a user (initial Start account), simulating ATM business (withdrawals, 100 integers, changing passwords, checking balances, etc.), a variety of simple and cumbersome operations ;-)  )

Directly paste the code bar:

#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <string >using namespace Std;class consumer;class ATM//ATM cash Machine {PUBLIC:ATM (consumer& cn): Cnsm (cn) {} void Welcome        (); Login interface bool CHECK_PASSWD (char N[],char pwd[]);     Check password void change_passwd ();        Change password void Fetchmoney ();            withdrawal void information ();            Query information void Exitatm ();      Exit system void Functionshow ();              Functional interface void lock ();               Lock Machine private:int times; Record password input times consumer& cnsm;};    Class Consumer//user {Public:friend class ATM;              Consumer (char Name[],char num[],float money,char password[]);p rotected:char* get_name ();               Acquired name Char* Get_num ();            Get the card number char* get_passwd ();             Get password float Get_money ();   Get balance void set_passwd (char pwd[]);       Set password void Set_money (float m); Take Money Private:char PASSWD[8];     User password char name[20];    User name Char num[20]; float money;};    Consumer::consumer (char Name[],char num[],float Money,char password[]) {strcpy (name,name);    strcpy (Num,num);    Money=money; strcpy (Passwd,password);} Float Consumer::get_money () {return money;} char* Consumer::get_name () {return name;} char* Consumer::get_num () {return num;} char* consumer::get_passwd () {return passwd;} void Consumer::set_money (float m) {money-=m;} void consumer::set_passwd (char pwd[]) {strcpy (passwd,pwd);}    void Atm::welcome () {times=0;    cout<< "Welcome to Tdap Bank ATM" << Endl;    Char pwd[8],num[20],ch;    int i=0;        do {i=0;        cout<< "Please enter card number:";            do {cin.get (ch);        Num[i++]=ch;            }while (ch!= ' \ n ');        num[i-1]= ' + ';        i=0;        cout<< "Please enter password:";            do {cin.get (ch);        Pwd[i++]=ch;        }while (ch!= ' \ n ');        pwd[i-1]= ' + '; if (!check_passWD (NUM,PWD)) {cout<< "the card number or password you entered is incorrect, please re-enter" <<endl;        times++;        } else {functionshow ();    }}while (times<3); Lock ();} BOOL Atm::check_passwd (char Num[],char pwd[]) {if (strcmp (Num,cnsm.get_num ()) ==0&&strcmp (pwd,cnsm.get_ passwd ()) ==0) return true; else return false;}   void Atm::functionshow () {int n;        do{cout<< "Please enter the corresponding operation sequence number to operate:" <<endl; cout<< "1) Change Password" <<endl<< "2" withdrawal "<<endl<<" 3) Check balance "<<endl<<" 4) exit system "<<        Endl        cout<< "$ >";        cin>>n; while (n<1| | n>4) {cout<< "Please enter the correct operation sequence number!"            <<endl;            cout<< "$ >";        cin>>n;   } switch (n) {case 1:change_passwd ();            Break      Case 2:fetchmoney ();            Break     Case 3:information ();            Break         Case 4:exit (0);        Break }    }while (true);}    void atm::change_passwd () {char pwd[8],repwd[8];    times=0;        do{cout<< "Please enter the old password:";        cin>>pwd;        if (!CHECK_PASSWD (Cnsm.get_num (), PWD)) times++;    else break;    }while (times<3);    if (times==3) lock ();    int t=0;        do{cout<< "Please enter a new password:";        cin>>pwd;        cout<< "Please enter the new password again:";        cin>>repwd; if ((t=strcmp (PWD,REPWD))!=0) cout<< "you entered two times the password is not the same, please new input!"    <<endl;    }while (t!=0);    CNSM.SET_PASSWD (PWD); cout<< "Password modified successfully, please remember!" << Endl;}   void Atm::fetchmoney () {int m;   Char ch;        do{cout<< "How much money do you want to take:" <<endl<< "$>";        cin>>m; while (m<=0 | | m%100!=0) {cout<< "Please enter the correct number!"            <<endl;            cout<< "$>";        cin>>m; } if (Cnsm.get_money ()-m<0) {cout<< "Sorry, your balance is not enough!"        <<endl; }else{cout<< "The operation is successful, please collect the money!" << endl;;        Cnsm.set_money (m);       } cout<< "Do you want to continue this operation: (y/n)" <<endl;       cout<< "$ >";        cin>>ch;            while (ch!= ' n ' &&ch!= ' n ' &&ch!= ' y ' &&ch!= ' y ') {cout<< "$ >\\";        cin>>ch; }}while (ch== ' Y ' | | ch== ' Y ');}    void Atm::information () {cout<< "**********************************" <<endl;    cout<< "*" <<endl;    cout<< "* User name:" << cnsm.get_name () <<endl;    cout<< "* Card number:" << cnsm.get_num () <<endl;    cout<< "* Balance:" << Cnsm.get_money () <<endl; cout<< "**********************************" &LT;&LT;ENDL;} void Atm::lock () {cout<< "Sorry, your card has been confiscated due to your incorrect operation!?"    <<endl;    cout<< "Please take card ..." <<endl; Exit (0);}    int main () {Consumer C1 ("Jim", "12345", 10000.0f, "123");//First construct a user ATM ATM (C1);    Atm.welcome (); return 0;}



Simulation of ATM Teller machine--The data structure course set

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.