/**************************************************** * Evaluate a polynomial fraction for x given * * * * ------------------------------------------------- * * Ref.: "Mathématiques en Turbo-Pascal By M. Ducamp * * and A. Reverchon (vol 2), Eyrolles, Paris, 1988" * * [BIBLI 05]. * * ------------------------------------------------- * * SAMPLE RUNS: * * * * EVALUATE A POLYNOMIAL FRACTION: * * * * Enter polynomial fraction P(x)/Q(x): * * * * P(x) = x3 -5x +2 * * Q(x) = x2 -1 * * * * x value: -2 * * F(x) = + 4/3 * * x value: 1/2 * * F(x) = + 1/2 * * x value: 2 * * F(x) = - 0/3 * * x value: 1 * * Evaluation failed. * * x value: 0 * * F(x) = - 2 * * ------------------------------------------------- * * Functions used (of module Polynoms): * * * * AddNumber(), EnterPolynom(), DivNumber(), * * DisplayPolynom(), MultNumber() and SetNumber(). * * * * C++ version by J-P Moreau. * * (www.jpmoreau.fr) * ****************************************************/ #include #include #include "polynoms.h" #include "polfract.h" ar_fraction F; ar_number x,y; bool EvalPolFract(ar_fraction *F,ar_number *x,ar_number *y) { ar_number u,v; if (!EvaluatePolynom(&F->numer,x,&u)) return FALSE; if (!EvaluatePolynom(&F->denom,x,&v)) return FALSE; if (!DivNumber(u,v,y)) return FALSE; return TRUE; } void main() { printf("\n EVALUATE A POLYNOMIAL FRACTION:\n\n"); EnterPolFract(" Enter polynomial fraction P(x)/Q(x):",&F); printf("\n"); DisplayPolFract(&F); printf("\n\n"); SetNumber(&x,"1"); while (x.value!=0) { ReadNumber("x value: ",&x); if (EvalPolFract(&F,&x,&y)) { printf(" F(x) = "); WriteNumber(y); } else printf(" Evaluation failed."); printf("\n\n"); } } //end of file evalfrac.cpp