TAB

One of the works done by our Robotics and Machine Learning division,
SELF-LEVELING QUADCOPTER
Arduino based Quadcopter.
Self-leveling is acheived by the aligning the quadcopter using the readings from the gryo as well as the accelerometer.
A four channel RC transmitter is used to control the movement of the quadcopter when in flight. Kindly subscribe to our YouTube Channel and stay tuned.

Friday 11 March 2016

PRACTICE PROBLEM 4 :overload polynomial


AT LAST IT WORKED!!!!!
-------------------------------------------------------------------------------------------------------------------------------

 This program is really complex!

================================================= 

================================================
poly::poly()
{
    num=0;
    terms=new term[10];
}
poly::poly(int a)
{
    num=a;
    terms=new term[10];
}
poly::poly(poly &p)
{
    num=p.num;
    terms=new term[10];
}
poly poly::operator+(poly& p)
{
    poly temp;
    int i,j,k=0;
    int done =0;
    term *point,*p2,*p3;
    p2=p.terms;
    p3=terms;
    point=temp.terms;

    while(done!=1)
    {
        if((p.terms)->expo>terms->expo)
        {
            temp.terms->expo=p.terms->expo;
            temp.terms->coeff=p.terms->coeff;
            p.terms++;

        }

        else if((p.terms)->expo<terms->expo)
        {
            temp.terms->expo=terms->expo;
            temp.terms->coeff=terms->coeff;
            terms++;

        }
        else
        {
            temp.terms->expo=terms->expo;
            temp.terms->coeff=p.terms->coeff+terms->coeff;
            p.terms++;
            terms++;
        }
    if(p.terms->coeff==0 && p.terms->expo==0)
    {
    if(terms->coeff==0 && terms->expo==0)
    {
    done=1;
    }
    }
        (temp.terms)++;
        k++;
    }
    temp.num=k;
    temp.terms->coeff=0;
    temp.terms->expo=0;
    temp.terms=point;
    p.terms=p2;
    terms=p3;
    return temp;
}
poly poly::operator++()
{
    poly temp;
    term *point,*p2,*p3;
    int d=0;
    point=temp.terms;
    p2=terms;
    temp.terms->coeff=terms->coeff+1;
    temp.terms->expo=terms->expo+1;
    d++;
    temp.terms++;
    while(terms->coeff!=0 || terms->expo!=0)
    {
        temp.terms->coeff=terms->coeff;
        temp.terms->expo=terms->expo;
        temp.terms++;
        d++;
        terms++;
    }
    temp.num=d;
    temp.terms->coeff=0;
    temp.terms->expo=0;
    temp.terms=point;
    terms=p2;

    return temp;
}
poly poly::operator++(int a)
{
    poly temp;
    term *point,*p2,*p3;
    int d=0;
    point=temp.terms;
    p2=terms;
    temp.terms->coeff=terms->coeff+1;
    temp.terms->expo=terms->expo+1;
    d++;
    temp.terms++;
    while(terms->coeff!=0 || terms->expo!=0)
    {
        temp.terms->coeff=terms->coeff;
        temp.terms->expo=terms->expo;
        temp.terms++;
        d++;
        terms++;
    }
    temp.num=d;
    temp.terms->coeff=0;
    temp.terms->expo=0;
    temp.terms=point;
    terms=p2;

    *this=temp;
}
poly& poly::operator=(const poly& p)
{
    num=p.num;
    terms=p.terms;
}
istream& operator>>(istream& b,term& t)
{

    b>>t.coeff>>t.expo;
    return b;
    }
ostream& operator<<(ostream& a,term& t)
{
    a<<t.coeff<<endl<<t.expo<<endl;
    return a;
}
istream& operator>>(istream& a,poly& p)
{
    a>>p.num;
    term *point;
    point=p.terms;
    for(int i=0;i<p.num;i++)
    {
    a>>*(p.terms);
    (p.terms)++;
    }
    p.terms=point;


    return a;
    }
ostream& operator<<(ostream& a,poly& p)
{
    term *point;
    point=p.terms;
    for(int i=0;i<p.num;i++)
    {
    a<<*(p.terms);
    (p.terms)++;
    }
    p.terms=point;
    return a;
}

1 comment:

  1. hi.. this is Rohan's friend... thank you for your help... keep up this good work

    ReplyDelete