Lab Assignment 5 UTA018
Lab Assignment 5 UTA018
1. Write a simple base class, then a derived class and use objects of both of them in the
main function. It will be a simple illustration of inheritance.
2. Practice protected access specifier in inheritance. In the base class declare a variable
which is protected and access it in the derived class.
3. Most of the time we use public mode of inheritance, for example class Derived:
public Base{}; Try protected and private access modifiers to understand the
difference of various modes of inheritance.
4. Various types of inheritances are as shown below. Write small C++ codes for each
inheritance type.
5. How can you use constructors and destructors in C++ inheritance? Write a program
to illustrate.
6. Implement a base class Book with attributes title, author, and price. Then, create a
derived class Textbook that inherits from Book and adds a new attribute subject.
Demonstrate how single inheritance is used to manage the data for general books
and textbooks.
7. A software company is creating a program to simulate a car's dashboard. The
dashboard needs to display speed, fuel level, and temperature. The speed is
controlled by a Speedometer class, the fuel level by a FuelGauge class, and the
temperature by a Thermometer class. Implement the three classes: Speedometer,
FuelGauge, and Thermometer, each with relevant attributes and methods. Then,
create a CarDashboard class that inherits from all three classes to display the
combined information on the dashboard. Demonstrate how multiple inheritance is
used to build this class.
8. You are tasked with creating a system for a library that tracks different types of
users. The system needs to handle general user information such as name, ID, and
contact details. There are two specific types of users: Student and Teacher. Each
type of user has additional attributes, such as grade level for students and
department for teachers. Implement a base class LibraryUser with general attributes.
Then, create two derived classes Student and Teacher that inherit from LibraryUser
and add their own specific attributes. Demonstrate how hierarchical inheritance is
applied in this scenario.
9. A logistics company needs a software system to manage its vehicle fleet. All vehicles
share common attributes like make, model, and year. Trucks have additional
attributes like load_capacity. Furthermore, refrigerated trucks have a special
attribute called temperature_control. Implement a base class Vehicle with common
attributes. Then, create a derived class Truck that adds the load_capacity attribute.
Finally, create another derived class RefrigeratedTruck that inherits from Truck and
adds the temperature_control attribute. Demonstrate how multilevel inheritance
works in this case.
10. You are developing a software system for an academic institution. The institution has
various roles like Person, Staff, and Student. A Person has general attributes like
name and address. Staff members, who are a type of Person, have additional
attributes like employee_id and department. Student, another type of Person, has
attributes like student_id and grade. Some Staff members are also Students (e.g.,
teaching assistants) and need to inherit from both classes. Implement a base class
Person with general attributes. Then, create derived classes Staff and Student that
inherit from Person and add their specific attributes. Finally, create a
TeachingAssistant class that inherits from both Staff and Student. Demonstrate how
hybrid inheritance is applied and managed in this scenario.