Sei sulla pagina 1di 4

EX.

No:6(a)
MULTIPLE INHERITANCE
AIM:
To write a C++ program to display N employee details for multiple inheritance concept.
Algorithm:
1. Create the base class1 as pdetail with the data members empno,name,dept as protected
and member function as getp().
2. Create the base class2 as sdetail with the data members sal as protected and member
function as getsal.
3. Derive class employee from base classes pdetail and sdetail with the member functions
getdetail() and diplay().
4. Define member function getp() to initialize the members of pdetail class.
5. Define member function getsal() to initialize the members of sdetail class.
6. Define member function getdetails() to initialize the members by calling getp(),getsal().
7. Define member function display() to print the employee details.
8. In main function create object in form of array for employee class and invoke the
functions.
OUTPUT:
Enter the number of employee:
2
Enter the employee details:
Enter name:Raja
Enter employee no:100
Enter department:IT
Enter salary:20000
Enter the employee details:
Enter name:Kannan
Enter employee no:101
Enter department:CSE
Enter salary:25000
Employee Details:
Ename Eno Edept
Raja 100
IT
Kannan 101 CSE
Result:

Esal
20000
25000

Thus the C++ program to display N employee details using multiple inheritance was
successfully executed and output was verified.
EX.No:6(b)
MULTI LEVEL INHERITANCE
AIM:
To write a C++ program to addition of 2 numbers for multilevel inheritance concept.
Algorithm:
1. Create the base class as data1.with the data member a and member function as get1().
2. Derive a class as data2 from data1 with data member as b and member function as
get2().
3. Derive a class as sum from data2 with data member as s and member function as add()
and display() .
4. Define member function get1() to read a value.
5. Define member function to read b value.
6. Define the member function add() to add the a and b value.
7. Define the member function display() to display the result.
8. In main function create object for sum class and invoke the functions.
OUTPUT:
Enter a value:
2
Enter b value:
3
a=2
b=3
sum=5
Result:
Thus the C++ program to add 2 numbers using multi level inheritance was successfully
executed and output was verified.

EX.No:7(a)
VIRTUAL FUNCTION
AIM:
To write a C++ program to addition and subtraction of 2 numbers using virtual function
Algorithm:
1. Create the base class as sum with the data member a,b and member function as get()
and virtual function calc().
2. Create the derived class as addition from the base class sum with member function
calc() .
3. Define the function get() to read the member values a,b.
4. Define virtual calc() to add the two values.
5. Define calc() to subtract the two values.
6. Create the base class object and pointer variable.
7. In main function create the object and invoke the function.
OUTPUT:
Enter the a and b values:
23
Base class - virtual function
Addition of a and b is:5
Enter the a and b values:
42
Subtraction of a and b is:2
Result:
Thus the C++ program to add and subtract two numbers using virtual function was
executed successfully and output was verified.

EX.No:7(b)
VIRTUAL BASE CLASS MULTIPATH INHERITANCE
AIM:
To write a C++ program to find area of rectangle and triangle using virtual base class.
Algorithm:
1. Create the base class as shape with data member a,b and the member function as get().
2. Create the virtually derived class as rect from the base class with member function
area1() .
3. Create the virtually derived class as tria from the base class with member function area2()
4. Create the derived class as ashape from rect and tria classes with member functions
display() to call area1() and area2().
5. In main function,create object for ashape class and call the functions get() and display().
OUTPUT:
Enter a and b value:
23
Area of the Rectangle is:6
Area of the Triangle is:3
Result:
Thus the C++ program to find area of rectangle and triangle using virtual base class was
executed successfully and output was verified.

Potrebbero piacerti anche