Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Point {
- private:
- int x, y;
- public:
- Point() {}
- Point(int x, int y) {
- this->x = x;
- this->y = y;
- }
- Point(const Point &tmp) {
- this->x = tmp.x;
- this->y = tmp.y;
- }
- ~Point() {}
- Point operator + (Point p) {
- return Point(x + p.x, y + p.y);
- }
- Point operator - (Point p) {
- return Point(x - p.x, y - p.y);
- }
- Point operator * (Point p) {
- return Point(x * p.x, y * p.y);
- }
- Point operator / (Point p) {
- return Point(x / p.x, y / p.y);
- }
- Point & operator += (Point p) {
- x += p.x;
- y += p.y;
- return *this;
- }
- Point & operator -= (Point p) {
- x -= p.x;
- y -= p.y;
- return *this;
- }
- Point & operator *= (Point p) {
- x *= p.x;
- y *= p.y;
- return *this;
- }
- Point & operator /= (Point p) {
- x /= p.x;
- y /= p.y;
- return *this;
- }
- bool operator < (Point p) {
- if(x < p.x and y < p.y) {
- return true;
- }
- return false;
- }
- bool operator > (Point p) {
- if(x > p.x and y > p.y) {
- return true;
- }
- return false;
- }
- void print() {
- cout << x << " " << y << endl;
- }
- friend ostream & operator << (ostream & stream, Point & p);
- friend istream & operator >> (istream & stream, Point & p);
- };
- ostream & operator << (ostream & stream, Point & p) {
- stream << "X: " << p.x << endl;
- stream << "Y: " << p.y << endl;
- return stream;
- }
- istream & operator >> (istream & stream, Point & p) {
- stream >> p.x >> p.y;
- return stream;
- }
- int main() {
- Point A;
- Point B;
- cin >> A >> B;
- Point C = A + B;
- Point C2 = A - B;
- Point C3 = A * B;
- Point C4 = A / B;
- C.print();
- C2.print();
- C3.print();
- C4.print();
- Point D(4, 5);
- D += A;
- D.print();
- D -= B;
- D.print();
- D *= A;
- D.print();
- D /= B;
- D.print();
- if(A < B) {
- cout << "A e pomalo od B" << endl;
- }
- cout << A << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment