Advertisement
FemalEngineer

Helpppp C#

Nov 7th, 2012
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1.  
  2. Read the following code and then implement a code for each of the following parts:
  3.  
  4. public abstract class Polyn {
  5.  
  6. protected double[] coefficients = null;
  7.  
  8. public Polyn( double[] coefficients)
  9. {
  10. this.coefficients=new double[coefficients.Length];}
  11.  
  12. public abstract void Plot();
  13. }
  14. 1.
  15. Derive a class from Polyn and call it polynomial, the new class will contain a constructor that will assign the coefficients values provided as an argument (array) to the polynomial coefficients. Note that the first element in the array represents the coefficient of the constant term and the second element represents the coefficient of the term X and so on.
  16.  
  17. 2. Override the method ToString() and make it return a representation of a polynomial in the following format (example: 4X^3+X^2+2 ) if invoked on an object of type polynomial.
  18.  
  19. 3. Overload the operator (-) so that we can use it with objects of type polynomial, the subtraction of two polynomials is performed by subtracting the respective coefficients to each other. (note that the two polynomials may be of different order)
  20.  
  21. 4. Override the Equals method in the polynomial class (make sure no exceptions are thrown).
  22.  
  23. 5. Override the GetHashCode method in the polynomial class, make sure that it returns almost a unique value for each polynomial and it is consistent with the Equals method.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement