SHARE
TWEET

Untitled

Yanislav29 Mar 26th, 2020 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Money.h"
  2. #include <iostream>
  3. Money::Money() : leva(0), stotinki(0)
  4. {
  5. }
  6. Money::Money(int lv, int st)
  7. {
  8.     leva = lv;
  9.     stotinki = st;
  10.  
  11. }
  12. double Money::makeMoney(int lv, int st)
  13. {
  14.  
  15.     double sum = lv + ((double)st / 100);
  16.     return sum;
  17. }
  18. Money::~Money()
  19. {
  20. }
  21. Money::Money(const Money & rhs)
  22. {
  23.     leva = rhs.leva;
  24.     stotinki = rhs.stotinki;
  25. }
  26. Money & Money::operator=(const Money & rhs)
  27. {
  28.     leva = rhs.leva;
  29.     stotinki = rhs.stotinki;
  30.     return *this;
  31. }
  32.  
  33. bool Money::operator<(const Money & rhs)
  34. {
  35.     double sum = leva + ((double)stotinki / 100);
  36.     double rhsSum = rhs.leva + ((double)rhs.stotinki / 100);
  37.     return sum < rhsSum;
  38. }
  39.  
  40. bool Money::operator>(const Money & rhs)
  41. {
  42.     double sum = leva + ((double)stotinki / 100);
  43.     double rhsSum = rhs.leva + ((double)rhs.stotinki / 100);
  44.     return sum > rhsSum;
  45. }
  46.  
  47. Money Money::operator+(const Money & rhs)
  48. {
  49.     int sum = 100 * leva + stotinki;
  50.     int rhsSum = 100 * rhs.leva + rhs.stotinki;
  51.     int totalLv = (sum + rhsSum) / 100;
  52.     int totalSt = (sum + rhsSum) % 100;
  53.  
  54.     Money res(totalLv, totalSt);
  55.  
  56.     return res;
  57. }
  58.  
  59. Money Money::operator-(const Money & rhs)
  60. {
  61.     int sum = 100 * leva + stotinki;
  62.     int rhsSum = 100 * rhs.leva - rhs.stotinki;
  63.     int totalLv = (sum - rhsSum) / 100;
  64.     int totalSt = (sum - rhsSum) % 100;
  65.  
  66.     Money res(totalLv, totalSt);
  67.  
  68.     return res;
  69. }
  70. int Money::getLeva() const
  71. {
  72.     return leva;
  73. }
  74.  
  75. int Money::getStotinki() const
  76. {
  77.     return stotinki;
  78. }
  79.  
  80. void Money::setLeva(int leva)
  81. {
  82.     this->leva = (leva > 0) ? leva : 0;
  83. }
  84.  
  85. void Money::setStotinki(int stotinki)
  86. {
  87.     this->stotinki = (stotinki > 0) ? stotinki : 0;
  88. }
  89.  
  90. int Money::print() const
  91. {
  92.     std::cout << leva << '.' << stotinki << std::endl;
  93.  
  94.     return 0;
  95. }
  96.  
  97. std::ostream & operator<<(std::ostream & out, const Money& rhs)
  98. {
  99.     out << rhs.getLeva() << " lv and " << rhs.getStotinki() << " st" << std::endl;
  100.     return out;
  101. }
  102.  
  103. std::istream & operator>>(std::istream & in, Money & rhs)
  104. {
  105.     int lv, st;
  106.     in >> lv;
  107.     in >> st;
  108.     rhs.setLeva(lv);
  109.     rhs.setStotinki(st);
  110. }
  111.  
  112. Money operator%(const double percent, const Money & rhs)
  113. {
  114.     int sum = 100 * rhs.leva + rhs.stotinki;
  115.     int percentRhs = (sum * percent) / 100;
  116.     int newLv = percentRhs / 100;
  117.     int newSt = percentRhs % 100;
  118.     Money res(newLv, newSt);
  119.     return res;
  120. }
  121.  
  122. Money operator*(const double num, const Money & rhs)
  123. {
  124.     int sum = 100 * rhs.getLeva() + rhs.getStotinki();
  125.     int prodLv = num * (sum / 100);
  126.     int prodSt = num * (sum % 100);
  127.  
  128.     Money res(prodLv, prodSt);
  129.     return res;
  130.  
  131. }
  132.  
  133. Money operator/(const double num, const Money & rhs)
  134. {
  135.     int sum = 100 * rhs.getLeva() + rhs.getStotinki();
  136.     int prodLv = (sum / 100) / num;
  137.     int prodSt = (sum % 100) / num;
  138.  
  139.     Money res(prodLv, prodSt);
  140.     return res;
  141. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top