Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Rectangle
- {
- public:
- Rectangle(): xa(0), ya(0), xb(0), yb(0){}
- Rectangle(int _xa, int _ya, int _xb, int _yb): xa(_xa), ya(_ya), xb(_xb), yb(_yb) {}
- friend istream& operator >> (istream& in, Rectangle& r)
- {
- in >> r.xa >> r.ya >> r.xb >> r.yb;
- return in;
- }
- friend ostream& operator << (ostream& out, Rectangle const& r)
- {
- out << r.xa << " " << r.ya << " " << r.xb << " " << r.yb;
- return out;
- }
- Rectangle operator + (const Rectangle &r) const;
- Rectangle operator - (const Rectangle &r) const;
- Rectangle operator * (const Rectangle &r) const;
- friend Rectangle operator + (const Rectangle &r, int a);
- friend Rectangle operator - (const Rectangle &r, int a);
- friend Rectangle operator * (const Rectangle &r, int a);
- friend Rectangle operator * (int a, const Rectangle &r);
- friend Rectangle operator / (const Rectangle& r, int a);
- private:
- int xa, ya, xb, yb;
- };
- Rectangle Rectangle::operator + (const Rectangle &r) const
- {
- Rectangle r1(*this);
- r1.xa += r.xa;
- r1.ya += r.ya;
- r1.xb += r.xb;
- r1.yb += r.yb;
- return r1;
- }
- Rectangle Rectangle::operator - (const Rectangle &r) const
- {
- Rectangle r1(*this);
- r1.xa -= r.xa;
- r1.ya -= r.ya;
- r1.xb -= r.xb;
- r1.yb -= r.yb;
- return r1;
- }
- Rectangle Rectangle::operator * (const Rectangle &r) const
- {
- Rectangle r1(*this);
- r1.xa *= r.xa;
- r1.ya *= r.ya;
- r1.xb *= r.xb;
- r1.yb *= r.yb;
- return r1;
- }
- Rectangle operator + (const Rectangle &r, int a)
- {
- return Rectangle(r.xa + a, r.ya + a, r.xb + a, r.yb + a);
- }
- Rectangle operator - (const Rectangle &r, int a)
- {
- return Rectangle(r.xa - a, r.ya - a, r.xb - a, r.yb - a);
- }
- Rectangle operator * (const Rectangle &r, int a)
- {
- return Rectangle(a*r.xa, a*r.ya, a*r.xb, a*r.yb);
- }
- Rectangle operator * (int a, const Rectangle &r)
- {
- return Rectangle(a*r.xa, a*r.ya, a*r.xb, a*r.yb);
- }
- Rectangle operator / (const Rectangle& r, int a)
- {
- return Rectangle(r.xa/a, r.ya/a, r.xb/a, r.yb/a);
- }
- int main()
- {
- Rectangle a, b, c;
- cout << "Enter coordinates: ";
- cin >> a;
- cin >> b;
- c = a + b;
- cout << c << endl;
- c = a - b;
- cout << c << endl;
- c = a * b;
- cout << c << endl;
- c = a + 3;
- cout << c << endl;
- c = a - 3;
- cout << c << endl;
- c = a * 3;
- cout << c << endl;
- c = a / 2;
- cout << c << endl;
- system ("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement