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 - a property returning
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
an indexer that retrieves any coefficient of
the polynomial. If p is a Polynomial, then p[0] will
return the lowest-order coefficient.
a method that evaluates a polynomial for a given value of x
a method that returns the first derivative of a polynomial
a method asString() 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 Time that represents a
time of day with hours, minutes, and seconds. Your class should have
the following members:
a constructor Time(int h, int m, int s)
that builds the time h:m:s
properties int hours, int
minutes and int seconds that retrieve the
components of a Time
an overloaded operator that adds a Time
and an integer number of seconds, producing a new Time
object. The time may wrap past midnight. For example, if t is the
time 23:59:59, then t + 2 should produce the time 0:00:01.
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.