Sunday, March 20, 2016

Code ATM C++

#include
#include  //function for exit.or stdio.h
using namespace std;
 class ATM{
  string userName;
  string password;
  public:
   string getUserName(){return userName;}
   string getPassword(){return password;}
  ATM(string user,string pass){
   userName=user;
   password=pass;
  }
  void login(){
   string name;
   string pass;
   int count=1;
   do{
    cout<<"****** Welcome My ATM *******"<<"\n";
    cout<<"Please input your name: ";
    getline(cin,name);
    cout<<"Input password: ";
    getline(cin,pass);
    count++;
    if(count>3){
     cout<<"you have logined only 3 times!";
     exit(0);
    }
    system("cls");
   }while(name!=getUserName()||pass!=getPassword());
   cout<<"Login success!"<<"\n";
  }


 };
int A;int wm; //wm=money that withdraw
float bal=0;
float balance();
float menu();
float withdraw();
float deposit();
float information();
float D;//D=money that you dispost

int main(){
 {
 ATM us("chan","123");
 us.login();
    //call function login for prepare with constructor User(string user,string pass).
 cin.sync();
 cin.get();
}
// system("pause");
 menu();
 system("pause");
 return 0;
  }
float menu(){
    do{
 system("cls");
    cout<<"1.check Balance"<    cout<<"2.Withdraw"<    cout<<"3.Deposit"<    cout<<"4.Show Information"<    cout<<"5.EXIT"<    cout<<"Select number: ";
     cin>>A;
    }while(A<1>5);
       switch(A){
     case 1: balance();break;
     case 2: withdraw();break;
     case 3: deposit();break;
  case 4: information();break;
        case 5: exit(0);
     default:
  exit(0);
  }
    }
float balance(){
    system("cls");
    cout<<"Your balance is $ "<    system("pause");
    menu();
    return 0;
}
float withdraw()
{
    system("cls");
    do{
 cout<<"\n 1. $20"< cout<<"\n 2. $60"< cout<<"\n 3. $100"< cout<<"\n 4. $200"< cout<<"\n 5. back to menu"< cout<<"\nselect number that you want withdraw: ";
 cin>>wm;  //wm=Withdraw menu;
 cout<    }while(wm<1 wm="">5);
    switch(wm){
 case 1:
     if(bal<20 br="" cls="" system="">  cout<<"\nyour money is enough"<
  cout<<"\nyour have only : $"<  cout<  system("pause");
     }
     else
     {system("cls");
  cout<<"\nsuccess with  your withdraw :$" <<20 br="" endl="">  bal=bal-20;
  cout<<"New Balance : $"<     }break;
 case 2:
     if(bal<60 br="" cls="" system="">  cout<<"\nyour money is enough"<  cout<<"\nyour have only : $"<  cout<  system("pause");
     }
     else
     {system("cls");
  cout<<"\nsuccess with  your withdraw: $"<<60 br="" endl="">  bal=bal-60;
  cout<<"New Balance : $"<     }break;
 case 3:
     if(bal<100 br="">  cout<<"\nyour money is enough"<  cout<<"\nyour have only : $"<  cout<  system("pause");
     }
     else
     {system("cls");
  cout<<"\nsuccess with  your withdraw: $"<<100 br="" endl="">  bal=bal-100;
  cout<<"New Balance : $"<     }break;
 case 4:
     if(bal<200 br="">  cout<<"\nyour money is enough"<  cout<<"\nyour have only : $"<  cout<  system("pause");
     }
     else
     {
  system("cls");cout<<"\nsuccess with  your withdraw: $"<<200 br="" endl="">  bal=bal-200;
  cout<<"New Balance : $"<     }break;
 case 5:
     cout<<"\nEXITING WITHDRAW MENU..."<     system("pause");
     system("cls");
     menu();
     break;
 }
 system("pause");
 menu();
 return 0;
    }
float deposit()
    {
 system("cls");
 cout<<"Input money: $";
 cin>>D;
 bal=bal+D;
 cout<<"Depositing $"< cout<<"now your balance is: $"< cout<<"Thank You!"< cout< system("pause");
 menu();
 return 0;
    }
float information(){
    system("cls");
    cout<<"Welcome to my information"<    cout<<"*************************"<    system("pause");
    menu();
    cout<    }

No comments:

Post a Comment