Question

In: Computer Science

This is C++ programming. Use separate compilation to implement a polynomial ADT that manipulates polynomials in...

This is C++ programming.

Use separate compilation to implement a polynomial ADT that manipulates polynomials in a single variable x (e.g., p = 4 x^5 + 7 x^3 – x^2 + 9 ). For this problem, consider only polynomials whose exponents are non-negative integers. You are required to identify a proper data representation schema to store such polynomials and hide such data from external users of this ADT. Additionally, your ADT will at least include the following member functions:

One default constructor, which creates a polynomial with no terms.

Ex: Polynomial p; // This should create a polynomial with no terms.

One method allowing one to get an entire polynomial by interacting with the user (by writing to cout and reading from cin) to obtain the degree and coefficient of each term in a polynomial. If the user enters nonsense, your program should not crash! It is up to you how to handle this case. The method can look something like this when called:

myPolynomial.readFromUser(); // prompts the user for the degree and
// coefficients and stores the
// results in myPolynomial

degree() // Returns the degree of a polynomial, which is the highest power of a term with a nonzero coefficient.

  E.g: int deg = myPolynomial.degree();

coefficient(power) // Returns the coefficient of the x p o w e r term.

changeCoefficient(newCoefficient, power) // Replaces the coefficient of the x p o w e r term with newCoefficient. (Note: This method should handle the invalid case too. what happens if the power is out of range?? )

A method that multiplies a polynomial by an integer (make this a normal named method - do not overload the multiplication (*) operator).

A method that adds two polynomials ( overload the addition(+) operator as a standalone function).

Overload the division operator (/) as a member function to multiple divide a polynomial by a scalar variable.

A method that prints out a polynomial. Ex: cout<<p; // should print 4 x^5 + 7 x^3 – x^2 + 9 (Here you have to overload the "<<" put operator as a friend function. Because you cannot overload it as a member function)

Overload the subtraction operator(-) as a member function to subtract two polynomials.

Example: p1 = 3 x^3 - 2 x^2 - 3; p2 = 4 x^4 - x^2 + 3 x^1 - 5;

p3 = p1 - p2; // p3 should result in: - 4 x^4 + 3 x^3 - x^2 - 3 x + 2;

Overload the negation operator (-) as a member function to negate a polynomial. (NOTE: This is different from the subtraction operator! The subtraction operator takes an argument - the polynomial you are subtracting - whereas the negation operator takes no arguments.)

Example: p1 =  3 x^3 - 2 x^2 - 3; // -p1 should result in - 3 x^3 + 2 x^2 +3;

Solutions

Expert Solution


Related Solutions

In C++, Design and implement an ADT that represents a triangle. The data for the ADT...
In C++, Design and implement an ADT that represents a triangle. The data for the ADT should include the three sides of the triangle but could also include the triangle’s three angles. This data should be in the private section of the class that implements the ADT. Include at least two initialization operations: one that provides default values for the ADT’s data, and another that sets this data to client-supplied values. These operations are the class’s constructors. The ADT also...
In C++, Implement the queue ADT with a singly linked list
In C++, Implement the queue ADT with a singly linked list
C++ problem - Implement and add the advanced functionalities to the ADT of the BST made...
C++ problem - Implement and add the advanced functionalities to the ADT of the BST made with the fundamental functionalities: Visit - Description: It will display each of the data stored in the BST depending on the input parameter:Preorder Inorder Bidder Level by level Input - An integer (1-4) Exit - Nothing Precondition - A valid BST Postcondition - Nothing Height - Description:Will return the height of the BST Entry - Nothing Output - An integer with which to indicate...
1. Implement the graph ADT using the adjacency list structure. 2. Implement the graph ADT using...
1. Implement the graph ADT using the adjacency list structure. 2. Implement the graph ADT using the adjacency matrix structure. LANGUAGE IS IN JAVA Comment for any questions Data structures and algorithms
When languages allow separate compilation, the compiler must decide on the compilation order. How does the...
When languages allow separate compilation, the compiler must decide on the compilation order. How does the Java compiler make that decision?
Implement the stack ADT in a fully generic manner (through the use of templates) by means...
Implement the stack ADT in a fully generic manner (through the use of templates) by means of a singly linked list. (Give your implementation “from scratch,” without the use of any classes from the Standard Template Library ).
Overview: implement the ADT List in Java. This program is meant to the ADT List from...
Overview: implement the ADT List in Java. This program is meant to the ADT List from the ground up In the lecture, we learned how to implement an ADT like the ArrayList you have used in Project 1. With this project, you have the chance to implement an ADT called MyList, which is a simplified replacement for the full-blown ArrayList. Requirements You will implement the MyList ADT according to the following: 1. MyList must implement the List interface. It will...
Use Java programming to implement the following: Implement the following methods in the UnorderedList class for...
Use Java programming to implement the following: Implement the following methods in the UnorderedList class for managing a singly linked list that cannot contain duplicates. Default constructor Create an empty list i.e., head is null. boolean insert(int data) Insert the given data into the end of the list. If the insertion is successful, the function returns true; otherwise, returns false. boolean delete(int data) Delete the node that contains the given data from the list. If the deletion is successful, the...
Task : (Please Answer in C#) Class Polynomials The class Polynomials is a collection of polynomials...
Task : (Please Answer in C#) Class Polynomials The class Polynomials is a collection of polynomials of either implementation stored in an instance of the generic library class List. class Polynomials { private List L; // Creates an empty list L of polynomials public Polynomials ( ) { … } // Retrieves the polynomial stored at position i in L public Polynomial Retrieve (int i) { … } // Inserts polynomial p into L public void Insert (Polynomial p) {...
Implement a queue - C programming, please read the instruction carefully and implement queue.c using dynamic...
Implement a queue - C programming, please read the instruction carefully and implement queue.c using dynamic array structure given dynarray.h and dynarray.c below The second ADT you'll implement for this assignment is a queue. For this assignment, the interface for the queue (i.e. the structures and the prototypes of functions a user of the queue interacts with) is already defined for you in the file queue.h. Your first task in this assignment is to implement definitions for the functions that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT