Home > database >  In C programming for bosses to help emergency solving high number
In C programming for bosses to help emergency solving high number

Time:11-15

Figure 1 is a problem, figure 2 is a requirement,,, big genuflect is begged help

CodePudding user response:

 
#include

# define N 1000

The class Aintegral {
Protected:
int n;
Public:
Aintegral (int n) : n (n) {}
Virtual double integral, double min, double Max)=0.
};

The class Xintegral: public Aintegral {
Private:
Aintegral& Next;
Double fx (double x) {
return x;
}
Public:
Xintegral (int n, Aintegral& Next) : Aintegral (n), next (next) {}
The double integral, double min, double Max) {
Double the result=0;
Double delta=(Max - min)/n.
For (double I=min + delta; i Result +=fx (min + I) * * next delta. The integral (0, min + I);
}
return result;
}
};
The class Yintegral: public Aintegral {
Private:
Aintegral& Next;
Double fx (double y) {
Return * y y;
}
Public:
Yintegral (int n, Aintegral& Next) : Aintegral (n), next (next) {}
The double integral, double min, double Max) {
Double the result=0;
Double delta=(Max - min)/n.
For (double I=min + delta; i Result +=fx (min + I) * * next delta. The integral (0, + I (min) * Max);
}
return result;
}
};
The class Zintegral: public Aintegral {
Private:
Double fx (double z) {
Return the z z z * *;
}
Public:
Zintegral (int n) : Aintegral (n) {}
The double integral, double min, double Max) {
Double the result=0;
Double delta=(Max - min)/n.
For (double I=min + delta; i The result +=fx (min + I) * delta;
}
return result;
}
};


Int main (int arg c, const char * argv []) {
Zintegral z=Zintegral (N);
Yintegral y=Yintegral (N, z);
Xintegral x=Xintegral (N, y);
Double the result=x.i ntegral (0, 1);
STD: : cout & lt; <"The result:" & lt; //the result: 0.00272932
STD: : cout & lt; <"1/364:" & lt; <(double) 1/364 & lt; //1/364:0.00274725
return 0;
}
  • Related