O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Object Oriented Programming Concepts

593 visualizações

Publicada em

This presentation illustrates concepts of object oriented programming (OOPS) in C programming language.

Publicada em: Educação
  • Entre para ver os comentários

  • Seja a primeira pessoa a gostar disto

Object Oriented Programming Concepts

  1. 1. Object Oriented Programming Concepts C SharpC ode.org
  2. 2. OOPS Class – group of data members & member functions Like person can be class having data members height and weight and member functions as get_details() and put_details() to manipulate on detailsput_details() to manipulate on details Class is nothing until you create it’s object Object – instantiates class allocates memory C SharpC ode.org
  3. 3. OOPS Fundamentals… Access to data members & member functions can be done using object only (if they are not static!) OOPS features are 1. Encapsulation1. Encapsulation 2. Data hiding 3. Data reusability 4. Overloading (polymorphism) 5. Overriding C SharpC ode.org
  4. 4. OOPS Features… Encapsulation – making one group of data members & member functions Can be done through class Then group of data members & Member functions will beThen group of data members & Member functions will be available just by creating object. C SharpC ode.org
  5. 5. OOPS Features… Data Hiding – can be done through access modifiers Access modifiers are private, public, protected and internal Private members or member function won’t be available outside classoutside class Public – available all over in program outside class also C SharpC ode.org
  6. 6. OOPS Features… Protected – members that are available in class as well as in it’s child class Private for another class Protected access modifier comes only when inheritance isProtected access modifier comes only when inheritance is in picture Internal is used with assembly creation C SharpC ode.org
  7. 7. class employee //Class Declaration { private: char empname[50]; int empno; public: void getvalue() { cout<<"INPUT Employee Name:"; cin>>empname; cout<<"INPUT Employee Number:"; cin>>empno; } void displayvalue() {void displayvalue() { cout<<"Employee Name:"<<empname<<endl; cout<<"Employee Number:"<<empno<<endl; } }; main() { employee e1; //Creation of Object e1.getvalue(); e1.displayvalue(); } C SharpC ode.org
  8. 8. OOPS Features… Overloading – taking different output of one method or operator based on parameters and return types Like add() method performs addition and add(int a,int b) performs addition of ‘a’ and ‘b’ passed when callingperforms addition of ‘a’ and ‘b’ passed when calling Also, + operator performs addition of two numbers as well as concatenation of strings C SharpC ode.org
  9. 9. class arith { public: void calc(int num1) { cout<<"Square of a given number: " <<num1*num1 <<endl; } void calc(int num1, int num2 ) { cout<<"Product of two whole numbers: " <<num1*num2 <<endl; } };}; int main() //begin of main function { arith a; a.calc(5); a.calc(6,7); } This is example of method overloading, output will be Square of given number : 25 Product of two whole numbers : 42 C SharpC ode.org
  10. 10. OOPS Features… Data Reusability – helps in saving developers time You can use already created class to crate new one Called inheritance Already existing class is base class and new created isAlready existing class is base class and new created is derived class Base class members can be available in derived class and to access them create object of derived class Like from parent to child C SharpC ode.org
  11. 11. class CPolygon { protected: int width, height; public: void set_values (int a, int b) { width=a; height=b;} }; class CRectangle: public CPolygon { public: int area () { return (width * height); } }; class CTriangle: public CPolygon {class CTriangle: public CPolygon { public: int area () { return (width * height / 2); } }; int main () { CRectangle rect; CTriangle trgl; rect.set_values (4,5); trgl.set_values (4,5); cout << rect.area() << endl; cout << trgl.area() << endl; return 0; } C SharpC ode.org
  12. 12. OOPS Features… In C++, overriding is a concept used in inheritance which involves a base class implementation of a method. Then in a subclass, you would make another implementation of the method. This is overriding. Here is a simple example. class Base {{ public: virtual void DoSomething() {x = x + 5;} private: int x; }; class Derived : public Base { public: virtual void DoSomething() { y = y + 5; Base::DoSomething(); } private: int y; }; C SharpC ode.org