Lab Task 7 - Inheritance
Lab Task 7 - Inheritance
Date:
Batch: BSCS F15 A
Lab 7
Objective: Inheritance
Q1: Imagine a publishing company that markets both book and audiocassette versions of its
works. Create a class publication that stores the title (a string) and price (type float)
of a publication. From this class derive two classes: book, which adds a page count (type
int), and tape, which adds a playing time in minutes (type float). Each of these three
classes should have a getdata() function to get its data from the user at the keyboard,
and a putdata() function to display its data.
Write a main() program to test the book and tape classes by creating instances of them,
asking the user to fill in data with getdata(), and then displaying the data with putdata().
Q2: The publisher in Exercises 1 decides to add a third way to distribute books: on computer
disk, for those who like to do their reading on their laptop. Add a disk class that, like book and
tape, is derived from publication. The disk class should incorporate the same member functions
as the other classes. The data item unique to this class is the disk type: either CD or DVD. You
can use an enum type to store this item. The user could select the appropriate type by typing c
or d.
This class should have a getdata() function to get its data from the user at the keyboard,
and a putdata() function to display its data.
Write a main() program to test this disk class by creating instance of this class, asking the user
to fill in data with getdata(), and then displaying the data with putdata().
Q3. Derive a class called RegularEmployee and HourlyEmploee from the Employee class sent to
you via email in previous lectures. RegularEmployee should add a type double data item called
basicSalary . HourlyEmploee should add a type double data item called hourlyRate and another
double data type item called noOfHours to calculate salary for hours worked. In both classes
add appropriate functions to take their information from user and display it as well.
Create a menu driven program that enters the information of both type of employees by
selecting choice from menu. For eg
1. Enter data
2. Display data
3. Exit
Your choice: 2
Error no data exists yet
Do you want to continue Y/N: N
Good Bye
Do you want to continue Y/N: Y
1. Enter data
2. Display data
3. Exit
Your choice: 3
Good Bye
Menu:
1. Enter data
2. Display data
3. Exit
Your choice: 1
1 Enter data for regular employee
2. Enter data hourly employee
3. Exit
Do you want to continue Y/N: Y
1. Enter data
2. Display data
3. Exit
Your choice: 2
1 Display data for regular employee
2. Display data hourly employee