Adding source code to the Point DataBlade 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

  1. Double-click Distance() in the Class view and scroll to the beginning of the udr.c file.
  2. 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>
  3. 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." );
  4. 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) ); 
  5. Check your source code against the final version of udr.c.
  6. Save the changes to udr.c.