- Start Microsoft Visual Studio if necessary and display the New Project dialog box
- In the Project Types list, make sure you select the Visual C++ Projects node. In the Templates list, click Win32 Project. In the Name edit box, replace the content with BusMath

- Click OK
- In the Win32 Application Wizard, click Application Settings. In the Application Type section, click Static Library

- Click Finish
- To add a header file, on the main menu, click Project -> Add New Item… In the Add New Item – BusMath dialog box, in the Templates list, click Header File (.h). Replace the content of the Name edit box with bmcalc and click Open
- In the empty file, declare the following functions:
#ifndef _BUSINESSMATH_H_
#define _BUSINESSMATH_H_
double Min(const double *Numbers, const int Count);
double Max(const double *Numbers, const int Count);
double Sum(const double *Numbers, const int Count);
double Average(const double *Numbers, const int Count);
long GreatestCommonDivisor(long Nbr1, long Nbr2);
#endif // _BUSINESSMATH_H_
|
- To add a source file, on the main menu, click Project -> Add New Item… In the Templates list of the Add New Item – BusMath dialog box, click Source File
(.cpp). Replace the content of the Name edit box with bmcalc and click Open
- Implement the functions as follows:
#include "StdAfx.h"
#include "bmcalc.h"
double Min(const double *Nbr, const int Total)
{
double Minimum = Nbr[0];
for(int i = 0; i < Total; i++)
if( Minimum > Nbr[i] )
Minimum = Nbr[i];
return Minimum;
}
double Max(const double *Nbr, const int Total)
{
double Maximum = Nbr[0];
for(int i = 0; i < Total; i++)
if( Maximum < Nbr[i] )
Maximum = Nbr[i];
return Maximum;
}
double Sum(const double *Nbr, const int Total)
{
double S = 0;
for(int i = 0; i < Total; i++)
S += Nbr[i];
return S;
}
double 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 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 Build -> Build BusMath
|