1. Vector
Expand the Vector class that we begin writing in the lecture:
class Vector { double[] v; public Vector(params double[] v) { this.v = v; } … }
Add these elements:
a read-only property dims
that
returns the number of dimensions of the vector
a read-only property isZero
that
is true if the vector is zero
an operator + that adds two vectors
an operator *
that multiplies a
scalar times a vector, yielding a new vector
an operator
*
that computes the dot product of two vectors,
yielding a scalar
a method angle
that computes the
angle between two vectors in radians
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.
Write a class Queue
implementing a queue of integers. A queue should have an unlimited
size. The Queue
class should have
these members:
Queue
()
bool
isEmpty
()
void
enqueue
(
int
i)
int
dequeue()
bool
tryDequeue(out int i)
All operations should run in O(1).
Write a class Deque implementing a double-ended queue of integers:
Your class should have these members:
Deque
()
bool
isEmpty
()
void
enqueueFirst
(
int
i)
int
dequeueFirst()
void
enqueueLast(int i)
int dequeueLast()
All operations should run in O(1). In dequeueFirst() and dequeueLast(), you may assume that the queue is not empty.