Download - Oops concept
![Page 1: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/1.jpg)
![Page 2: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/2.jpg)
Sreya [email protected]
mwww.facebook.com/sreyatwitter.com/usernamein.linkedin.com/in/
profilename
OOPS CONCEPT IN C++
![Page 3: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/3.jpg)
Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
![Page 4: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/4.jpg)
Object Oriented Programming
Object-oriented programming (OOP) is a programming paradigm that uses “Objects“ and their interactions to design applications and computer programs.
![Page 5: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/5.jpg)
Important in oops
• Object• Class• Data Abstraction • Encapsulation• Inheritance• Polymorphism
![Page 6: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/6.jpg)
Object
• Object is the basic unit of object-oriented programming.
• Objects are identified by its unique name.
• An object represents a particular instance of a class.
Example : Car is an object
![Page 7: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/7.jpg)
•An Object is a collection of data members and associated
member functions also known as methods.
object
Data membersModelColor
StartMoveStop
Methods
car
![Page 8: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/8.jpg)
class• Class is basically blue print for object.
• It declare and define what data variables the object will have
and what operations can be performed on the class’s object.
Class name
Data variable
Functions
Structure of class
![Page 9: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/9.jpg)
#include <iostream.h> class Square {
private: int side, a; public: int area( side) {
a =side*side; return a;
} void show()
{ cout << "The area is::" << a;
} }; void main() { Square x; //x is the object for class Square
x.area(10); x.show(); }
The area is:: 100
![Page 10: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/10.jpg)
Data abstraction
• Abstraction refers to showing only the essential features of the
application and hiding the details.
• Example : calculator
• Any C++ program where you implement a class with public
and private members is an example of data abstraction.
![Page 11: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/11.jpg)
#include <iostream>using namespace std;class Adder{ public: // constructor Adder1(int i = 0) { total = i; } // interface to outside world void addNum(int number) { total += number; } // interface to outside world int getTotal() { return total; }; private: // hidden data from outside world int total;};
int main( ){ Adder a; a.addNum(10); a.addNum(20); a.addNum(30); cout << "Total " << a.getTotal() <<endl; return 0;}
Out put
Total 60
![Page 12: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/12.jpg)
Encapsulation• Encapsulation is also known as Data Hiding.• Encapsulation is the process of combining data and function
into a single unit called class.
class class name{private:datatype data;public:Member functions;};main(){classname objectname1,objectname2……………;}
![Page 13: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/13.jpg)
Inheritance
• Inheritance is the process of forming a new class from an
existing class or base class.
• The base class is also known as parent class or super class.
• The new class that is formed is called derived class. Derived
class is also known as a child class or sub class.
![Page 14: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/14.jpg)
Shape class hierarchy
TwoDimensionalShape
Shape
ThreeDimensionalShape
Circle Square Triangle Sphere Cube Tetrahedron
![Page 15: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/15.jpg)
Implementation of inheritance
class derived-class: access-specifier base-class
•Syntax for implementing derived class
•Access Control and Inheritance
Access public protected private
Same class yes yes yes
Derived classes yes yes no
Outside classes yes no no
![Page 16: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/16.jpg)
Type of inheritance
• Single inheritanceIn this this type of inheritance one derived class
inherits from only one base class.
B
A
![Page 17: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/17.jpg)
• Multiple inheritance
In this type of inheritance a single derived class may inherit from two or more base class.
BA
c
![Page 18: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/18.jpg)
• Hierarchical Inheritance
in this method multiple derived classes inherits from a single base class.
B
A
C D
![Page 19: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/19.jpg)
• Multi Level inheritance
In this type of inheritance the derived class inherits from a class, which in turn inherits from other class.
B
C
A
![Page 20: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/20.jpg)
• Hybrid (virtual) inheritanceit is the combination of hierarchical and multilevel
inheritance.
B
A
C
D
![Page 21: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/21.jpg)
Polymorphism
• The word polymorphism means having many forms.
• C++ polymorphism means that a call to a member function
will cause a different function to be executed depending on the
type of object that invokes the function.
![Page 22: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/22.jpg)
Shape
Rectangle Ttiangle
area()
perimeter()
area()
perimeter()
area()
perimeter()
Triangle and Rectangle are child classes with their own separate implementations of the methods area() and Perimeter()
Shape is the super class with no implementation of area() and perimeter()
Example
![Page 23: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/23.jpg)
#include <iostream>using namespace std;class Polygon { protected: int width, height; public: void set_values (int a, int b) { width=a; height=b; }};class Rectangle: public Polygon { public: int area() { return width*height; }};
int main () { Rectangle rect; Triangle trgl; rect.set_values (4,5); trgl.set_values (4,5); cout << rect.area() << '\n'; cout << trgl.area() << '\n'; return 0;}
class Triangle: public Polygon { public: int area() { return width*height/2; }};
Out put2010
![Page 24: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/24.jpg)
Thank you
![Page 25: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/25.jpg)
Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many contents online?
Do you want to learn things quickly?
Tired of spending huge amount of money to become a Software professional?
Do an online course @ baabtra.com
We put industry standards to practice. Our structured, activity based courses are so designed to make a quick, good software professional out of anybody who holds a passion for coding.
![Page 26: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/26.jpg)
Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Give a feedback @ massbaab.com/baabtra
Thanks in advance
www.baabtra.com | www.massbaab.com |www.baabte.com
![Page 27: Oops concept](https://reader030.vdocument.in/reader030/viewer/2022013003/5576cac2d8b42ae3108b501a/html5/thumbnails/27.jpg)
Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550
NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550
Cafit Square,Hilite Business Park,Near Pantheerankavu,Kozhikode
Start up VillageEranakulam,Kerala, India.Email: [email protected]
Contact Us