Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Wyjatek
- {
- public:
- int mon;
- Wyjatek(int n_mon)
- {
- mon=n_mon;
- cout<<"Nie wykonujemy obliczen na dlugach. "<<endl;
- }
- };
- class Pieniadze{
- public:
- Pieniadze(int a=0) { mon = a; }
- Pieniadze operator+(Pieniadze a)
- {
- mon += a.zwroc();
- if (mon<0)
- throw Wyjatek(a.mon);
- }
- Pieniadze operator-(Pieniadze a)
- {
- mon -= a.zwroc();
- if (mon<0)
- throw Wyjatek(a.mon);
- }
- int zwroc() { return mon; }
- Pieniadze wypisz() { cout<<mon<<" groszy to "<<mon/100<<" zlotych i "<<mon%100<<" groszy."<<endl; }
- private:
- int mon;
- };
- int main()
- {
- Pieniadze kwota(1000);
- kwota-30000;
- try {kwota.wypisz();}
- catch(Wyjatek negative) { cout<<negative.mon; }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement