mga bro and guros apil napud sis basta maayo.. patabang unta ko ninyo naa mi project sa skol then lisod kaayo naa nako nabuhat gamay unya ang uban kay dli gyud kaya. patabang unta ko gamay para matiwas nako ug himo. kinahanglan gyud kaayo namo..
mao ni ay.. mag buhat kuno mi ug program na mo read ug input sa user nga polynomial. then ang amo buhaton is kinahanlan nga pwede makapili ang user kon gusto ba niya i add or i subtract. mao rana pero lisod man i implement. mao ni ang link sa ako gi buhat na codes palihog ko tabang ninyo.. pang finals nani namo.. by the way ang gamiton kay C diay nga program pwede rasad C++
tan-awa nlang ni ang codes kay dli ko kabalo asa i share:
naay mga functions diha nga wla ma tiwas mao na ako ki lisdan.. tabang mga bro
#include "Polynomial.h"
#include <stdlib.h>
/*----------------------------------------------*/
/* Sets all coefficients to 0 */
/*--------------------------------------------- */
void initialize(Polynomial p)
{ int i;
for(i=0; i<MaxDegree; i++)
p[i] = 0;
}
/*----------------------------------------------*/
/* Builds a polynomial by randomly generating */
/* exponents and coefficients. */
/*--------------------------------------------- */
void build(Polynomial p)
{
int i,n,coef,exp;
initialize(p);
n = random(10);
for (i=0; i < n; i++)
{
exp = random(10);
coef = random(10);
if (coef % 2 == 0)
coef = -coef;
addTerm(coef,exp,p);
}
}
/*----------------------------------------------*/
/* Adds a term by setting the coefficient */
/* and the exponent */
/*--------------------------------------------- */
void addTerm(int coef,int exp,Polynomial p)
{
p[exp] = coef;
}
/*----------------------------------------------*/
/* Displays the polynomial on the screen */
/*--------------------------------------------- */
void display(char *name,Polynomial p)
{ int i;
printf("%s = ",name);
for (i=MaxDegree-1; i>=0;i--)
{ if (p[i] != 0)
{
printf((p[i]>0)?" +":" ");
printf(((p[i] != 1)?"%d":""),p[i]);
printf((i!=0)?"X%d":"",i);
}
}
}
/*---------------------------------------------- */
/* Adds the two polynomials p1 and p2 and */
/* stores the resulting polynomial in result. */
/* This can be done by adding the coefficients */
/* of the two polynomials. */
/*---------------------------------------------- */
void add(Polynomial p1,Polynomial p2,Polynomial result)
{
}
/*------------------------------------------------------ */
/* Substracts polynomial p2 from p1 and */
/* stores the resulting polynomial in result. */
/* This can be done by subtracting the coefficients */
/* of the second from the first polynomial. */
/*------------------------------------------------------ */
void subtract(Polynomial p1,Polynomial p2,Polynomial result)
{
}
/*------------------------------------------------------ */
/* Gets the derivative of p and stores it in result. */
/*------------------------------------------------------ */
void derivative(Polynomial p,Polynomial result)
{
}
/*------------------------------------------------------ */
/* Evaluates the polynomial at point/value x. */
/* This means substituting x in the polynomial and */
/* computing for the value of the whole expression. */
/*------------------------------------------------------ */
int evaluate(int x,Polynomial p)
{
}