Write a polynomial adder application, which allows the user toinput, and then ad
ID: 3608799 • Letter: W
Question
Write a polynomial adder application, which allows the user toinput, and then add, two polynomials. Divide into three files: poly.h- The polynomial ADT headerfile poly.cpp-The polynomial ADT implementation file prog.cpp-File containing main ( ) Sample dialog POLYNOMIAL ADDER This program adds two polynomials and displays theresult. Enter first polynomial Enter each term on a separate line; coefficient followed bypower. For example, 3 4 represents the term 3x^4. Enter -1 -1 to end input for the polynomial input: 4 5 7 4 -1 2 90 -1-1 output: First polynomial: 4x^5+7x^4-x^2+9 Enter second polynomial input : 2 4 31 -100 -1-1 output: Second polynomial: 2x^4+3x-10 Use try/cath to detect inputs of powers that are out ofrange: input: 9 0 4 5 7 -4 Error:cannot have negative power Please re-enter term and continue input: 7 4 -1 2 -1 -1 output: 4x^5+7x^4-x^2+9 Write a polynomial adder application, which allows the user toinput, and then add, two polynomials. Divide into three files: poly.h- The polynomial ADT headerfile poly.cpp-The polynomial ADT implementation file prog.cpp-File containing main ( ) Sample dialog POLYNOMIAL ADDER This program adds two polynomials and displays theresult. Enter first polynomial Enter each term on a separate line; coefficient followed bypower. For example, 3 4 represents the term 3x^4. Enter -1 -1 to end input for the polynomial input: 4 5 7 4 -1 2 90 -1-1 output: First polynomial: 4x^5+7x^4-x^2+9 Enter second polynomial input : 2 4 31 -100 -1-1 output: Second polynomial: 2x^4+3x-10 Use try/cath to detect inputs of powers that are out ofrange: input: 9 0 4 5 7 -4 Error:cannot have negative power Please re-enter term and continue input: 7 4 -1 2 -1 -1 output: 4x^5+7x^4-x^2+9Explanation / Answer
please rate - thanks I didn't have time to add the error checking in the input. I'm not familiar with try/catch. I also don't know how tobreak up into multiple files #include void input(int[],int[],int &,int); void output(int[],int[],int,int); void add(int[],int[],int[],int[],int,int,int [],int [],int&); int main() {int i,na,nb,nc,acoeff[10],bcoeff[10]={0},aexp[10]={0}; int bexp[10]={0},ccoeff[10]={0},cexp[10]={0}; input(acoeff,aexp,na,1); output(acoeff,aexp,na,1); input(bcoeff,bexp,nb,2); output(bcoeff,bexp,nb,2); add(bcoeff,bexp,acoeff,aexp,nb,na,ccoeff,cexp,nc); output(ccoeff,cexp,nc,3); system("pause"); return 0; } void add(int ac[],int ae[],int bc[],int be[],int na,int nb, int cc[],int ce[], int &nc) {int i=0,j=0,k=0; do {if(ae[i]>be[j]) {ce[k]=ae[i]; cc[k++]=ac[i++]; } else if(be[j]>ae[i]) {ce[k]=be[j]; cc[k++]=bc[j++]; } else {ce[k]=be[k]; cc[k++]=ac[i++]+bc[j++]; } }while(ce[k-1]!=0); nc=k-2; return; } void input(int c[],int e[],int &n,int poly) {n=0; coutc[n]>>e[n]; } n--; return; } void output(int c[],int e[],int n,int poly) {int i; if(polyRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.