I have 2 files: a .h file and a .cpp file. I am new to c++ but need to know how to execute these files. In other words, how do I write a 'main' so I can actually get an output to these 2 files. I am using Microsoft Visual studio 6.0.
//-------------------------------------------------------------------------
#ifndef ErfnH
#define ErfH
//-------------------------------------------------------------------------
class Erfn
{
public:
class ErfnRange{};
double *ErfnTable;
double operator()(double x);
Erfn(void);
~Erfn(void);
};
extern Erfn erfn;
#endif
//Erfn.cpp
//-------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <math.h>
#include "Erfn.h"
//-------------------------------------------------------------------------
#pragma package(smart_init)
#define ERFNTABLESIZE 2501
#define pi 3.1415926536
Erfn erfn;
double MaxX;
Erfn::Erfn(void)
{
MaxX=200.0;
ErfnTable=new double[ERFNTABLESIZE];
double rootpi=sqrt(pi);
int i;
double t,dt;
for(i=0;i<ERFNTABLESIZE;i++)
{
double val=0;
int j;
dt=1.0/(double)(ERFNTABLESIZE-1)*MaxX;
t=0.5/(double)(ERFNTABLESIZE-1)*MaxX;
for(j=0;j<i;j++)
{
val+=2.0/rootpi*exp(-t*t)*dt;
t+=dt;
}
if(val>1)
val=1;
ErfnTable[i]=val;
}
}
Erfn::~Erfn(void)
{
delete [] ErfnTable;
}
double Erfn::operator()(double x)
{
double val;
int index;
if(x<0)
{
throw ErfnRange();
}
index=x*(double)(ERFNTABLESIZE-1)/MaxX;
if(index>=ERFNTABLESIZE-1)
{
return 1-exp(-x*x)/(x*sqrt(pi))*(1-1/(2*x*x));
}
double interp=(x*(double)(ERFNTABLESIZE-1)/MaxX-index);
val=ErfnTable[index]*(1-interp)+ErfnTable[index+1]*interp;
return val;
}