#include #include #include #define begin { #define end } typedef double (*FPtr) (double); class Fcn{ public: Fcn(FPtr f, double a1, double b1); FPtr F; double a,b,root,froot,error; int no_iterations; int bisect(); void writeout (int status); }; Fcn::Fcn(FPtr f, double a1, double b1){ F=f; a = a1; b = b1; } int Fcn::bisect() { double a1, b1, ya, yb, yc, c; no_iterations = 0; // Initialize iteration counter cout << "\n Start again\n"; a1= a; b1 = b; ya=F(a1); // function values at x1 and x2 yb=F(b1); if (ya*yb > 0) return(2); while (no_iterations <= 100) { no_iterations++; c= (a1+b1)/2; yc=F(c); if (yc==0) begin a1 = c; b1 = c; end else if (yb*yc>0) begin b1 = c; yb = yc; end else begin a1 = c; ya = c; end if ((b1-a1)&& sqrt(F(c)*F(c)) < 1e-15) begin root = (a1+b1)/2; froot = F(c); error = ((b1-a1)/2); return(1); end } // end of while return(0); } // end of function void Fcn::writeout(int status) { switch(status){ case 1: cout<<"\na= "<