Creating the Library Project |
|
- Start Borland C++ Builder and, on the main menu, click File
-> New -> Other...
- In the New property page of the New Items dialog, click Library
- Click OK
- To save the project, on the Standard toolbar, click the Save All
button
- In the Save Project As dialog box, click the Create New Folder
button to create a new folder. Type BusMath and press Enter twice to
display the new folder in the Save combo box
- Replace the name of the project with BusinessMath and click Save
- To add a new unit, on the main menu, click File -> New -> Unit
- To save the new unit, on the Standard toolbar, click the Save All
button
- Replace the content of the Name edit box with bmcalc and click
Save
- In the header file, declare the following functions:
//---------------------------------------------------------------------------
#ifndef bmcalcH
#define bmcalcH
//---------------------------------------------------------------------------
double __fastcall Average(const double *Numbers, const int Count);
long __fastcall GreatestCommonDivisor(long Nbr1, long Nbr2);
//---------------------------------------------------------------------------
#endif
|
- In the source file, implement the functions as follows:
//---------------------------------------------------------------------------
#pragma hdrstop
#include "bmcalc.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
double __fastcall Average(const double *Nbr, const int Total)
{
double avg, S = 0;
for(int i = 0; i < Total; i++)
S += Nbr[i];
avg = S / Total;
return avg;
}
//---------------------------------------------------------------------------
long __fastcall GreatestCommonDivisor(long Nbr1, long Nbr2)
{
while( true )
{
Nbr1 = Nbr1 % Nbr2;
if( Nbr1 == 0 )
return Nbr2;
Nbr2 = Nbr2 % Nbr1;
if( Nbr2 == 0 )
return Nbr1;
}
}
//---------------------------------------------------------------------------
|
- To create the library, on the main menu, click Project -> Build
BusinessMath
- When the library has been built, click OK on the Compiling dialog
box
- Save All
|
|
|