Hello all - fairly new to C++ - my second college class on it and I am usually great about being able to google-foo my way thru things I get stuck on but this has me stumped.
Basically we have some already completed code. We have to write the class definition and implementation - so it boils down to creating some methods for get/set for some x/y cordinates - I have wrote the SetX() SetY() and Set() as well as a GetX() GetY() and Get()methods - The SetX and SetY methods work fine - The GetX and GetY methods do as well.
I'm not so sure about the Set() or Get() methods... I believe the Set() method is working but the Get() method isnt -
Set call: (Pre-code can't be changed)
P4.Set(13.5, 16.2);
Set Definition:
void Set(double point1, double point2);
Set Method:
1 2 3 4
|
void Point::Set(double point1, double point2)
{ x = point1;
y = point2;
} //Set()
|
Here's where I am lost - the homework says Get() must be declared const - it also says that to obtain the coordinates of a point, we must use reference parameters for the Get() method.
This is where I have become stumped I am just not that good with reference, pointers, and const. I have wrote and rewrote the Get() method many times without success - everything works up until I call the Get() method - the returning result is always the last value that I set for x/y using the SetX() and SetY() command.
Get call: (Pre-code can't be changed)
P4.Get(x,y);
Get Definition:
double Get(double &point1, double &point2)const;
Get Method:
1 2 3 4 5
|
double Point::Get(double &point1, double &point2) const
{ const double &x = point1;
const double &y = point2;
return x,y;
}
|
My Get() function is probably totally screwed up right now - I have spent probably 3 to 4+ hours coding, recoding, googling, and now it's some montrosity that I dont even recognize or understand and I am lost as to how to fix it. I've get the general idea of reference and pointers but I clearly dont understand the correct usage when it comes to passing them between methods back to main. If anyone can look at this and help me understand this I would be greatful - even a corrected get method that works so I at least have a working example to draw from would be super.
I read somewhere that a method can't return more than one value - so is that why you have to use references? By me trying to return x,y is that even working? Needless to say I am a bit confused...