What will this program print?
class MyException : Exception { } static class Test { static int foo(int i) { try { WriteLine("a " + i); if (i == 0) throw new MyException(); WriteLine("b " + i); return foo(i - 1); } catch (MyException e) { WriteLine("c " + i); if (i < 2) throw e; return i; } finally { WriteLine("d " + i); } } static void Main(string[] args) { WriteLine("e " + foo(3)); } }
Design and implement a C# class Polynomial
representing a polynomial of a single variable. Your class should
include the following:
a constructor that takes a variable number of arguments of
type double
, yielding a polynomial with those
coefficients. For example,
new Polynomial(1.0, 4.0, 5.0)
should yield the polynomial x2 + 4x + 5.
an overloaded operator +
that adds two
polynomials
an overloaded operator - that subtracts two polynomials
an overloaded operator * that multiplies two polynomials, or a polynomial and a scalar
a method that evaluates a polynomial for a given value of x
a method that returns the first derivative of a polynomial
a method that finds an approximate zero of a polynomial, i.e. a value x for which the polynomial evaluates to zero
a ToString()
method that yields a string such as
"x^2 + 4x + 5"
a static method Parse()
that parses a string
such as "x^2 + 4x + 5", yielding a polynomial. Throw a
ParseException
if you cannot parse the string.