Adding source code to the Point module udr.c file
About this task
You must add code to implement the Distance() function, which you can see in Visual C++ under the Globals node in the Class view. This function implements the same functionality as the rciDistance() function and the Distance() function in previous exercises.
To implement the Distance() function:
Procedure
- Double-click Distance() in the Class view and scroll to the beginning of the udr.c file.
- Add the following statement to the #include statements
at the beginning of the udr.c file to include
the C math library:
#include <math.h> - Find the following comment directly after
Your_Code ... BEGIN, remove it and the mi_db_error_raise() statement that follows it:/* ** TO DO: Remove this comment and call to * * mi_db_error_raise after implementing ** this function. */ mi_db_error_raise( Gen_Con, MI_EXCEPTION, "Function Distance has not been implemented." ); - Find the comment
TO DO: Compute and store your value into Gen_RetVal. Add the following code after the comment:*Gen_RetVal = sqrt((Pnt1->x - Pnt2->x) * (Pnt1->x - Pnt2->x) + (Pnt1->y - Pnt2->y) * (Pnt1->y - Pnt2->y) ); - Check your source code against the final version of udr.c.
- Save the changes to udr.c.