Garey

Bank Account

Oct 9th, 2018
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <random>
  4.  
  5. using namespace std;
  6.  
  7. class BankAccount {
  8.     private:
  9.         string bankNumber;
  10.         string bankName;
  11.         string ownerName;
  12.        
  13.         double balance;
  14.     public:
  15.         BankAccount() {
  16.             this->bankNumber = "null";
  17.             this->bankName = "null";
  18.             this->ownerName = "null";
  19.             this->balance = 0.0;
  20.         }
  21.         BankAccount(string bankNumber, string bankName, string ownerName, double balance) {
  22.             this->bankNumber = bankNumber;
  23.             this->bankName = bankName;
  24.             this->ownerName = ownerName;
  25.             this->balance = balance;
  26.         }
  27.  
  28.         //get
  29.         string getBankNumber() { return this->bankNumber; }
  30.         string getBankName() { return this->bankName; }
  31.         string getOwnerName() { return this->ownerName; }
  32.  
  33.         double getBalance() { return this->balance; }
  34.  
  35.         //set
  36.         void setBankNumber(string number) { this->bankNumber = number; }
  37.         void setBankName(string bankName) { this->bankName = bankName; }
  38.         void setOwnerName(string ownerName) { this->ownerName = ownerName; }
  39.  
  40.         void setBalance(double balance) { this->balance = balance; }
  41.  
  42.         // Abstract
  43.         void deposit(double value) { this->balance += value; }
  44.         void withdraw(double value) { this->balance -= value; }
  45.         void generate() {
  46.             string names[4] = { "Toshko", "Goshko", "Chochko", "Neshto" };
  47.             string bankNames[4] = { "DSK", "BNB", "RBB", "CCB" };
  48.  
  49.             //////////////////////////////////////////////////////////////////
  50.             // Random Generating                                            //
  51.             //////////////////////////////////////////////////////////////////
  52.             random_device rd;
  53.             mt19937 gen(rd());
  54.             //////////////////////////////////////////////////////////////////
  55.             uniform_int_distribution<> random_names(0, 4);
  56.             uniform_int_distribution<> random_banks(0, 4);
  57.             uniform_int_distribution<> random_bank_number(100000, 999999);
  58.             uniform_real_distribution<> random_balance(0.0, 1000.0);
  59.             //////////////////////////////////////////////////////////////////
  60.  
  61.             this->bankNumber = to_string(random_bank_number(gen));
  62.             this->bankName = bankNames[random_banks(gen)];
  63.             this->ownerName = names[random_names(gen)];
  64.             this->balance = random_balance(gen);
  65.         }
  66.         void print_info() {
  67.             cout << "Bank Number: " << this->bankNumber << endl;
  68.             cout << "Bank Name: " << this->bankName << endl;
  69.             cout << "Owner Name: " << this->ownerName << endl;
  70.             cout << "Balance: " << this->balance << endl;
  71.         }
  72. };
  73.  
  74. int main() {
  75.  
  76.     BankAccount acc;
  77.  
  78.     acc.generate();
  79.     acc.print_info();
  80.  
  81.     cout << endl;
  82.  
  83.     acc.withdraw(15);
  84.     acc.print_info();
  85.  
  86.     return 0;
  87. }
Add Comment
Please, Sign In to add comment