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
Write a class DynArray that represents a variable-sized array of integers, with indices starting at 0. It should have the following members:
DynArray() - create a new empty DynArray
int length() - return the current array length
void append(int i) - append an integer to the array
int get(int index) - read the integer at the given index
void set(int index, int val) - set the integer at the given index, which must be within the current array bounds
What will be the average-case big-O running time of append()?
Write a class BinaryTree that holds a binary tree of integers. Your class should have these members:
BinaryTree() - create a BinaryTree that is initially empty
void insert(int i) - insert a value into the tree if it is not already present
bool contains(int i) - return true if the tree contains the value i, otherwise false
int[] toArray() - return an array holding all the values in the binary tree, in ascending order