Advertisement
Guest User

Untitled

a guest
Jun 30th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Fraction
  5. {
  6. int chis;
  7. int znam;
  8. public:
  9. int GetChis() const
  10. {
  11. return chis;
  12. }
  13. int GetZnam() const
  14. {
  15. return znam;
  16. }
  17. void SetChis(int chis)
  18. {
  19. this->chis = chis;
  20. }
  21. void SetZnam(int znam)
  22. {
  23. this->znam = znam == 0 ? 1 : znam;
  24. }
  25.  
  26. Fraction operator + (/*Fraction* this, */ const Fraction& f2)
  27. {
  28. Fraction result;
  29. result.SetChis(this->GetChis() * f2.GetZnam() + f2.GetChis() * this->GetZnam());
  30. result.SetZnam(this->GetZnam() * f2.GetZnam());
  31. return result;
  32. }
  33. };
  34.  
  35.  
  36.  
  37. void main()
  38. {
  39. Fraction a;
  40. a.SetChis(1);
  41. a.SetZnam(2);
  42. Fraction b;
  43. b.SetChis(1);
  44. b.SetZnam(4);
  45. Fraction result = a + b;
  46. Fraction r = a.operator + (b);
  47. cout << result.GetChis() << " / " << result.GetZnam() << "\n";
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement