Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can any1 translate this code from Java to C/C++ please public class Integrale{ p

ID: 3649565 • Letter: C

Question

Can any1 translate this code from Java to C/C++ please

public class Integrale{


public static double Fonction(double x, int n){
double resultat=0;
resultat =(Math.pow(x, n)/(x+5));
return resultat;
}

public static double Somme_2f_x(int n,int y){
double resultat =0;
double h =1.0/y;
for(int i=2;i<=y-1;i=i+2){
resultat = resultat+Fonction(i*h,n);
}

return resultat;
}

public static double Somme_4f_x(int n,int y){
double resultat =0;
double h =1.0/y;
for(int i=1;i<=y;i=i+2){
resultat = resultat+Fonction(i*h,n);
}

return resultat;
}
public static double Simpson1_3(int y,double bornInf,double bornSup,int n){
double resultat=0;
double h =1.0/y;

double f0 = Fonction(bornInf,n);
double f1= Somme_2f_x(n,y);
double f2=Somme_4f_x(n,y);
double f3=Fonction(bornSup,n);

resultat =h/3.0 *(f0 + 2*f1 + 4*f2 + f3);
return resultat;
}

public static double Simpson3_8(int y , double bornInf,double bornSup,int n ){
double resultat =0;
double h = 1.0/y;


double f0 = Fonction(bornInf,n);
double f1= Fonction (bornInf+h,n);
double f2= Fonction (bornInf+2*h,n);
double f3=Fonction(bornSup,n);
resultat = (3.0/8.0)*h * (f0 + 3*f1 + 3*f2 + f3);

return resultat;
}

public static double Calculer(int y, int n){
double resultat=1;
double h = 1.0/y;
if (y % 2 ==0.0){ //y est pair
resultat = Simpson1_3(y,0,1,n);
}
if (y%2 ==1.0){//y est impair
resultat = Simpson1_3(y,0,(1-3*h),n) + Simpson3_8(y,(1.0-3.0*h),1.0,n);
}


return resultat;
}


public static void main (String args[]){
for (int i=2;i<=1000;i=i+1){
System.out.println("i = "+i+" "+Calculer(i,25));
}
}
}

Explanation / Answer

double Fonction(double x, int n) { double resultat=0; resultat =(Math.pow(x, n)/(x+5)); return resultat; } double Somme_2f_x(int n,int y) { double resultat =0; double h =1.0/y; for(int i=2;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote