Advertisement
DescendingBear

Wyjatki

Nov 24th, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Wyjatek
  5. {
  6.     public:
  7.     int mon;
  8.     Wyjatek(int n_mon)
  9.     {
  10.          mon=n_mon;
  11.          cout<<"Nie wykonujemy obliczen na dlugach. "<<endl;
  12.     }
  13. };
  14.  
  15. class Pieniadze{
  16.       public:
  17.              Pieniadze(int a=0) { mon = a; }
  18.  
  19.              Pieniadze operator+(Pieniadze a)
  20.              {
  21.                   mon += a.zwroc();
  22.                   if (mon<0)
  23.                     throw Wyjatek(a.mon);
  24.              }
  25.              Pieniadze operator-(Pieniadze a)
  26.              {
  27.                   mon -= a.zwroc();
  28.                   if (mon<0)
  29.                     throw Wyjatek(a.mon);
  30.              }
  31.              int zwroc() { return mon; }
  32.  
  33.              Pieniadze wypisz() { cout<<mon<<" groszy to "<<mon/100<<" zlotych i "<<mon%100<<" groszy."<<endl; }
  34.       private:
  35.             int mon;
  36. };
  37.  
  38. int main()
  39. {
  40.     Pieniadze kwota(1000);
  41.     kwota-30000;
  42.     try {kwota.wypisz();}
  43.         catch(Wyjatek negative) { cout<<negative.mon; }
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement