Consider this class:
enum Suit { Clubs, Diamonds, Hearts, Spades }; class Card { public int rank; // 1 = Ace, 2 .. 10, 11 = Jack, 12 = Queen, 13 = King public Suit suit; public Card(int rank, Suit suit) { this.rank = rank; this.suit = suit; }
}
a) Add a method string describe()
that returns a string description such as "7 of Diamonds
"
or "Jack of Hearts
".
b) Write a class Deck with these members:
Deck() - return a new deck of 52 cards
Card[] deal(int n) – return an array of n cards randomly chosen from the remaining cards in the Deck, and remove them from the deck. If fewer than n cards remain, return null.
int count() - return the number of cards currently remaining in the deck
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.
a property degree
that returns
the degree of a polynomial. For example, the polynomial above has
degree 2.
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 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 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.
Write a class SIDict that represents a dictionary from strings to integers. It should have the following members:
SIDict() - create an empty SIDict
an indexer that allows the user to get or set values by index
For example, your class could be used as follows:
SIDict d = new SIDict() d["red"] = 4 d["blue"] = 5 d["red"] += 1 WriteLine(d["red"])
Use a linked list of key-value pairs.