Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Pieniadze
- {
- public:
- int zlote;
- void SetZlote(int zlote)
- {
- this->zlote = zlote;
- }
- int GetZlote()
- {
- return this->zlote;
- }
- int grosze;
- void SetGrosze(int grosze)
- {
- this->grosze = grosze;
- }
- int GetGrosze()
- {
- return this->grosze;
- }
- Pieniadze(int my_grosze = 0, int my_zlote = 0)
- {
- if(my_grosze < 0 || my_zlote < 0)
- {
- string w = "Pieniadze nie moga byc ujemne!\n";
- throw w;
- }
- else
- {
- SetZlote(my_zlote + my_grosze / 100);
- SetGrosze(my_grosze % 100);
- }
- }
- Pieniadze operator +(int toAdd)
- {
- return Pieniadze(((grosze + toAdd) % 100), (zlote + (grosze + toAdd) / 100));
- }
- Pieniadze operator -(int toSubtract)
- {
- return Pieniadze(((grosze - toSubtract) % 100), (zlote - (grosze + toSubtract) / 100));
- }
- Pieniadze operator - (Pieniadze &p)
- {
- return Pieniadze(grosze - p.grosze, zlote - p.zlote);
- }
- Pieniadze operator *(int toMultiply)
- {
- return Pieniadze((grosze * toMultiply) % 100, zlote * toMultiply + (grosze * toMultiply) / 100);
- }
- Pieniadze operator /(int toDivide)
- {
- return Pieniadze((grosze / toDivide) % 100, zlote / toDivide + (grosze / toDivide) / 100);
- }
- Pieniadze operator +(Pieniadze &toAdd)
- {
- return Pieniadze((grosze + toAdd.grosze) % 100, zlote + toAdd.zlote + (grosze + toAdd.grosze) / 100);
- }
- friend ostream & operator<< (ostream &wyjscie, const Pieniadze &s);
- operator int()
- {
- return zlote;
- }
- void Ustaw(int grosze = 0, int zlote = 0)
- {
- SetZlote(zlote + grosze / 100);
- SetGrosze(grosze % 100);
- }
- void Wypisz()
- {
- float kwota = zlote + int(grosze / 100) + (grosze % 100) / 100;
- cout << kwota;
- }
- };
- ostream & operator<< (ostream &wyjscie, const Pieniadze &p)
- {
- return wyjscie << p.zlote << " zl " << p.grosze << "gr" << endl;
- }
- int main()
- {
- Pieniadze a = Pieniadze(100);
- Pieniadze b(200);
- try
- {
- cout << a - b;
- }
- catch(string e)
- {
- cout << "Pojawil sie wyjatek! " << e << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement