Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Help! Special Grading Considerations: If your code doesn't compile or if you use (non-constant) global variables, the best you can do is a C.

C++ Help!

Special Grading Considerations: If your code doesn't compile or if you use (non-constant) global variables, the best you can do is a C.

You will process a file that contains a sequence of strings representing polynomial arithmetic. Each line of the file will consist of a string that contains two polynomials that are to be added or multiplied. Each polynomial will be contained in parentheses and they will be separated by the appropriate operator. For example,

(1*x+2*x^3-1*x+7)+(1+1*x^2-1*x+1*x^4)

or

(1*x+2*x^3-1*x+7)*(1+1*x^2-1*x+1*x^4)

Facts about the input string:

The string will contain no spaces.

The terms may not be in order of degree.

A term with coefficient 1 will have the 1 present.

The coefficients will always be integers.

Zero will never appear as a coefficient.

Each file will contain some unspecified number of strings (one per line) that meet the above criteria. The program should read in each problem as a whole and then break it into two polynomials. The terms of the operands may be stored in the order they are specified. After the appropriate operation is performed, the polynomial must be sorted from highest degree to smallest and displayed to the console. If you would like to be eligible for full credit, the display must look like a typical polynomial:

5 3 3x + x - 12x + 7

You may opt to output in the format of the input

3*x^5+x^3-12*x+7

but that will cap your grade at 90.

A polynomial will be a dynamically allocated two dimensional arrays where each row represents a monomial and each row has two columns: the first is the exponent and the second is the coefficient. That is, a polynomial will be declared as

int ** polynomial;

You should define a function per operation; i.e.

int** add(int **left, int **right) int** mutliply(int **left, int **right)

and have another operation that parses a string to extract one polynomial:

int** getPolynomial(string polynomial)

Get familiar with the string (Links to an external site.) class and the string (Links to an external site.) library. They will be helpful in solving this problem.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions

Question

What did they do? What did they say?

Answered: 1 week ago