Guest User

Untitled

a guest
May 31st, 2015
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class IntMod
  6. {
  7. private:
  8.  
  9. int num;
  10. int mod;
  11.  
  12. public:
  13.  
  14. IntMod(int num = 0, int mod = 1) : num(num % mod), mod(mod) {}
  15. IntMod operator+(const IntMod& other);
  16. void get();
  17. };
  18.  
  19. void IntMod::get()
  20. {
  21. cout << this->num << endl;
  22. }
  23.  
  24. IntMod IntMod::operator+(const IntMod& other)
  25. {
  26. if (this->mod == other.mod)
  27. return IntMod((this->num + other.num) % this->mod, this->mod);
  28. }
  29.  
  30. int main()
  31. {
  32. IntMod a, b(13,21), c(10,21),d(5,21);
  33. a = (b + c);
  34. a.get();
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment