0% found this document useful (0 votes)
13 views1 page

CS 200 - Lab - 7

Lab7

Uploaded by

seemarahat1122
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

CS 200 - Lab - 7

Lab7

Uploaded by

seemarahat1122
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Task 1 - Polynomials [100 Marks]

Note: For this task, you can create as many classes, constructors, destructors, setters, getters, data
variables and class methods as you wish. Make sure that all your data members are private.

In this lab, you must implement a polynomial calculator to perform polynomial arithmetic (addition,
subtraction, multiplication). You would also be implementing input, output and evaluation of the
polynomials.

What is a polynomial?
A polynomial is a collection of terms. Each term has a coefficient and an exponent.
Example:
4 2
5𝑥 + 2𝑥 + 10
Some implementation hints:
You may implement your polynomial as a dynamic array of terms. Note that each term in the polynomial
must have a unique exponent (i.e. no two terms can have the same exponent).

Overload the following operators:


1. Plus [+]: Adds the two polynomials and returns the resultant polynomial.
2. Plus-Equal [+=]: Same as above but stores the result in the first polynomial.
3. Minus [-]: Subtracts the two polynomials and returns the resultant polynomial.
4. Minus-Equal [-=]: Same as above but stores the result in the first polynomial.
5. Multiply [*]: Multiplies the two polynomials and returns the result.
6. Multiply-Equal [*=]: Same as above but stores the result in the first polynomial.
7. Assignment [=]: Self-explanatory.
8. Function-Call [()]: Evaluates the polynomial with the provided value.
9. Output-Stream [<<]: Prints the polynomial on the terminal.
10. Output-Stream [>>]: Inputs the polynomial from the user. Your program will continuously ask
users if they want to enter a new term or stop the input.
11. Comparison [==]: Returns true if the polynomials are equal, false otherwise.

Requirements:
1. You must name your polynomial class as Poly.
2. Comment on your main function before running the test file.

Assumptions:
1. The user will always input the polynomial in descending order. For example, if the user inputs
coefficient 5 and exponent 4 for the first term (which is 5x^4), you can assume the next term will
have an exponent of 3 or lower.

Examples and Syntax Help:


1. Function-Call operator(): int& operator() (int value)
2. Input Menu: Do you want to insert more terms? (1: Yes, 0: No)

You might also like