Advertisement
irmantas_radavicius

Untitled

Apr 23rd, 2024
747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <vector>
  5. #include <cmath>
  6. #include <cctype>
  7.  
  8. using namespace std;
  9.  
  10.  
  11.  
  12. class Account {
  13.     private:
  14.         double money;
  15.         static int accessCount;
  16.  
  17.     public:
  18.         Account(){
  19.             //accessCount = 0;
  20.             this->money = 0;
  21.         }
  22.         Account(double money){
  23.             if(money > 0){
  24.                 ++accessCount;
  25.                 this->money = money;
  26.             } else {
  27.                 this->money = 0;
  28.             }
  29.         }
  30.  
  31.         double in(double money){
  32.             if (money > 0)
  33.                 accessCount++;
  34.             //cout << money << " " << this->money << " " << ::money << endl;
  35.             this->money += money;
  36.             return this->money;
  37.         }
  38.  
  39.         double out(double money){
  40.             double t = min(money, this->money);
  41.             this->money -= t;
  42.             if(t > 0){
  43.                 accessCount++;
  44.             }
  45.             return t;
  46.         }
  47.  
  48.         double get(){
  49.             return money;
  50.         }
  51.  
  52.         static int getAccessCount(){
  53.             return accessCount;
  54.         }
  55.  
  56.         void print(){
  57.             cout << "Account: " << money << " EUR " << endl;
  58.         }
  59. };
  60. int Account::accessCount = 0;
  61.  
  62.  
  63.  
  64. int main(){
  65.  
  66.     Account account1(0);
  67.     account1.print();
  68.     double a1 = account1.in(100);
  69.     cout << "Total " << a1 << endl;
  70.     account1.print();
  71.     double b1 = account1.out(0);
  72.     cout << "Took out " << b1 << endl;
  73.     account1.print();
  74.     cout << "Total " << account1.get() << endl;
  75.     cout << "Total transactions " << Account::getAccessCount() << endl;
  76.  
  77.     cout << endl << endl;
  78.  
  79.     Account account2(0);
  80.     account2.print();
  81.     double a2 = account2.in(100);
  82.     cout << "Total " << a2 << endl;
  83.     account2.print();
  84.     double b2 = account2.out(0);
  85.     cout << "Took out " << b2 << endl;
  86.     account2.print();
  87.     cout << "Total " << account2.get() << endl;
  88.     cout << "Total transactions " << Account::getAccessCount() << endl;
  89.  
  90.     return 0;
  91. }
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement