Assignment _ 2
Assignment _ 2
Overload the *
operator to multiply two fractions. In the main () function, we create two Fraction objects
(f1 and f2) and perform multiplication, displaying the result.
2. Write a function calculate() that takes a pointer to an array, its size, and two pointers (sum
and average) as parameters. In the main function that creates an array of integers, initializes it
with values and calculates the sum and average of its elements using calculate() function.
After the function call, display the sum and average of the array in the main function.
3. Your task is to implement the classes Book, FictionBook and NonFictionBook using
inheritance. A base class Book represents basic book attributes like title, author, and
publication year. It also has a display method to print these attributes. Define the two derived
classes, FictionBook and NonFictionBook, inheriting from the Book class. These derived
classes add their own unique attributes (genre for fiction and topic for non-fiction) and
override the display method to include these attributes. In the main function, we create
instances of both FictionBook and NonFictionBook and call their respective display methods
to see how inheritance allows us to reuse and extend the functionality of the base class.