Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <exception>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- class Money {
- int nominal;
- int amount;
- public:
- void print()
- {
- out << "nominal : " << nominal << " amount : " << amount << endl;
- }
- bool isEnough(int x)
- {
- return nominal * amount >= x;
- }
- int countProductWithCost(int y)
- {
- return nominal * amount / y;
- }
- void setNominal(int nominal)
- {
- this->nominal = nominal;
- }
- void setAmount(int amount)
- {
- this->amount = amount;
- }
- long long overall()
- {
- return amount * 1LL * nominal;// 1LL - приведение к типу long long
- }
- //префексная форма ++a
- Money operator++()
- {
- this->amount++;
- return *this;
- }
- Money operator--()
- {
- this->amount--;
- return *this;
- }
- // постфиксная форма a++
- Money operator++(int)
- {
- Money b;
- b.setAmount(this->amount);
- b.setNominal(this->nominal);
- this->amount++;
- return b;
- }
- Money operator--(int)
- {
- Money b;
- b.setAmount(this->amount);
- b.setNominal(this->nominal);
- this->amount--;
- return b;
- }
- Money operator + (int k)
- {
- this->amount += k;
- return *this;
- }
- };
- void Print(Money a)
- {
- a.print();
- }
- int main()
- {
- int n = 5;
- //in >> n;
- Money *a = new Money[n];
- for (int i = 0; i < n; ++i)
- {
- a[i].setAmount (10 + 10 * i / 2 + 3);
- a[i].setNominal(10 + 10 * i);
- a[i].print();
- out << "overall: " << a[i].overall() << endl;
- out << "count Product With Cost 12 : " <<
- a[i].countProductWithCost(12) <<
- "\n================================\n";
- }
- out << "\nPostfix form of operator++\n variable A before A++:\n";
- Money A = a[0];
- out << "\t\t";
- A.print();
- Money B = A++;
- out << " variable B:\n\t\t";
- B.print();
- out << " variable A after A++:\n\t\t";
- A.print();
- out << "\nPrefix form of operator++\n variable A before ++A:\n";
- A = a[0];
- out << "\t\t";
- A.print();
- B = ++A;
- out << " variable B:\n\t\t";
- B.print();
- out << " variable A after ++A:\n\t\t";
- A.print();
- }
Add Comment
Please, Sign In to add comment