Банкомат перевод денег

Я пытаюсь построить симулятор банкомата с C++, но я не знаю, как организовать передачу между двумя учетными записями, функцией проверки класса учетных записей. Я пытался встроить его в основной класс, но... почему бы не изменить значение баланса?

#include <iostream>
using namespace std;

class account
{
    protected:
    string cust_name;
    int  acc_no;
    int  acc_pass;
    public:
       virtual void set_info()
       {
       cout<<"Enter Customer Name : ";
       cin>>cust_name;
       cout<<"Enter Account Number : ";
       cin>>acc_no;
       cout<<"Enter Accout Password:";
       cin>>acc_pass;
       }
       int get_accno(){
          return this->acc_no;
       }
       int get_accpass(){
          return this->acc_pass;
       }
       string get_name(){
          return this->cust_name;
       }
       virtual void display_accinfo()
       {
          cout<<cust_name<<"\t\t\t"<<acc_no<<endl;
       }
       virtual void deposit(){}
       virtual void withdraw(){};
       virtual void transper(){};
       virtual float  getbal(){};
       virtual void setbal(float &balance){};
};

class check_acct : public account
{
  float balance;
  int lim;

  public:
       virtual void set_info(){
       cout<<"Enter Customer Name : ";
       cin>>cust_name;
       cout<<"Enter Account Number : ";
       cin>>acc_no;
       cout<<"Enter Accout Password:";
       cin>>acc_pass;
       cout<<"Enter available balance:";
       cin>>balance;
       cout<<"Enter limit transper money: ";
       cin>>lim;
       }        

       virtual void display_accinfo()
       {
          cout<<cust_name<<"\t\t\t"<<acc_no<<"\t\t\t"<<balance<<endl;
       }      
       virtual float getbal(){
          return balance;
       }
       virtual void deposit()
       { 
          float deposit;
          cout<<"\nEnter amount to Deposit : ";
          cin>>deposit;
          balance = balance + deposit;
          cout<<"\nNow your available balance is"<<balance<<endl;
       }
       virtual void withdraw()
       {
          float withdraw;
          cout<<"\nBalance : "<<balance;
          cout<<"\nEnter amount to be withdraw : ";
          cin>>withdraw;
          if(withdraw > balance)
          {
              cout<<"\n\nThe withdraw amount must be smaller than you 
              available balance\n";
          }
          else
          balance=balance-withdraw;       
          cout<<"\nAfter Withdrawl your Balance has : "<<balance<<endl;
       }
       virtual void setbal(float &balance){
          balance=balance;
       }    

// Я намерен создать эту функцию здесь

       virtual void transer(account **a){
    }   
};

class sav_acct : public account
{
//  float savbal;
float balance;
  public:
    virtual void set_info(){
    cout<<"Enter Customer Name : ";
    cin>>cust_name;
    cout<<"Enter Account Number : ";
    cin>>acc_no;
    cout<<"Enter Accout Password:";
    cin>>acc_pass;
    cout<<"Enter saving balance:";
    cin>>balance;
  }
  virtual float getbal(){
     return balance;
  }
  virtual void setbal(float &balance){
     balance=balance;
  }
  virtual void display_accinfo()
  {
    cout<<cust_name<<"\t\t\t"<<acc_no<<"\t\t\t"<<balance<<endl;
  }   

  virtual void deposit()
  {
    float deposit,interest;
    cout<<"\nEnter amount to Deposit : ";
    cin>>deposit;
    balance = balance + deposit;
    interest=(balance*2)/100;
    balance=balance+interest;
    cout<<"\nNow your available saving balance is "<<balance<<endl;
  }
  virtual void withdraw()
  {
    float withdraw;
    cout<<"\nBalance : "<<balance;
    cout<<"\nEnter amount to be withdraw : ";
    cin>>withdraw;
    if(withdraw > balance)
  {
  cout<<"\n\nWithdraw amount must be smaller than your available balance \n";
  }
  else{
  balance=balance-withdraw;
  cout<<"\nAfter Withdrawl your Balance has : "<<balance;
 }      
}
};

class manage:public account{

int n,no;

int choice;
account **a;
public:
manage(){

cout<<"Enter amount of account you need to creat:";
cin>>n;

a=new account *[n];
}
void input(){
for(int i=0;i<n;i++){
    cout<<"\n1.Checking\n2.Savings"<<endl;
    cin>>choice;
    if(choice==1){
        a[i]=new check_acct();
    }
    if(choice==2){
        a[i]=new sav_acct();
    }
    cout<<"\nEnter info of account "<<i+1<<":"<<endl;   
    a[i]->set_info();   
    }
}

void output(){
cout<<"Accounts list"<<endl;
cout<<"Account num"<<"\t\t"<<"ID"<<"\t\t\t"<<"Balance"<<endl;
    for(int i=0;i<n;i++){
        a[i]->display_accinfo();

    }
}



void function(){
    int count=0;
    int ndn =-1;
    int check=-1;
    account a1;
    while (ndn <0)
    {
        a1.set_info();
        for(int i=0;i<n;i++){
            if(a1.get_accno()==a[i]->get_accno() && a1.get_accpass()==a[i]- 
        >get_accpass()){
                cout<<"Login success!"<<endl;
                ndn=i;  
            }   
        }
        count++;
        if(count>=3){
            cout<<"Login attempt limited ( less than 3 times )";
            exit(0);
        }           
       }
        int n1=a1.get_accno()-1;
        cout<<"\nChoose Your Choice\n";
        cout<<"1)   Deposit\n";
        cout<<"2)   Withdraw\n";
        cout<<"3)   Display with full Details\n";
        cout<<"4)   Transfer to another account\n";
        cout<<"5)   Exit\n";
        cout<<"6)   Choose Your choice:";       
        cin>>choice;
        switch(choice){
        case 1:     
        a[n1]->deposit();break;
        case 2:
        a[n1]->withdraw();break;
        case 3:
        cout<<"Account num"<<"\t\t"<<"ID"<<"\t\t\t"<<"Balance"<<endl;               
        a[n1]->display_accinfo();break;

Я временно построил передаточную функцию здесь, но возвращаемое значение указывает, что баланс не имеет каких-либо изменений

        case 4: float trans;
        int n2;
        int ndn2=-1;
        while(ndn2<0){
            cout<<"Enter account number that need to transper: ";
            cin>>n2;
            for(int i=0;i<n;i++){       
                if(n2==a[i]->get_accno()){
                    cout<<"Valid account!"<<endl;
                    ndn2=i;
                }   
            }
        }   
        do{
            cout<<"\nEnter amount that need to transper ( must be smaller 
than your balance and smallest amount is 5000 ): ";
            cin>>trans; 
            }
        while(trans>a[n1]->getbal() && trans<5000);
        float newbal;
        newbal=a[n1]->getbal()-trans;
        a[1]->setbal(newbal);
        cout<<"Transper success! Now your available balance is:"<<a[n1]- 
        >getbal()<<endl; 
        float newbal2=a[n2]->getbal()+trans; 
        a[2]->setbal(newbal2);
        break;                              
        }
    }
};

int main()
{   
    manage r;
    r.input();
    r.output();
    r.function();         
    r.output();             
    return 0;
}

0 ответов

Другие вопросы по тегам