oops concept

27

Upload: baabtracom-no-1-supplier-of-quality-freshers

Post on 09-Jun-2015

241 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Oops concept
Page 2: Oops concept

Sreya [email protected]

mwww.facebook.com/sreyatwitter.com/usernamein.linkedin.com/in/

profilename

OOPS CONCEPT IN C++

Page 3: Oops concept

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

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

Important in oops

• Object• Class• Data Abstraction • Encapsulation• Inheritance• Polymorphism

Page 6: Oops concept

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

•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

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

#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

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

#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

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

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

Shape class hierarchy

TwoDimensionalShape

Shape

ThreeDimensionalShape

Circle Square Triangle Sphere Cube Tetrahedron

Page 15: Oops concept

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

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

• 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

• Hierarchical Inheritance

in this method multiple derived classes inherits from a single base class.

B

A

C D

Page 19: Oops concept

• 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

• Hybrid (virtual) inheritanceit is the combination of hierarchical and multilevel

inheritance.

B

A

C

D

Page 21: Oops concept

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

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

#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

Thank you

Page 25: Oops concept

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

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

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