Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Account {
  6.     string nickname;
  7.     static int bonus;
  8.     int money = 0;
  9.    
  10. public:
  11.     Account(string nickname, int money) {
  12.         this->nickname = nickname;
  13.         this->money = money + bonus;
  14.     }
  15.  
  16.     static void setBonus(int _bonus) {
  17.         bonus = _bonus;
  18.     }
  19.  
  20.     static int getBonus() {
  21.         return bonus;
  22.     }
  23.    
  24.     int getMoney() {
  25.         return money;
  26.     }
  27.  
  28. };
  29.  
  30. int Account::bonus = 10;
  31. int main() {
  32.  
  33.    
  34.     Account n1("papa1", 30);
  35.     Account n2("papa2", 100);
  36.     Account n3("papa3", 75);
  37.  
  38.     cout << n1.getMoney() << endl;
  39.     cout<< n2.getMoney() << endl;
  40.     cout << n3.getMoney() << endl;
  41.  
  42.     system("pause");
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement