Nomad987
دوشنبه 21 دی 1388, 12:14 عصر
سلام دوستان من سورس کد برنامه جمع چند جمله ای ها رو دارم فقط موقع کامپایلش ارور میده.
البته یه تازه کارم و اطلاعات کمی تو این زمینه دارم.
ممنون میشم از دوستان اگه مرحله به مرحله راهنمایی کنن و بگن چطور فایل اجرایی رو بگیرم.
هر کاری که لازمه انجام بدم رو لطف کنید و مرحله به مرحله از اول توضیح بدین.
اینم از کد ها:
تعریف کلاس چند جمله ای:
struct term
{
int coef ;
int exp ;
viod Init(int c,int e) {coef=c;exp=e};
};
class polynomial
{
friend polynomial operator+(const polynomial&,const polynomial&) ;
private:
list <term> poly ;
};
و جمع دو چند جمله ای:
poynomial operator+(const polynomial& a , const polynomial& b){
// polynimials a and b are added and the sum returned
term *p,*q,temp;
ListIterator <Element> Aiter(a.poly) ; ListIterator <Element> Biter(b.poly) ;
polynomial c;
p=Aiter.First() ; q=Biter.First() ; // get first node in a and b
while (Aiter.NotNull() && Biter.NotNull()) { // current node is not null
switch (compare(p->exp,q->exp)) {
case '=':
int x=p->coef + q->coef ; temp.Init(x,q->exp);
if(x) c.poly.Attach(temp) ;
p=Aiter.Next() ; q=Biter.Next() ; // advance to next term
break;
case'<':
temp.Init(q->coef,q->exp) ; c.poly.Attach(temp) ;
q=Biter.Next() ; // next term of b
break;
case'>':
temp.Init(p->coef,p->exp) ; c.poly.Attach(temp) ;
p=Aiter.Next() ; // next term of a
}
}
while (Aiter.NotNull()) { // copy rest of a
temo.Init(p->coef,p->exp) ; c.poly.Attach(temp) ;
p=Aiter.Next() ;
}
while (Biter.NotNull()) { // copy rest of b
temp.Init(q->coef,q->exp) ; c.poly.Attach(temp) ;
q=Biter.Next() ;
}
return c;
}
اگه کد اشتباهه یا باید چیز اضافه ای رو بنویسم لطفا بگید.
ممنون
البته یه تازه کارم و اطلاعات کمی تو این زمینه دارم.
ممنون میشم از دوستان اگه مرحله به مرحله راهنمایی کنن و بگن چطور فایل اجرایی رو بگیرم.
هر کاری که لازمه انجام بدم رو لطف کنید و مرحله به مرحله از اول توضیح بدین.
اینم از کد ها:
تعریف کلاس چند جمله ای:
struct term
{
int coef ;
int exp ;
viod Init(int c,int e) {coef=c;exp=e};
};
class polynomial
{
friend polynomial operator+(const polynomial&,const polynomial&) ;
private:
list <term> poly ;
};
و جمع دو چند جمله ای:
poynomial operator+(const polynomial& a , const polynomial& b){
// polynimials a and b are added and the sum returned
term *p,*q,temp;
ListIterator <Element> Aiter(a.poly) ; ListIterator <Element> Biter(b.poly) ;
polynomial c;
p=Aiter.First() ; q=Biter.First() ; // get first node in a and b
while (Aiter.NotNull() && Biter.NotNull()) { // current node is not null
switch (compare(p->exp,q->exp)) {
case '=':
int x=p->coef + q->coef ; temp.Init(x,q->exp);
if(x) c.poly.Attach(temp) ;
p=Aiter.Next() ; q=Biter.Next() ; // advance to next term
break;
case'<':
temp.Init(q->coef,q->exp) ; c.poly.Attach(temp) ;
q=Biter.Next() ; // next term of b
break;
case'>':
temp.Init(p->coef,p->exp) ; c.poly.Attach(temp) ;
p=Aiter.Next() ; // next term of a
}
}
while (Aiter.NotNull()) { // copy rest of a
temo.Init(p->coef,p->exp) ; c.poly.Attach(temp) ;
p=Aiter.Next() ;
}
while (Biter.NotNull()) { // copy rest of b
temp.Init(q->coef,q->exp) ; c.poly.Attach(temp) ;
q=Biter.Next() ;
}
return c;
}
اگه کد اشتباهه یا باید چیز اضافه ای رو بنویسم لطفا بگید.
ممنون