Polynorm By Anonymous November 28, 2008 Buồn vì làm lý kô đc bạn ngồi post cho a e bài polynorm coi chơi. Bài này bạn chạy ngon rồi, a e tự hiểu nhé. #include #include #include #include class Polynorm { private: int bac; double *hs; public: Polynorm(int n) :bac(n) {hs=new double[bac+1];} Polynorm(Polynorm &p) :bac(p.bac){hs=new double[bac+1]; memcpy(hs,p.hs,(bac+1)*sizeof(double)); } ~Polynorm(){delete []hs;} public: double & operator[](int index){return hs[index];} Polynorm operator+(Polynorm &p) { Polynorm *p1=this,*p2=&p; if(bac>p.bac){p1=p2;p2=this;} Polynorm res(*p2); for(int i=0;i<=p1->bac;i++) res.hs[i]+=p1->hs[i]; return res; } Polynorm operator-(double a) { Polynorm res(*this); res.hs[0]-=a; return (res); } friend Polynorm operator*(double a,Polynorm &p) { Polynorm res(p); for(int i=0;i<=p.bac;i++) res.hs[i]*=a; return (res); } double operator()(double x) { double res=hs[bac]; for(int i=bac-1;i>=0;i--) res=res*x+hs[i]; return res; } }; void main() { double x=5; double a=3; int bacA,bacB; cout<<"Nhap so bac cua da thuc A = "; cin>>bacA; cout<<"Nhap so bac cua da thuc B = "; cin>>bacB; Polynorm A(bacA),B(bacB); cout<<"Nhap he so cho da thuc A.\n"; for(int i=0;i<=bacA;i++) { cout<<"HS["<>A[i]; } cout<<"Nhap he so cho da thuc B.\n"; for(int j=0;j<=bacB;j++) { cout<<"HS["<>B[j]; } cout<<"A[4] = "<cout<<"A(5) = "<Polynorm C=A+B; Polynorm D=a*A; cout<<"C=A+B"<for(int k=0;k<=bacA||k<=bacB;k++) { cout<<"C["<} cout<<"D=a*A voi a=3"<for(int l=0;l<=bacA;l++) { cout<<"D["<} getch(); } Share Get link Facebook X Pinterest Email Other Apps Labels Documents Programming Share Get link Facebook X Pinterest Email Other Apps Comments PigNovember 29, 2008 at 8:38 AMthx aBôn nhiều gud ;) p.s :thể loại này khó post lắm đéi, vì dễ bị hiểu sang html, mình vừa tạm thời post lạiReplyDeleteRepliesReplyPigJanuary 3, 2009 at 11:27 AMcopy vìa nhớ xóa thẻ đi đéiReplyDeleteRepliesReplyAdd commentLoad more... Post a Comment compose your comment here
Build linux kernel By Phạm Hoàng Việt November 09, 2011 Today, I will show you the way to build kernel for linux from linux source code. We can run linux from something you created from source code Read more
Thông báo : Happy birthdey to our blog By Pig September 27, 2009 Đúng giờ ngọ ngày 29-9 của 1 năm trước đây, với í tưởng là có 1 túp lều tranh cập nhật những thông tin vớ vẩn của trường mình đến với các bạn 1 cách nhanh nhất, chúng tớ đã tạo ra cái blog này... Read more
thx aBôn nhiều gud ;) p.s :thể loại này khó post lắm đéi, vì dễ bị hiểu sang html, mình vừa tạm thời post lại
ReplyDeletecopy vìa nhớ xóa thẻ
ReplyDeleteđi đéi