Assignment No.4 (Inheritance)
Assignment No.4 (Inheritance)
Assignment #4
Due Date: Saturday December 23, 2023 9:00 am
Instructor: Dr. Javid (16-12-2023)
Note: The deadline is hard, late submission and copied solutions will
credit zero marks. The Demos of this assignment will be conducted on 23th
December, 2023 in the Lab class. (Comment your program properly, write
down your Name, Registration No. at the top of .cpp file as comment. Take
care of indentation when writing program).
Task-1
Design a class named Person and its two derived classes named Student and Teacher.
The Person class has:
Attributes i.e. name, age, phone number, and e-mail address
Behaviors (Method/function ) i.e. work something.
Default as well as parameterized constructor
Then Student class is derived from the Person class. The Student class has
Attributes i.e. registration ID, department, number of completed credit hours
Behavior (Method/function ) i.e. pay course registration fee
Default and parameterized constructors
The Teacher class is derived from The Person as well and it additionally contains the
following:
Attributes i.e. staff ID, salary
Behavior (Method/function ) i.e. teach course(s)
Default and parameterized constructors
Additionally each class should have its own input()/setter() and display/getter() as well.
In the main() function make 2 objects of each class i.e. Person, Student and Teacher and
call the corresponding functions/methods. One object should be created using default
constructor, while the second object should be created using parameterized constructor.
Also call all the functions using derived classes objects. What type of inheritance is this?
Task-2
Imagine a publishing company that markets both book and audiocassette versions of its work.
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 page count (type int) and author (a string);
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 keyboard, and a putData() function to
display its data.
Add a member function having return type bool called isOversize() to the book and tape classes.
Let’s say that a book with more than 800 pages, or a tape with a playing time longer than 90
minutes (which would require two cassettes), is considered oversize. You can access this function
from main() and display the string “Oversize” for oversize books and tapes when you display
their other 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(). The
getData()and putData()of Publication should have protected access specifier. Mention proper
accessor and mutator as well.
Task-3
Write down programs explaining the types of inheritance. Write down simple classes
having only one function (display()), constructor(s). There should be 5 programs,
defining each type of inheritance. Comment program properly.