Assignment 5

Due date: Nov 12 before class

Techniques: Operator overloading and multiple inheritance

(1) Implement a class Fraction.
A fraction is a number of the form 3/4 or 6/23 or ...
Overload the arithmetic operators + - to handle this class fractions. Also overload the input/output operators >> and <<
So something like cout << fr should output the value of the fraction and NOT the address of the object.

NOTE: Please take into account that 4/4 = 1. So the numerator is 1 and the denominator is 1. In such a case, do not output 1/1 but only 1.

Also if you wish, you may print the float value. So 3/4 is 0.75.

 

 (2) Now a small assignment with multiple inheritance.

Consider the four classes

  1. Window
  2. Window_with_borders
  3. Window_with_menu
  4. Window_menu_borders

Now relate these four classes using multiple inheritance.

Also all the classes must have one function called draw().

  1. Window::draw() does nothing.
  2. Window_with_borders::draw() just outputs four co-ordinates on the screen. ( Can be some random numbers assigned to the member variables).
  3. Window_with_menu::draw() outputs some arbitrary menu functions like HELP, SAVE etc.
  4. Window_menu_borders::draw() calls the functions of (2) and (3). Call the functions EXPLICITLY – DO NOT hardcode the statements into this function.

You may use virtual functions as well as virtual inheritance for this assignment. No user interaction is necessary. Please use constructors and call the base constructors from the derived.

The purpose of this assignment is to get you familiar with multiple inheritance so you can pass the border co-ordinates in the Window_with_borders constructors or something as easy.