Part I: written exercises

1. Suppose someone designed a stack abstract data type in which the function top returned an access path (or pointer) rather than returning a copy of the top element. This is not a true data abstraction. Why? Give an example that illustrates the problem.

2. Describe the three ways a client can reference a name from a namespace in C++.

3. Compare the dynamic binding of C++ and Java.

4. Compare the multiple inheritance of C++ with that provided by interfaces in Java.

5. Using the grammar in Example 3.2, show a parse tree and a leftmost derivation for each of the following statements:

A = A * (B + (C * A))

6. Consider the following grammar:

< S> -> a < S> c < B> | < A> | b
< A> -> c < A> | c
< B> -> d | < A>

Which of the following sentences are in the language generated by this grammar?

a. abcd
b. acccbd
c. acccbcc
d. acd
e. accc

Part II: programming exercise

The goal of this exercise is to use some of the object oriented features of C++ or Java.

The program is to simulate a tennis tournament, for our purposes, takes a field of 8 players and plays a series of three rounds, eliminating half the players with each round - ending with a single (winning) player.

Individual rounds operate as follows:

  • Randomly divide the remaining players into pairs.
  • Simulate a single game between each pair, using the scoring rules specified in assignment 1.
  • The winners advance to the next round, the losers are eliminated.

The user should enter the names of the 8 players, then the program should simulate each of the three rounds, printing the result of each game.

At the end of the tournament the program should print the name of the winner and the name of the second place finisher.

Your software must include appropriate classes of object for both a player and a tournament, but beyond that the design is at your discretion.

In addition, the simulation between any two players is as follows:

  • The score will start at 0/0, and will continue until someone wins the game.
  • It is assumed that either player one or player two will win a point on each play.
  • A (pseudo) random number generator will be used to determine the results of each play, with each player equally likely to win any given point.
  • After each play, the program should indicate which player won the point, the new score, and which player is serving next.
  • The program should then pause until the user strikes a key to continue play.
  • The player who won the previous point serves for the next point (randomly determine the player to serve first in the game).
  • The score is determined as follows (scores displayed as server/receiver). See http://tennis.about.com/cs/beginners/a/beginnerscore.htm
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.