0% found this document useful (0 votes)
4 views

oop prac4 inheritanceandpolymorphism

The document contains a lab report on Object-Oriented Programming (OOP) focusing on inheritance and polymorphism. It includes code examples demonstrating inheritance through shape classes (Square, Circle, Triangle) and polymorphism via function overloading and overriding. Each code section is accompanied by its expected output, showcasing the functionality of the implemented concepts.

Uploaded by

dhageatharv06
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

oop prac4 inheritanceandpolymorphism

The document contains a lab report on Object-Oriented Programming (OOP) focusing on inheritance and polymorphism. It includes code examples demonstrating inheritance through shape classes (Square, Circle, Triangle) and polymorphism via function overloading and overriding. Each code section is accompanied by its expected output, showcasing the functionality of the implemented concepts.

Uploaded by

dhageatharv06
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Shri Vile Parle Kelavani Mandal's

INSTITUTE OF TECHNOLOGY
DHULE (M.S.)
DEPARMENT OF COMPUTER ENGINEERING
Remark
Subject : OOP lab

Name : Dhage Atharv Vijaykumar Roll No. : 30

Class :S.Y. Computer Batch : S2 Division: B


Signature
Expt. No. :04 Date :

Title : Programs on Inheritance and Polymorphism

code : 1.Inheritance using Block diagram

SHAPES

SQUARE CIRCLE TRIANGLE

Block diagram

#include <iostream>

using namespace std;

class shape
{
public:
void showshape()
{
cout<<"\n \nshape -";
}
};

class circle:public shape


{
public:
void show()
{showshape();
cout<<"\n Circle";

}
};

class square:public shape


{
public:
void show()
{showshape();
cout<<"\n square";

}
};

class triangle:public shape


{
public:
void show()
{showshape();
cout<<"\n triangle";

}
};

int main ()
{
square s1;
circle c1;
triangle t1;

s1.show();

c1.show();

t1.show();

return 0;
}

Output:

shape -
square

shape -
Circle

shape -
triangle

code : 2.Polymorphism (function overloading)

#include <iostream>
using namespace std;

class A
{
protected:
int x;
int a,b;

public:
void show()
{
cout<<"\n Polymorphism";
}
void show(int x)
{
cout<<"\n Also know as function overloding";
}
void show(int a,int b)
{
cout<<"\n Addition A+B is = "<<a+b;
}
};

int main ()
{
A a1;
a1.show();
a1.show(3);
a1.show(10,20);
return 0;
}

Output:

Polymorphism
Also know as function overloding
Addition A+B is = 30

code : 3.Polymorphism (function overriding)

#include <iostream>

using namespace std;

class A
{
protected:
int a=10;

public:
void show()
{
cout<<" Printing A : "<<a;
}
};
class B:public A
{
protected:
int b=20;
public:
void show()
{
cout<<"\n Printing B : "<<b;
}
};
class C:public B
{
private:
int c=30;
public:
void show()
{
cout<<"\n Printing C : "<<c;
}
};

int main()
{
A a1;
B b1;
C c1;

a1.show();
b1.show();
c1.show();

return 0;
}

Output:

Printing A : 10
Printing B : 20
Printing C : 30

You might also like