Advertisement
Guest User

Hajs

a guest
Nov 22nd, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.47 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Pieniadze
  6. {
  7.     public:
  8.    
  9.         int zlote;
  10.         void SetZlote(int zlote)
  11.         {
  12.             this->zlote = zlote;
  13.         }
  14.         int GetZlote()
  15.         {
  16.             return this->zlote;
  17.         }
  18.    
  19.         int grosze;
  20.         void SetGrosze(int grosze)
  21.         {
  22.             this->grosze = grosze;
  23.         }
  24.         int GetGrosze()
  25.         {
  26.             return this->grosze;
  27.         }
  28.    
  29.    
  30.    
  31.         Pieniadze operator +(int toAdd)
  32.         {
  33.             Pieniadze res;
  34.             res.grosze = (grosze + toAdd) % 100;
  35.             res.zlote = zlote + (grosze + toAdd) / 100;
  36.             return res;
  37.         }
  38.        
  39.         Pieniadze operator -(int toSubtract)
  40.         {
  41.             Pieniadze res;
  42.             int kwotaWGr = zlote * 100 + grosze;
  43.             if(kwotaWGr >= toSubtract)
  44.             {
  45.                 int reszta = toSubtract - grosze;
  46.                 if (reszta > 0)
  47.                 {
  48.                     res.zlote = zlote - reszta / 100;
  49.                     res.grosze = reszta % 100;
  50.                 }else
  51.                 {
  52.                     res.zlote = zlote;
  53.                     res.grosze = grosze - toSubtract;
  54.                 }
  55.             }
  56.             return res;
  57.         }
  58.        
  59.         Pieniadze operator *(int toMultiply)
  60.         {
  61.             Pieniadze res;
  62.             res.grosze = (grosze * toMultiply) % 100;
  63.             res.zlote = zlote * toMultiply + (grosze * toMultiply) / 100;
  64.             return res;
  65.         }
  66.        
  67.         Pieniadze operator /(int toDivide)
  68.         {
  69.             Pieniadze res;
  70.             res.grosze = (grosze / toDivide) % 100;
  71.             res.zlote = zlote / toDivide + (grosze / toDivide) / 100;
  72.             return res;
  73.         }
  74.        
  75.         Pieniadze operator +(Pieniadze &toAdd)
  76.         {
  77.             Pieniadze res;
  78.             res.grosze = (grosze + toAdd.grosze) % 100;
  79.             res.zlote = zlote + toAdd.zlote + (grosze + toAdd.grosze) / 100;
  80.             return res;
  81.         }
  82.        
  83.        
  84.        
  85.         friend ostream & operator<< (ostream &wyjscie, const Pieniadze &s);
  86.        
  87.         operator int()
  88.         {
  89.             return zlote;
  90.         }
  91.        
  92.         Pieniadze(int grosze = 0, int zlote = 0)
  93.         {
  94.             SetZlote(zlote + grosze / 100);
  95.             SetGrosze(grosze % 100);
  96.         }
  97.        
  98.         void Ustaw(int grosze = 0, int zlote = 0)
  99.         {
  100.             SetZlote(zlote + grosze / 100);
  101.             SetGrosze(grosze % 100);
  102.         }
  103.        
  104.         void Wypisz()
  105.         {
  106.             float kwota = zlote + int(grosze / 100) + (grosze % 100) / 100;
  107.             printf("%f\n", kwota);
  108.         }
  109. };
  110.  
  111. ostream & operator<< (ostream &wyjscie, const Pieniadze &p)
  112. {
  113.    return wyjscie << p.zlote << " zl " << p.grosze << "gr";
  114.  }
  115.  
  116. int main()
  117. {
  118.     Pieniadze tysiac(1000);
  119.     tysiac.Wypisz();
  120.    
  121.     cout << endl;
  122.    
  123.     Pieniadze kwota;
  124.     kwota.Ustaw(700);
  125.    
  126.     Pieniadze suma1 = tysiac + kwota;
  127.     Pieniadze suma2 = tysiac + 20;
  128.     Pieniadze suma3 = 20 + tysiac;
  129.    
  130.     cout << suma1 << endl;
  131.     cout << suma2 << endl;
  132.     cout << suma3 << endl << endl;
  133.    
  134.     int liczba1 = int(suma1);
  135.     int liczba2 = (int)suma2;
  136.     int liczba3 = suma3;
  137.    
  138.     cout << liczba1 << endl;
  139.     cout << liczba2 << endl;
  140.     cout << liczba3 << endl << endl;
  141.    
  142.     cout << "Tysiac groszy to: " << tysiac << endl;
  143.    
  144.     return 0;
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement