`Vector`

ClassAdding two vectors is very simple when you use x,y coordinates. You just add the two x components to get the x component of the answer and add the two y components to get the y component of the answer. From this description, you might be tempted to use this code:

Vector Vector::operator+(const Vector & b) const{ Vector sum; sum.x = x + b.x; sum.y = y + b.y; return sum; // incomplete version}

And this would be fine if the object stored only the x and y components. Unfortunately, this version of the code fails to set the polar values. You could fix this problem by adding more code:

Vector Vector::operator+(const Vector & b) const{ Vector sum; sum.x = x + b.x; sum.y ...

Start Free Trial

No credit card required