IFD:EAI SoS21/course material/Session 3: File Structuring, Pointers and Addresses: Difference between revisions

From Medien Wiki
Line 11: Line 11:
To get the x- and y-coordinates in our code, we can use the private variables for point p1 (_x and _y) and the member functions getX() and getY() for point p2. So the most crucial lines of code are:  
To get the x- and y-coordinates in our code, we can use the private variables for point p1 (_x and _y) and the member functions getX() and getY() for point p2. So the most crucial lines of code are:  
<source lang="c++" line start="1" highlight="4">float Point2D::calculateDistanceToOtherPoint(Point2D p2){
<source lang="c++" line start="1" highlight="4">float Point2D::calculateDistanceToOtherPoint(Point2D p2){
     float distance = sqrt( (p2.getX() -_x)*( p2.getX() -_x)+( p2.getY()-_y)*( p2.getY() -_y) );  
     float distance = sqrt( (p2.getX() -_x)*( p2.getX() -_x)+( p2.getY()-_y)*( p2.getY() -_y) );  
     return distance;
     return distance;