2009-06-26 01:04:13 ЭФИОП Постучите ко мне в асю 362-337-377 Это срочно | ||
2009-06-26 01:26:01 zlotty ЭФИОП пиши тут | ||
2009-06-26 01:44:36 MrHide
| ||
2009-06-26 01:47:50 Axel
| ||
2009-06-26 01:56:23 Voide
| ||
2009-06-26 02:23:50 ЭФИОП мде.. Там много... Я в асе ждал всех.. | ||
2009-06-26 02:26:13 zlotty ЭФИОП перекопировать сложно? | ||
2009-06-26 02:26:41 Axel
| ||
2009-06-26 02:31:11 ЭФИОП ну, если ещё кто-то есть, тогда... void Polinom::Insert(Odno4len &q) { current=first; Odno4len* tmp=current->next; int k=0; if (q.step>MaxStep()) { this->InsertToEnd(q.koef,q.step); //printf("i1= "); return; } current=first; while(current) { if(q.step==current->step) {current->koef=(current->koef + q.koef); //printf("i2="); return;} current=current->next; } current=first; if(current->step>q.step) { // printf("i3="); first=&q; q.next=current;return; } while (current) { if(current->next->step>q.step) break; current=current->next; } // printf("i4="); //cout<<current->next->step; tmp=current->next; q.next=tmp; current->next=&q; return; } Вот функция, коменты не удалял, сорь если что На первом вызове все нормально. Всё нормально когда добавляются одночлены а начало и в конец списка(или просто добавляются в какое-то место списка). Но если уже есть такой элемент... При втором вызове коэффициент, который должен считаться здесь while(current) { if(q.step==current->step) {current->koef=(current->koef + q.koef); //printf("i2="); return;} current=current->next; } считается по странной формуле. Чем больше вызовов для ОДНОГО И ТОГО ЖЕ ОДНОЧЛЕНА, на столько увеличивается он сам. Т.е при втором вызове функции для одного и того же одночлена, сумма посчитается как (коеф+коеф)*2, в третьем, (коеф+коеф)*3.... И так далее Почему = хз | ||
2009-06-26 02:32:32 ЭФИОП могу скинуть только функции, используемые тут,а могу всю прогу(~500 строк) | ||
2009-06-26 02:33:20 ЭФИОП #include<conio.h> #include<stdio.h> #include<assert.h> #include<iostream.h> #include<stdlib.h> class Polinom; class Odno4len { friend class Polinom; public: Odno4len(int,int); void SetValue(); int GetValue(); void ShowPart(); Odno4len* next; private: int koef; int step; }; class Polinom { public: Polinom(); ~Polinom(); void PlusOdno4len(Odno4len); void MinusOdno4len(Odno4len); void InsertToEnd(int,int); void InsertToAfBegin(int,int); void Insert(Odno4len&); Polinom Oppositing(); void DeleteFromEnd(); int DeleteFromBegin(); int QualityOfMembers(); int MaxStep(); void IncreaseForPart(Odno4len&); void Print(); void Filling(); void InsertAfter(int,Odno4len&); int NullOrNot(); Polinom operator%(Polinom); Polinom operator+(Polinom); Polinom operator-(Polinom); Polinom operator*(Polinom&); void operator=(Polinom); Odno4len operator[](int); private: Odno4len* current; Odno4len* first; }; Odno4len::Odno4len(int _koef, int _step):koef(_koef),step(_step),next(0) { } void Odno4len::ShowPart() { if(this->koef>0) printf("+%dx^%d",this->koef,this->step); if(this->koef<0) printf("%dx^%d",this->koef,this->step); if(this->koef==0) printf("+%d^%d",this->koef,this->step); } int Polinom::QualityOfMembers() { current=first; int k=0; while(current) { k++; current=current->next; } return k; } /*void Polinom::InsertAfter(Odno4len& q) { current=first; if(!i) { this->InsertToAfBegin(q.koef,q.step); return; } int j=0; do { if(j==i) break; current=current->next; j++; } while(j!=i); if(!current->next) { this->InsertToEnd(q.koef,q.step); return; } printf("n");current->ShowPart(); //assert(i<this->QualityOfMembers()); j=0; Odno4len* tmp=current->next; printf("n"); current->next=&q; // current->next->next=tmp; q.next=tmp; delete tmp; } */ int I=0; void Polinom::Insert(Odno4len &q) { current=first; Odno4len* tmp=current->next; int k=0; if (q.step>MaxStep()) { this->InsertToEnd(q.koef,q.step); //printf("i1= "); return; } current=first; while(current) { if(q.step==current->step) {current->koef=(current->koef + q.koef); //printf("i2="); return;} current=current->next; } current=first; if(current->step>q.step) { // printf("i3="); first=&q; q.next=current;return; } while (current) { if(current->next->step>q.step) break; current=current->next; } // printf("i4="); //cout<<current->next->step; tmp=current->next; q.next=tmp; current->next=&q; return; /* current=first; for(int i=0;i<=this->QualityOfMembers();i++) { if(q.step==current->step){ current->koef=current->koef+q.koef;printf("i1=%d",i); break;} // if(/*(q.step>current->step)||*///(current->next==0)) // { this->InsertToEnd(q.koef,q.step); printf("i2= %d",i);break;} //if(q.step==current->step){ current->koef=current->koef+q.koef;printf("i=%d",i); break;} /* if(q.step<current->next->step) { Odno4len* tmp=current->next; current->next=&q; q.next=tmp; // delete tmp; printf("i3=%d",i); break; } printf("i4=%d",i); printf("n%dn",this->QualityOfMembers()); current=current->next; */ //} } void Polinom::InsertToAfBegin(int koef,int step) { Odno4len* newOdno4len = new Odno4len(koef,step); current=first; Odno4len* tmp=current->next; newOdno4len->next=tmp; current->next=newOdno4len; return; } void Polinom::InsertToEnd(int koef,int step) { Odno4len* newOdno4len = new Odno4len(koef,step); if(!first) { first=newOdno4len; return; } else { current=first; while(current->next) current=current->next; current->next=newOdno4len; } } int Polinom::DeleteFromBegin() { if(!first) return 0; Odno4len* tmp = first; first=first->next; delete tmp; return 1; } int Polinom::MaxStep() { current=first; int i=current->step; while(current) { if(i<current->step) i=current->step; current=current->next; } return i; } void Polinom::Print() { Odno4len* current=first; while(current) { current->ShowPart(); if(current->next) printf(" "); else printf("."); current=current->next; } } int max(int value1, int value2) { return ( (value1 > value2) ? value1 : value2); } void Polinom::DeleteFromEnd() { if(!first->next) { delete first; first=0; } current=first; while(current->next->next) current=current->next; delete current->next; current->next=0; } Polinom::Polinom():first(0) {} Polinom::~Polinom() { } void Polinom::PlusOdno4len(Odno4len q) { current=first; int p=0; while(current) { if(q.step==current->step) { current->koef+=q.koef; p++; } current=current->next; } if(!p) { for(int v=this->MaxStep()+1;v<q.step;v++) this->InsertToEnd(0,v); InsertToEnd(q.koef,q.step); } } Polinom Polinom::Oppositing() { current=first; Polinom res; int i=0; while(current) { res.InsertToEnd(-current->koef,i); current=current->next; i++; } return res; } void Polinom::IncreaseForPart(Odno4len &q) { int i=QualityOfMembers(),n=0; current=first; while(current) { if(!q.koef) current->koef=0; printf("Increasing current= "); current->ShowPart(); current->koef*=q.koef; current->step+=q.step; n++; current=current->next; if(n==i) break; } current->next=0; printf("n"); } int Polinom::NullOrNot() { if(!first) return 0; else return 1; } /*void Polinom::Filling() { int i=0,p=0; current=first; // assert((this->QualityOfMembers())==(this->MaxStep())); int e=this->MaxStep(); for(i;i<=e;i++) { while(current) { if(current->step==i) { p++; break; } if(current==0) break; current=current->next; } if(!p) {Odno4len q(0,i); this->InsertAfter(i,q);} p=0; } }*/ Odno4len Polinom::operator[](int i) { Odno4len* current1=first; for(int v=0;v<i;) { current1=current1->next; if(current1==0) break; v++; } return *current1; } Polinom Polinom::operator+(Polinom a) { Polinom res; if(!first) return a; if(!a.first) return *this; // if(this->MaxStep()>=a.MaxStep()) {a1=*this; a2=a; } // else {a2=*this; a1=a; } // res=a1%a2; res=*this; a.current=a.first; current=first; while(a.current) { res.Insert(*a.current); a.current=a.current->next; } return res; } Polinom Polinom::operator-(Polinom a) { Polinom res,a1,a2; a1=*this; a2=a.Oppositing(); if(this->MaxStep()>=a.MaxStep()) res=a1%a2; else { res=a2%a1; } return res; } Polinom Polinom::operator%(Polinom s) { Polinom res; current=first; int i=this->MaxStep(); int j=s.MaxStep(); res=*this; for(int v=0;v<=j;v++) { res.PlusOdno4len(s[v]); res.current=res.current->next; } i++; return res; } void Polinom::operator=(Polinom s) { int i=0,k,st; int l=s.QualityOfMembers(); current=first; if(first) {for(int n=0; n<=l;n++) { this->DeleteFromEnd(); } first=0;} while(i<l) { k=s[i].koef; st=s[i].step; this->InsertToEnd(k,st); i++; } } Polinom Polinom::operator*(Polinom& s) { Polinom res; Polinom s1; Polinom s2; int i=0; Odno4len q=*current; s.current=s.first; current=first; while(s.current) { s1=(*this); printf("n s= "); s.Print(); printf("ns1= "); s1.Print(); s1.IncreaseForPart(*s.current); printf("n s.current= "); (*s.current).ShowPart(); printf("ns1*current= "); s1.Print(); res=(res+s1); printf("nres[%d]= ",i); res.Print(); s.current=s.current->next; s1=s2; printf("ns1 v konce= "); s1.Print(); i++; } return res; } void main() { int I=0; clrscr(); /* Polinom s; Polinom s1; s.InsertToEnd(-5,0); printf("ns0="); s.Print(); printf("n"); s.InsertToEnd(-10,1); printf("ns1="); s.Print(); printf("n"); s.InsertToEnd(20,2); printf("ns0="); s.Print(); printf("n"); s1.InsertToEnd(3,0); s1.InsertToEnd(4,1); s.InsertToEnd(1,3); s.InsertToEnd(3,4); s.Print(); printf("n"); s1.Print(); printf("nMax step=%d",s.MaxStep()); printf("nMax step=%dn",s.MaxStep()); s.Print(); printf("nn"); s1.Print(); getch(); clrscr(); printf("n"); s1.InsertToEnd(3,2); s1.InsertToEnd(3,3); s1.InsertToEnd(3,4); s1.InsertToEnd(5,5); Polinom res; res=s; printf("ns= "); res.Print(); printf("ns1="); res=s1; res.Print(); printf("ns1+s= "); res=(s1+s); res.Print(); res=(s+s1); printf("ns+s1= "); res.Print(); res=(s1-s); printf("ns1-s= "); res.Print(); printf("ns=!!!! "); s.Print(); printf("n"); res=(s-s1); printf("ns-s1= "); res.Print(); Odno4len q(3,5); res.IncreaseForPart(q); printf("n(s-s1)*3x^5= "); res.Print(); res.InsertToMiddle(4,q); printf("ns-s1 3x^5 - 3-i el-t= "); res.Print(); getch(); */ Polinom s; Polinom r; Polinom res; Odno4len q1(2,1); Odno4len q2(4,2); Odno4len q3(6,5); Odno4len q4(3,7); Odno4len q5(2,0); Odno4len q6(2,2); s.Insert(q4); s.Insert(q2); s.Insert(q3); s.Insert(q1); r.Insert(q6); r.Insert(q5); r.Insert(q5); r.Insert(q5); r.Insert(q5); r.Insert(q5); r.Insert(q6); r.Insert(q6); r.Insert(q6); printf("ns= "); s.Print(); printf("nr= "); r.Print(); res=s*r; printf("nres!!= "); res.Print(); //Polinom e; //s=e; //printf("n"); //s.Print(); /*s.Insert(q1); s.Insert(); s.Insert(); s.Insert(); s.Insert(3,0); r.Insert(1,9); r.Insert(2,0); r.Insert(1,2);*/ /*printf("r= "); r.Print(); printf("nres= "); r=r*s; r.Print(); printf("ns= "); s.Print(); */ //r.Filling(); //r.Print(); getch(); clrscr(); do { { clrscr(); cout<<"<<Vuberite pynkt meny>>"<<endl; cout<<"1->Vvod polinoma."<<endl; cout<<"2->Vuvod polinoma."<<endl; cout<<"3->Symma polinomov."<<endl; cout<<"4->Raznost' polinomov."<<endl; cout<<"5->Proizvidenee polinomov."<<endl; cout<<"6->Vuxod."<<endl; int p=0; scanf("%d",&p); switch(p) { case 1: { int koef=0,step=0; printf("<<Vvod polinoma>>nVvedite max stepen' polinoma k= "); scanf("%d",&step); for(int i=0;i<=step;i++) { printf("Vvedite koef dlua stepeni %dn",i); scanf("%d",&koef); s.InsertToEnd(koef,i); } break; } case 2: { cout<<"<<Vu voLLIli v Vuvod polinoma>>"<<endl; if(!s.NullOrNot()) cout<<"ERROR!!!VVEDITE POLINOM!!!"<<endl; else s.Print(); getch(); break; } case 3: { cout<<"Vu voLLli v Summu polinomov"<<endl; if(!s.NullOrNot()) cout<<"ERROR!!!VVEDITE POLINOM!!!"<<endl; else { Polinom s1; Polinom res; int koef=0,step=0; printf("Vvedite max stepen'vtorogo polinoma/ kotoriy budem dobavlyat' k= "); scanf("%d",&step); for(int i=0;i<=step;i++) { printf("Vvedite koef dlua stepeni %dn",i); scanf("%d",&koef); s1.InsertToEnd(koef,i); } res=s+s1; printf("ns1= "); s.Print(); printf("n+ns2= "); s1.Print(); printf("n=nres= "); res.Print(); getch(); } break; } case 4: { cout<<"<<Vu voLLIli v Raznost' polinomov>>"<<endl; if(!s.NullOrNot()) cout<<"ERROR!!!VVEDITE POLINOM!!!"<<endl; else { Polinom s1; Polinom res; int koef=0,step=0; printf("Vvedite max stepen'vtorogo polinoma/ kotoriy budem vi4itat' k= "); scanf("%d",&step); for(int i=0;i<=step;i++) { printf("Vvedite koef dlua stepeni %dn",i); scanf("%d",&koef); s1.InsertToEnd(koef,i); } res=s-s1; printf("ns1= "); s.Print(); printf("n-ns2= "); s1.Print(); printf("n=nres= "); res.Print(); getch(); } break; } case 5: { cout<<"<<Vu voLLIli v Proizvidenee polinomov>>"<<endl; break; } case 6: { exit(0); } } } } while(1); } | ||
2009-06-26 02:33:44 ЭФИОП воть) Там куча каментов, влом было удалять( | ||
2009-06-26 09:27:19 MrHide ЭФИОП а еще было бы неплохо озвучить задачу, что должна делать прога что функции | ||
2009-06-26 17:29:06 ЭФИОП MrHide позна) Это было немного срочно и на сегодня :) А ваще она должна выводить сумму, разность, произведение ПОЛИНОМОВ, состоящих из МНОГОЧЛЕНОВ(полином - список многочленов). Ну, я её уже впарил, не дождался вас.. | ||
2009-06-26 22:34:14 MrHide
это главное =) кстати, мой тебе совет перед описанием функции в комментарии писать для чего она предназначена что принимает на вход, что выдает на выходе при описаниии переменных в классе указывать для чего они предназначены все это и тебе полезно быдет, и облегчит задачу тех, кто пытается тебе помочь, когда ты кому-то код скидываешь =) | ||