Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- 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 operator +(int toAdd)
- {
- Pieniadze res;
- res.grosze = (grosze + toAdd) % 100;
- res.zlote = zlote + (grosze + toAdd) / 100;
- return res;
- }
- Pieniadze operator -(int toSubtract)
- {
- Pieniadze res;
- int kwotaWGr = zlote * 100 + grosze;
- if(kwotaWGr >= toSubtract)
- {
- int reszta = toSubtract - grosze;
- if (reszta > 0)
- {
- res.zlote = zlote - reszta / 100;
- res.grosze = reszta % 100;
- }else
- {
- res.zlote = zlote;
- res.grosze = grosze - toSubtract;
- }
- }
- return res;
- }
- Pieniadze operator *(int toMultiply)
- {
- Pieniadze res;
- res.grosze = (grosze * toMultiply) % 100;
- res.zlote = zlote * toMultiply + (grosze * toMultiply) / 100;
- return res;
- }
- Pieniadze operator /(int toDivide)
- {
- Pieniadze res;
- res.grosze = (grosze / toDivide) % 100;
- res.zlote = zlote / toDivide + (grosze / toDivide) / 100;
- return res;
- }
- Pieniadze operator +(Pieniadze &toAdd)
- {
- Pieniadze res;
- res.grosze = (grosze + toAdd.grosze) % 100;
- res.zlote = zlote + toAdd.zlote + (grosze + toAdd.grosze) / 100;
- return res;
- }
- friend ostream & operator<< (ostream &wyjscie, const Pieniadze &s);
- operator int()
- {
- return zlote;
- }
- Pieniadze(int grosze = 0, int zlote = 0)
- {
- SetZlote(zlote + grosze / 100);
- SetGrosze(grosze % 100);
- }
- 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;
- printf("%f\n", kwota);
- }
- };
- ostream & operator<< (ostream &wyjscie, const Pieniadze &p)
- {
- return wyjscie << p.zlote << " zl " << p.grosze << "gr";
- }
- int main()
- {
- Pieniadze tysiac(1000);
- tysiac.Wypisz();
- cout << endl;
- Pieniadze kwota;
- kwota.Ustaw(700);
- Pieniadze suma1 = tysiac + kwota;
- Pieniadze suma2 = tysiac + 20;
- Pieniadze suma3 = 20 + tysiac;
- cout << suma1 << endl;
- cout << suma2 << endl;
- cout << suma3 << endl << endl;
- int liczba1 = int(suma1);
- int liczba2 = (int)suma2;
- int liczba3 = suma3;
- cout << liczba1 << endl;
- cout << liczba2 << endl;
- cout << liczba3 << endl << endl;
- cout << "Tysiac groszy to: " << tysiac << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement