Assignment 3

  1. Discuss both the advantages and disadvantages of inheritance. Why is over-use of inheritance considered harmful?
  2. Summarize the major differences between Java and C++.
  3. Implement a class in Java, C++, or C#, named Rational, for reduced-form rational numbers that provides the following operations: add, sub, mul, and div.
  4. Implement a class in Java, C++, or C#, named Car, with the following behavior. A car has a certain fuel efficiency (measured in miles/gallon) and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. Supply a method 'drive' that simulates driving the car for a certain distance, reducing the fuel level in the gas tank, and methods 'getGas', to return the current fuel level, and 'addGas' to tank up.
  5. Extend the class Stack to provide a new method called reverse that reverses the elements on the stack.