1. Consider the dynamic array class (DynArray) we saw in the lecture. Write a subclass RobustArray that is like DynArray, except that
retrieving any element past the end of the array will return 0 rather than crashing;
setting any element past the end of the array will automatically extend the array length as needed.
(You will need to change a member of DynArray to be virtual.)
2. Consider the LinkedStack class we saw in the lecture. Write a subclass UniqueStack that is like LinkedStack, except that it will ignore any attempt to push the same value that is currently at the top of the stack.
3. Consider the Expression class we saw in the tutorial. Add a ToString() method.
4. Add a method numOps() to the Expression class that returns the total number of operations in a expression.
5. Add a method depth() to the Expression class that returns the depth of an expression. For example:
the depth of "4" is 0
the depth of "(2 + 4)" is 1
the depth of "((2 + 3) * (4 – 2))" is 2
6. Add a method allOps() to the Expression class that returns a string listing all the operations that occur at least once in an expression. For example, for the expression "((2 + 3) * (3 * 4))", allOps() will return "+*".
7. Write a class that holds a linked list of integers and has public methods supporting the following operations. Implement all methods recursively: you may not use any looping statements (e.g. while, for) anywhere in your implementation.
prepend an integer to the list
append an integer to the list
delete the Nth integer
insert an integer at position N
delete all odd integers
delete every other element, starting with the second
8. Write a class that represents a game of Tic-tac-toe. The class should have the following public members:
public int this[int x, int y]; public int turn { get; } public bool move(int x, int y, out bool win);
The indexer takes two values representing a board position, and should return
0 = the square is empty
1 = player 1 has played here
2 = player 2 has played here
The turn
property returns an integer indicating whose
turn it is. Player 1 moves first.
The move
() method causes the current player to move
at (x, y). The method returns true if the move is legal. It sets the
out parameter win
to true if the player wins the game.
9. Write a text-based user interface for the Tic-tac-toe game from the previous exercise. Your program should draw the board with an X for player 1, an O for player 2 and the numbers 1 through 9 for empty squares. Each player in turn should type a number from 1 through 9 to move at that position. The program should exit when either player has won.