changing C code into C++

November 25, 2011 at 15:48:58
Specs: Windows 7
Dear friends

The following code is correct, but it is written in C, Can anyone help me to change it to C++?

Thank you
#include <stdio.h>
#include <math.h>
#define pi 3.141593
#define A 1.
#define qx (0.005*pi)
#define qy (0.005*pi)
#define F(x) ((*f)(x))
#define sqr(x) ((x)*(x))
#define no_intv 5000 /* no. of (equal) intervals for the integral */

double xsav;
double (*nrfunc)();

double ellip2d(),funcn(),funca(),Nq,Aq;

double ellip2d(a,b,func)
double a,b;
double (*func)();
double simpson(),f1();
return simpson(a,b,f1);

double f1(x)
double x;
double simpson(),f2();
return simpson(-pi,pi,f2);

double f2(y)
double y;
return ((*nrfunc)(xsav,y));

double funcn(x,y)
double x,y;

return x*x+y;

double funca(x,y)
double x,y;
return x*x+y*y;
double simpson(a,b,f)
double a,b;
double (*f)();
/* integrnant = f(x), interval = [a,b], no. of intervals = no_int
i=1 -> x=a, i=2 -> x=a+h, ..., i=no_int+1 -> x=b; no_int = even */
int i;
double x,h,sum=0.;
if(fabs(b-a)<0.000001) return 0.;
for(i=2;i<=no_intv;i++) {
if(i&1) sum+=2.*F(x); /* bitwise definition of odd no. */
else sum+=4.*F(x);
return (h*(F(a)+sum+F(b))/3.);

See More: changing C code into C++

Report •

November 26, 2011 at 01:05:46
I can't see anything there that isn't valid C++. Why do you want to change it?

Report •

November 26, 2011 at 02:36:28
Dear ijack

Thank you very much for your reply. This code is valid and there is no problem with it, but I have additional steps which are written in C++ to add them to this code. I will be grateful if could please change it for me from C to C++.

Best Wishes

Report •

November 26, 2011 at 02:51:37
Just add the additional steps. As this code is already valid C++ it should interoperate with the new code without any problems.

Report •

Related Solutions

November 26, 2011 at 02:59:08
Dear ijack

Thank you for your quick response. I know it is, but I would really change it to C++, I will be really appreciate if could help me with this issue.

with all the respect

Report •

November 26, 2011 at 03:27:01
I really don't know what more you can want. The code is already valid C++, it works, so what do you want changed?

I'm beginning to suspect that this is a homework assignment and that you have a requirement to use particular C++ features. I'm afraid that I'm not interested in helping with that.

Report •

November 26, 2011 at 03:33:01
Thank you very much sir for your help and cooperation

Report •

Ask Question