Object Oriented Programming Concepts

246paa 778 views 12 slides Sep 07, 2015
Slide 1
Slide 1 of 12
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12

About This Presentation

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


Slide Content

Object Oriented Programming Concepts

+ Class - group of data members & member functions

+ Like person can be class having data members height and
weight and member functionsas get_details() and

put_details() to manipulate on details

+ Class is nothing until you create it's object
+ Object - instantiates class allocates memory

OOPS Fundamentals...

+ Access to data members & member functions can be done
using object only (if they are not static!)

+ OOPS features are

Encapsulation

Data hiding

Data reusability

Overloading (polymorphism)
Overriding

OOPS Features...

+ Encapsulation - making one group of data members €
member functions

+ Can be done through class

° Then group of data members & Member functions will be
available just by creating object.

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 class

° Public - available all over in program outside class also

OOPS Features...

+ Protected - members that are available in class as well as in
it’s child class

+ Private for another class

e Protected access modifier comes only when inheritance is
in picture

e Internal is used with assembly creation

private:
char empname[50];
int empno;
public:
void getvalue() {
cout<<"INPUT Employee Name:";
cin>>empname;
cout<<"INPUT Employee Number:";
cin>>empno; }

void displayvalue() {
cout<<"Employee Name:"<<empname<<endl;
cout<<"Employee Number:"<<empno<<endl;

employee ex; //Creation of Object
eı.getvalue();
eı.displayvalue();

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 calling

° Also, + operator performs addition of two numbers as well
as concatenation of strings

public:

void calc(int numı)

cout<<"Square of a given number: " <<numi*num1 <<endl;

)

void calc(int numa, int numa )

cout<<"Product of two whole numbers: "<<numı*numz2 <<endl;

)
int main() //begin of main function
arith a;

a.calc(5);
an

This is example of method overloading, output will be
Square of given number : 25
Product of two whole numbers : 42

OOPS Features...

+ Data Reusability - helps in saving developers time
e You can use already created class to crate new one
+ Called inheritance

e Already 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

e Like from parent to child

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); }
b

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;

OOPS Features...

+ In C++, overriding is a conce

implementation of a method.

+ Then ina subclass, you woul:

pt used in inheritance which involves a base class

d make another implementation of the method. This is

overriding. Here is a simple example.

class Base

public:

virtual void DoSomet!
private:

intx;

class Derived : public Base

public:

virtual void DoSometl
private:

int y;

hing() (x=x + 5;)

hing() { y = y + 5; Base::DoSomething(); }