Answer to Question #218027 in C++ for Shema

Question #218027

Use the operator overloading technique to define the binary operator+ in the Square class of Q1 then overload the insertion operator << for the same class, and overload the decrements operator-- which decrease the side by one . Use the new + operator to add two squares such that the side of resulted square equal to the addition of the sides of the added squares and use the decrements operator-- to decrease the side of square by one, then use the overloaded insertion operator << to print the resulted square in the main program. After that add a new integer pointer variable called color that point to an integer array of three elements to the class square then write the copy constructor for the new class.


1
Expert's answer
2021-07-17T01:30:24-0400
#include <iostream>

class Square {
public:
  int a, b;
  Square(int a, int b) {
    this->a = a;
    this->b = b;
  }
  void operator--() {
    if (this->a) this->a--;
    if (this->b) this->b--;
  }
  ostream & operator<<(ostream & out, const Point & point) {
    out << "[" << this->x << "," << this->y << "]";
    return out;
  }
};

Square operator+ (const Square &a, Square &b) {
  return Square(a->a+b->a, a->b+b->b);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS