- Details
- Parent Category: Programming Assignments' Solutions
We Helped With This C# Programming Homework: Have A Similar One?
Short Assignment Requirements
Assignment Description
Chapter 6 Test – Using methods in C#
Create a class Polynomial, with fields that hold a :
- a number representing the degree
- an array holding the coefficients;
Ex: 2x3 + 5x2 – 3x + 5
Will be saved in the a boject as IntDegree = 3 //highest exponent is 3
InCoefficient[0] = 5 //the coefficient for x0 is 5
InCoefficient[1] = -3 //the coefficient for x1 is -3 InCoefficient[2] = 5 //the coefficient for x2 is 5
InCoefficient[3] = 2 //the coefficient for x3 is 2
Your class will:
a) Create 2 properties for the fields: IntDegree and IntCoefficient (this last oen is an array)
b) Is your option if you set a limit to the degree or accept any degree;
c) Create 3 constructors:
o one takes no parameter. Will create the polynomial “0”
o one takes only 1 parameter, the degree. Ex Polynomial(3) will create the polynomial: “x3”
o one takes 2 parameters: one degree and an array of integers. The length of the array must match with the degree. Ex the degree is 3, then the array must have 4 numbers for the 4 coefficients like in the example above
d) Add an operator +() that adds 2 polynomials (Ex: (2x3 + 5x2 – 3x + 5) + (x3) = 3x3 + 5x2 – 3x + 5)
e) Create a ToString() method that returns a string that represents the polynomial. Ex: x3 + 1 will be returned as “x^3 + 1”
f) Implement the IComparable interface, so that you can use the Array.Sort() method on polynomials (use the following condition: a polynomial is bigger than another polynomial if the degree is higher than the degree of the 2nd polynomial)
Hint: The polynomial “x3” will be stored as follows:
IntDegree = 3
InCoefficient[0] = 0 //the coefficient for x0 is 0
InCoefficient[1] = 0 //the coefficient for x1 is 0 InCoefficient[2] = 0 //the coefficient for x2 is 0
InCoefficient[3] = 1 //the coefficient for x3 is 1
Testing your data
Create your own code to test the problem above.
The entire program will be saved as PolynomialDemo.cs.