im required to write a function to overload the ==operator to compare width, height and colour. i need to return 'Y' if its equal and 'N' if its not.
this is my code which i think its correct but keeps getting the error in the title.
i've done searches and nothing came close to comparing 3 data as most examples are for comparing 2 datas.
#include <iostream>
#include <string>
using namespace std;
class Rectangle
{
private:
float width;
float height;
char colour;
public:
Rectangle()
{
width=2;
height=1;
colour='Y';
}
~Rectangle(){}
float getWidth() { return width; }
float getHeight() { return height; }
char getColour() { return colour; }
Rectangle(float newWidth, float newHeight, char newColour)
{
width = newWidth;
height = newHeight;
colour = newColour;
}
char operator== (const Rectangle& p1){
if ((width==p1.width) && (height==p1.height) && (colour==p1.colour))
return 'Y';
else
return 'N';
}
};
int main(int argc, char* argv[])
{
Rectangle rectA;
Rectangle rectB(1,2,'R');
Rectangle rectC(3,4,'B');
cout << "width and height of rectangle A is := " << rectA.getWidth() << ", " << rectA.getHeight() << endl;
cout << "Are B and C equal? Ans: " << rectB==rectC << endl;
return 0;
}