Inheritance and Containership
Inheritance and Containership
Inheritance and Containership
1. Assume that Circle is defined using radius and Cylinder is defined using radius and height.
Write a Circle class as base class and inherit the Cylinder class from it. Develop classes such
that user can compute the area of Circle objects and volume of Cylinder objects. Area of Circle
is pie *radius*radius, while volume of Cylinder is pie*(radius * radius)*height.
2. Explain the type conversion from basic type to class type and from class type to basic type
with proper example.
3. Explain various forms of inheritance with suitable diagrammatic illustrations. OR
Define Inheritance. Write the types of Inheritance. Explain Inheritance with example.
4. Consider a class network as shown in figure given below. The class Employee derives
information from both Account and Admin classes which in turn derive information from the
class Person. Define all the four classes and write a program to create, update and display the
information contained in Employee objects.
5. Explain Runtime polymorphism. Explain and demonstrate, how virtual function to achieve
runtime polymorphism? OR
How is Polymorphism achieved at Compile Time and Run Time?
6. WAP to convert from ton to Kg & gms and vice-versa. Create two classes for the same. Class
tons (with ton as data member) and Class kilo (with kg and gms as data members)
Use formula 1 ton = 100 kg, 1kg = 1000gms
7. Explain data conversions and its type with example.
8. Create a class time12 that store hh:mm:ss in 12 hour format along with am or pm, create
another class time24 that store time hh:mm:ss in 24 hour format. Write a Conversion function
to convert from one class object to another class object.
9. Define class employee which has fname and lname as data member. Define following:
1. Constructor for employee class with default arguments
2. Print function
Derive a class called hourly_worker (with wage and hours as data members). Define following:
1. Constructor for hourly_worker class with default arguments
2. Getpay() function that calculates and returns the pay and
3. A print function
10. Write a class Box to draw a rectangle. Derive a class NewBox to add a data member character.
Use this character and draw a particular shape instead of lines.
11. Create a class publication with title and price. Use necessary constructors, destructors and
functions. Derive two classes books (member page_count), tape(member mins). Write
necessary functions.
12. Modify above program with two base classes. One as publication and create another sales
(member totalsales). Now, Derive two classes books (member page_count), tape(member
mins) from publication and sales. Use necessary constructors, destructors and functions.
13. Define Inheritance. Explain public, private and protected inheritance with example.
14.
Student
Name, Rollno
Engineering
University
CE IT