Solution Review: Coordinates of a Point
Explore how to define and use structs and methods in Go by working with a 2D Point struct. Understand pointer receiver methods like Abs() and Scale(), and apply these techniques to manipulate point coordinates for practical programming challenges.
We'll cover the following...
We'll cover the following...
In the above code, look at line 7. We make a struct of type Point that is a 2D point. It has two fields X and Y, both of type float64.
Now, we need to write a method Abs(). See its header at line 11: func (p *Point)Abs() float64 . From its header, it’s clear that this method can be called only by a pointer to the object of type Point. In the next line, the ...