0

Dear Friends

Can you help me to convert the following code from c into c++ and save the file as file.cpp. I would do that in order to use cout instead of fprint and for another reasons.

```
#include <stdio.h>
#include <math.h>
#define pi 3.141593
#define F(x) ((*f)(x))
#define sqr(x) ((x)*(x))
#define no_intv 5000
double xsav;
double (*nrfunc)();
main()
{
double ellip2d(),funcn(),Nq;
Nq=ellip2d(-pi,pi,funcn);
printf("Nq=%f\n",Nq);
system("pause");
}
//////////////////////////////////////
double ellip2d(a,b,func)
double a,b;
double (*func)();
{
double simpson(),f1();
nrfunc=func;
return simpson(a,b,f1);
}
double f1(s1)
double s1;
{
double simpson(),f2();
xsav=s1;
return simpson(-pi,pi,f2);
}
double f2(s2)
double s2;
{
return ((*nrfunc)(xsav,s2));
}
////////////////////////////////////
double funcn(x,y)
double x,y;
{
return x*x+y;
}
double simpson(a,b,f)
double a,b;
double (*f)();
{
int i;
double x,h,sum=0.;
if(fabs(b-a)<0.000001) return 0.;
h=(b-a)/((float)no_intv);
x=a+h;
for(i=2;i<=no_intv;i++) {
if(i&1) sum+=2.*F(x);
else sum+=4.*F(x);
x+=h;
}
return (h*(F(a)+sum+F(b))/3.);
}
```

*Edited 5 Years Ago by Narue*: Added code tags