Add two polynomials. Prompt the user to enter two polynomials (as above in step a), then ac these two polynomials and print out the result. e.g.: for the first polynomial, the user enters 3 for the degree of the polynomial and enters 7, 0, 9, 10 for each term from the highest degr the lowest degree; for the second polynomial, the user enters 2 for the degree of the polynomial and enters 1, 2, 3 for each term from the hig degree to the lowest degree, then you have: 1st polynomial: 7x^3+9x+10 2nd polynomial: x^2+2x+3 After vou add these two polynomials: your have 7x^3+x^2+11x+13.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

plz solve the b and c part here is the a part 

#include<iostream>

using namespace std;

//main function
int main(){

    //declare d1 for degree
    int d1;

    //asking user to enter degree
    cout<<"Degree of the polynomial : ";
    cin>>d1;

    //declare array
    int A1[d1 + 1];

    //asking user to enter coefficient
    cout<<"Enter coefficient for each term from highest degree to the lowest degree : ";
    for(int i = 0; i <= d1; i++)
        cin>>A1[i];

   //declare variables
   int k = d1;

   //for loop to print polynomial
    for( int i = 0; i <= d1; i++,k--){

        //when coefficient value is not 0 nor 1
        if(A1[i] !=0 && A1[i] != 1 ){
            
            //print polynomial with variable
            if(i != d1 && i != d1-1){
                cout<<A1[i];
                cout<<"x^"<<k;
            }
            
            //when it is 2nd last coefficient
            if(i == d1-1)
                cout<<A1[i]<<"x";
                
            //when it is not 2nd last coefficient
            if(i != d1-1)
                cout<<" + ";
                
            //when it is last element
            if(i == d1)
                cout<<A1[i];
        }

       //when coefficient value is 1
       if(A1[i] == 1){
           
        //print polynomial
        if(i != d1 && i != d1-1)
                cout<<"x^"<<k;

        if(i == d1-1)
                cout<<"x";

        if(i != d1-1)
                cout<<" + ";

        if(i == d1)
               cout<<A1[i];
      }
    }

return 0;
}

c. Add two polynomials.

Prompt the user to enter two polynomials (as above in step a), then add these two polynomials and print out the result.

e.g.: for the first polynomial, the user enters 3 for the degree of the polynomial and enters 7, 0, 9, 10 for each term from the highest degree to the lowest degree; for the second polynomial, the user enters 2 for the degree of the polynomial and enters 1, 2, 3 for each term from the highest degree to the lowest degree, then you have:

1st polynomial: 7x^3 + 9x + 10  
2nd polynomial: x^2 + 2x + 3  

After you add these two polynomials: you have 7x^3 + x^2 + 11x + 13.
Transcribed Image Text:c. Add two polynomials. Prompt the user to enter two polynomials (as above in step a), then add these two polynomials and print out the result. e.g.: for the first polynomial, the user enters 3 for the degree of the polynomial and enters 7, 0, 9, 10 for each term from the highest degree to the lowest degree; for the second polynomial, the user enters 2 for the degree of the polynomial and enters 1, 2, 3 for each term from the highest degree to the lowest degree, then you have: 1st polynomial: 7x^3 + 9x + 10 2nd polynomial: x^2 + 2x + 3 After you add these two polynomials: you have 7x^3 + x^2 + 11x + 13.
**3. ADT Array-based Polynomials**

a. **Input/Output**

   **Input:**
   
   1. The degree of the polynomial (the highest degree of all the terms in the polynomial).
   2. The coefficient for each term from the highest degree to the lowest degree.

   **Output:**
   
   Print out the polynomial.
   
   *Example:* If the user enters 3 for the degree of the polynomial and enters 7, 0, 9, 10 for each term from the highest degree to the lowest degree, then the output will be: \(7x^3 + 0x^2 + 9x + 10\).

b. **Evaluation**

   Once the polynomial has been entered by the user, prompt the user to enter the value of \(x\) and evaluate the polynomial. Print out the value of the polynomial.

   *Example:* If the user enters 2 for the value of \(x\) (that is, \(x = 2\)), then you evaluate the polynomial as \(7 \times 2^3 + 0 \times 2^2 + 9 \times 2 + 10 = 84\) and print out the value of the polynomial, which is 84.
Transcribed Image Text:**3. ADT Array-based Polynomials** a. **Input/Output** **Input:** 1. The degree of the polynomial (the highest degree of all the terms in the polynomial). 2. The coefficient for each term from the highest degree to the lowest degree. **Output:** Print out the polynomial. *Example:* If the user enters 3 for the degree of the polynomial and enters 7, 0, 9, 10 for each term from the highest degree to the lowest degree, then the output will be: \(7x^3 + 0x^2 + 9x + 10\). b. **Evaluation** Once the polynomial has been entered by the user, prompt the user to enter the value of \(x\) and evaluate the polynomial. Print out the value of the polynomial. *Example:* If the user enters 2 for the value of \(x\) (that is, \(x = 2\)), then you evaluate the polynomial as \(7 \times 2^3 + 0 \times 2^2 + 9 \times 2 + 10 = 84\) and print out the value of the polynomial, which is 84.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education