Up: Unit 08
Previous: Inheritance or composition? (optional)
Exercise 08.1 Extend the class Book (Exercise 3.1), by defining other
classes:
- for textbooks, where we can specify also the course to which they refer;
- for textbooks of the Free University of Bolzano, where we can specify
also the faculty for which the book has been chosen;
- for novels, where we can specify also the type.
For each of the above classes, define the constructor and suitably redefine the
method for the visualization of the object. Describe the hierarchy of classes.
Exercise 08.2 Write an example program for the classes defined in Exercise 8.1,
that realizes the following operations.
- for a first book, read the title, the authors, the course, and the
faculty adopting it, and store this information in an object;
- show the information about the first book;
- for a second book, read the title and the authors, and store them in a
suitable object;
- read the topic of the second book, and create a third object of type
novel;
- show the information about the two objects used to create the second
book;
- read the price of the first book and update the corresponding object
accordingly;
- show the information about the first book, including the price.
Up: Unit 08
Previous: Inheritance or composition? (optional)