Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Drob
- {
- public:
- int ch, zn;
- Drob(int ch, int zn)
- {
- // constructor
- this->ch = ch;
- this->zn = zn;
- }
- ~Drob()
- {
- // destructor
- }
- const Drob operator+(const Drob &v) const;
- const Drob& operator+=(const Drob &v);
- bool operator==(const Drob &v);
- friend istream& operator>>(istream& stream, Drob &v);
- friend ostream& operator<<(ostream& stream, Drob &v);
- };
- const Drob Drob::operator+(const Drob &v) const
- {
- Drob Sum;
- Sum.ch = this->ch + v.ch;
- Sum.zn = this->zn + v.zn;
- return Sum;
- }
- const Drob& Drob::operator+=(const Drob &v)
- {
- ch += v.ch;
- zn += v.zn;
- return *this;
- }
- bool Drob::operator==(const Drob &v)
- {
- if(this->ch == v.ch && this->zn == v.zn)
- return true;
- return false;
- }
- istream& operator>>(istream& stream, Drob &v)
- {
- stream >> v.ch >> v.zn;
- return stream;
- }
- ostream& operator<<(ostream& stream, Drob &v)
- {
- stream << "ch = " << v.ch << ", zn = " << v.zn;
- return stream;
- }
- void main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- Drob d1, d2;
- cin >> d1 >> d2;
- cout << d1 << endl << d2;
- d1 += d2;
- cout << d1 << endl << d2;
- cout << "\n\n";
- system("pause");
- }
Add Comment
Please, Sign In to add comment