Infiniti_Inter

Money(Alisa)

Dec 15th, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <exception>
  5. using namespace std;
  6.  
  7.  
  8. ifstream in("input.txt");
  9. ofstream out("output.txt");
  10.  
  11. class Money {
  12.     int nominal;
  13.     int amount;
  14.  
  15. public:
  16.     void print()
  17.     {
  18.         out << "nominal : " << nominal << " amount : " << amount << endl;
  19.     }
  20.  
  21.     bool isEnough(int x)
  22.     {
  23.         return nominal * amount >= x;
  24.     }
  25.     int countProductWithCost(int y)
  26.     {
  27.         return nominal * amount / y;
  28.     }
  29.  
  30.     void setNominal(int nominal)
  31.     {
  32.         this->nominal = nominal;
  33.     }
  34.     void setAmount(int amount)
  35.     {
  36.         this->amount = amount;
  37.     }
  38.  
  39.     long long overall()
  40.     {
  41.         return amount * 1LL * nominal;// 1LL - приведение к типу long long
  42.     }
  43.  
  44.  
  45.     //префексная форма ++a
  46.     Money operator++()
  47.     {
  48.         this->amount++;
  49.         return *this;
  50.  
  51.     }
  52.     Money operator--()
  53.     {
  54.         this->amount--;
  55.         return *this;
  56.  
  57.     }
  58.     // постфиксная форма a++
  59.     Money operator++(int)
  60.     {
  61.         Money b;
  62.         b.setAmount(this->amount);
  63.         b.setNominal(this->nominal);
  64.         this->amount++;
  65.         return b;
  66.     }
  67.     Money operator--(int)
  68.     {
  69.         Money b;
  70.         b.setAmount(this->amount);
  71.         b.setNominal(this->nominal);
  72.         this->amount--;
  73.         return b;
  74.  
  75.     }
  76.     Money operator + (int k)
  77.     {
  78.         this->amount += k;
  79.         return *this;
  80.     }
  81.  
  82.  
  83. };
  84.  
  85. void Print(Money a)
  86. {
  87.     a.print();
  88. }
  89.  
  90. int main()
  91. {
  92.  
  93.   int n = 5;
  94.   //in >> n;
  95.     Money *a = new Money[n];
  96.     for (int i = 0; i < n; ++i)
  97.   {
  98.     a[i].setAmount (10 + 10 * i / 2 + 3);
  99.     a[i].setNominal(10 + 10 * i);
  100.     a[i].print();
  101.     out << "overall: " << a[i].overall() << endl;  
  102.     out << "count Product With Cost 12 : " <<
  103.         a[i].countProductWithCost(12) <<
  104.         "\n================================\n";
  105.   }
  106.  
  107.  
  108.   out << "\nPostfix form of operator++\n   variable A before A++:\n";
  109.   Money A = a[0];
  110.   out << "\t\t";
  111.   A.print();
  112.   Money B = A++;
  113.   out << "   variable B:\n\t\t";
  114.   B.print();
  115.   out << "   variable A after A++:\n\t\t";
  116.   A.print();
  117.  
  118.  
  119.    
  120.   out << "\nPrefix form of operator++\n   variable A before ++A:\n";
  121.   A = a[0];
  122.   out << "\t\t";
  123.   A.print();
  124.   B = ++A;
  125.   out << "   variable B:\n\t\t";
  126.   B.print();
  127.   out << "   variable A after ++A:\n\t\t";
  128.   A.print();
  129.  
  130.    
  131.  
  132.  
  133.  
  134. }
Add Comment
Please, Sign In to add comment