daily pastebin goal
70%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. class Money{
  4. public:
  5.     Money(); // default
  6.     Money(unsigned, unsigned); //конструктор с параметри
  7.     ~Money(); //деструктор
  8.     Money(const Money&); // copy-конструктор
  9.     Money& operator=(const Money&); //оператор за присвояване
  10.     //КРАЙ НА ГОЛЯМАТА 5ОРКА
  11.  
  12.     void setLevas(unsigned);
  13.     void setStots(unsigned);
  14.     unsigned getLevas() const; //Туй са аксесори(не променям нищо с тях), затова има const след тях
  15.     unsigned getStots() const;
  16.     //Край на гетъри/сетъри
  17.  
  18.     std::ostream& ins(std::ostream&) const; // a tuk sa 2 parametyra - implicitniya i ostream
  19.     //virtual std::ostream ins(std::ostream&) const;//tva e za po sledvashtite koga ima nasledyavane
  20.  
  21.     Money operator+(const Money&) const;
  22.     Money operator-(const Money&) const;
  23.     Money operator*(const Money&) const;
  24.     Money operator/(const Money&) const;
  25.  
  26.     bool operator<(const Money&) const;
  27.     bool operator>(const Money&) const;
  28.     bool operator==(const Money&) const;
  29.  
  30. private:
  31.     unsigned levas;
  32.     unsigned stotinkis;
  33. };
  34.  
  35. Money::Money(){
  36.     levas = 0;
  37.     stotinkis = 0;
  38. }
  39.  
  40. Money::Money(unsigned levas, unsigned stotinkis){ //Мога да пропусна this ako imenata тук и на долния ред са различни примерно uns leavass != levas
  41.     this->levas = levas;
  42.     this->stotinkis = stotinkis;
  43. }
  44.  
  45. Money::~Money(){}
  46.  
  47. Money::Money(const Money& obj){
  48.     levas = obj.levas;
  49.     stotinkis = obj.stotinkis;
  50. }
  51.  
  52. Money& Money::operator=(const Money& rhs){
  53.     if (this != &rhs){
  54.         levas = rhs.levas;
  55.         stotinkis = rhs.stotinkis;
  56.     }
  57.     return *this;
  58. }
  59.  
  60. void Money::setLevas(unsigned l){
  61.     levas = l;
  62. }
  63.  
  64. void Money::setStots(unsigned s){
  65.     stotinkis = s;
  66. }
  67.  
  68. unsigned Money::getLevas() const{
  69.     return levas;
  70. }
  71.  
  72. unsigned Money::getStots() const{
  73.     return stotinkis;
  74. }
  75.  
  76. std::ostream& Money::ins(std::ostream& lhs) const{
  77.     lhs << levas << "." << stotinkis;
  78.     return lhs;
  79. }
  80.  
  81. std::ostream& operator<<(std::ostream& lhs, const Money& rhs){
  82.     return rhs.ins(lhs);
  83. }
  84.  
  85. Money Money::operator+(const Money& rhs) const{
  86.     return Money(levas + rhs.levas, stotinkis + rhs.stotinkis);
  87. }
  88.  
  89. Money Money::operator-(const Money& rhs) const{
  90.     return Money(levas - rhs.levas, stotinkis - rhs.stotinkis);
  91. }
  92.  
  93. Money Money::operator*(const Money& rhs) const{
  94.     return Money(levas * rhs.levas, stotinkis * rhs.stotinkis);
  95. }
  96.  
  97. Money Money::operator/(const Money& rhs) const{
  98.     return Money(levas / rhs.levas, stotinkis / rhs.stotinkis);
  99. }
  100.  
  101. bool Money::operator>(const Money& rhs) const{
  102.     unsigned temp1 = levas*100 * stotinkis;
  103.     unsigned temp2 = rhs.levas*100 + rhs.stotinkis;
  104.     return temp1 > temp2;
  105. }
  106.  
  107. bool Money::operator<(const Money& rhs) const{
  108.     unsigned temp1 = levas*100 * stotinkis;
  109.     unsigned temp2 = rhs.levas*100 + rhs.stotinkis;
  110.     return temp1 < temp2;
  111. }
  112.  
  113. bool Money::operator==(const Money& rhs) const{
  114.     return Money(levas, stotinkis) == Money(rhs.levas, rhs.stotinkis);
  115. }
  116.  
  117.     std::ostream& operator<<(std::ostream&, const Money&); //tova e s 3 parametyra imam 1 impliciten koito ne go vijdam
  118.  
  119. int main(int argc, char **argv)
  120. {
  121.     Money m(5, 40);
  122.     Money n(3, 90);
  123.     std::cout << m + n << std::endl;
  124.     std::cout << n << std::endl;
  125.     std::cout << m << std::endl;
  126.     (m > n) ? std::cout << true : std::cout << false << std::endl;
  127. }
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