Oops concept


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Oops concept

  1. 1. Sreyachandran.v sreya.chandran31@gmail.com www.facebook.com/sreya twitter.com/username in.linkedin.com/in/profilename OOPS CONCEPT IN C++
  2. 2. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  3. 3. Object Oriented Programming Object-oriented programming (OOP) is a programming paradigm that uses “Objects“ and their interactions to design applications and computer programs.
  4. 4. Important in oops • Object • Class • Data Abstraction • Encapsulation • Inheritance • Polymorphism
  5. 5. 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
  6. 6. •An Object is a collection of data members and associated member functions also known as methods. object Data members Model Color Start Move Stop Methods car
  7. 7. 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
  8. 8. #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
  9. 9. 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.
  10. 10. #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
  11. 11. 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……………; }
  12. 12. 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.
  13. 13. Shape class hierarchy TwoDimensionalShape Shape ThreeDimensionalShape Circle Square Triangle Sphere Cube Tetrahedron
  14. 14. 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
  15. 15. Type of inheritance • Single inheritance In this this type of inheritance one derived class inherits from only one base class. B A
  16. 16. • Multiple inheritance In this type of inheritance a single derived class may inherit from two or more base class. BA c
  17. 17. • Hierarchical Inheritance in this method multiple derived classes inherits from a single base class. B A C D
  18. 18. • 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
  19. 19. • Hybrid (virtual) inheritance it is the combination of hierarchical and multilevel inheritance. B A C D
  20. 20. 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.
  21. 21. Shape RectangleTtiangle 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
  22. 22. #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 put 20 10
  23. 23. 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.
  24. 24. 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
  25. 25. Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Cafit Square, Hilite Business Park, Near Pantheerankavu, Kozhikode Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com Contact Us