0% found this document useful (0 votes)
61 views85 pages

C++PPT - Unit - I - 2022-23

Uploaded by

ravijack025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views85 pages

C++PPT - Unit - I - 2022-23

Uploaded by

ravijack025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 85

OBJECT ORIENTED PROGRAMMING

CONCEPTS USING C++


(SU22A)

UNIT - I

PREPARED BY
S. LAKSHMI, DEPT. OF COMPUTER APPLICATIONS
INTRODUCTION TO C++
 It
was created by Bjarne Stroustrup at Bell Labs in
1983

 It was originally named C with Classes

 C++ is widely used in the software industry

 Some of its application domains include systems

software, application software, device drivers,


embedded software, high-performance server and
client applications, and entertainment software
such as video games.
DIFFERENCE BETWEEN C AND C++

 C is procedure oriented language, C++ is Object


Oriented Language

 C++ can support of all function of C, but C can't


support of all function of C++

 C++ follows bottom up approach, but C follows


Top down approach.

 Data can move in C openly around in the system


from function to function. In C++ data is hidden
can't be accessed by external function.
OOPS CONCEPT
 OOPS stands for Object Oriented Programming

 OOP is a programming paradigm that uses


"objects" – data structures consisting of data
fields and methods together with their
interactions – to design applications and
computer programs

 The major motivating factor in the invention of


OOP approach is to remove some of the flaws
encountered in the procedural approach
OBJECTS

CLASSES

DATA ABSTRACTION

DATA ENCAPSULATION

INHERITANCE

POLYMORPHISM

DYNAMIC BINDING

MESSAGE PASSING
OBJECTS &
CLASSES
 Objects are the basic run time entities

 It may also represent user-defined data such as


vectors, time and lists

 The entire set of data and code of an object can be


made a user defined data type with the help of a class

 Objects are variable of the type class

 we can create any number of objects belonging to that


class

 A class is thus a collection of objects of similar type


 C++ is an object-oriented programming language.

 Everything in C++ is associated with classes and objects,


along with its attributes and methods. For example: in real
life, a car is an object. The car has attributes, such as
weight and color, and methods, such as drive and brake.

 Attributes and methods are


basically variables and functions that belongs to the class.
These are often referred to as "class members".

 A class is a user-defined data type that we can use in our


program, and it works as an object constructor, or a
"blueprint" for creating objects.
CLASS SPECIFICATION

A class specification has two parts:

 Class declaration
 Class function definitions

class class_name
{
private:
variable declarations;
Function declarations;
public:
variable declarations;
Function declarations;
};
DEFINING MEMBER FUNCTIONS
Member of function can be defined in two places:
Outside the class definition
Inside the class definition
Outside:
return – type class-name :: function-name (argument
declaration)
{
Function body
}
Example:
void item :: getdata(int a, float b)
{
number = a;
cost = b;
INSIDE THE CLASS
DEFINITION
class Item
{
int number;
float cost;
public:
void getdata(int a,float b); //declaration
//inline function
void putdata(void) // definition inside the class
{
cout<<number << “\n”;
cout<<cost << “\n”;
}
};
#include<iostream.h>
class MyClass
{ // The class
public: // Access specifier
int myNum; // Attribute (int variable)
string myString; // Attribute (string variable)
};

int main()
{
MyClass myObj; // Create an object of MyClass

// Access attributes and set values


myObj.myNum = 15;
myObj.myString = "Some text";

// Print attribute values


cout << myObj.myNum << "\n";
cout << myObj.myString;
return 0;
}
ENCAPSULATION & DATA ABSTRACTION

 The wrapping up of data and functions into a single


unit is known as encapsulation.

 Abstraction refers to the act of representing essential


features without including the background details or
explanations

 Classes use the concept of abstraction and are defined


as a list of abstract attributes such as size, weight
and cost, and functions to operate on these attributes
#include<iostream.h>
class Summation
{
private:
// private variables
int a, b, c;
public:
void sum(int x, int y)
{
a = x;
b = y;
c = a + b;
cout<<"Sum of the two number is : "<<c<<endl;
}
};
int main()
{
Summation s;
s.sum(5, 4);
return 0;
}
INHERITANC
E
 The mechanism of deriving a new class from an old
one is called inheritance

 Inheritance is the process by which objects of one class


acquire the properties of objects of another class

 There are five types of Inheritance


1. Single Inheritance
2. Multiple Inheritance
3. Multilevel Inheritance
4. Hierarchical Inheritance
5. Hybrid Inheritance.
POLYMORPHISM

 Polymorphism means the ability to take more than


one form.

 An Operation may exhibit different behaviors in


different instances.

 There are two types of Polymorphism


1. Runtime Polymorphism.
Example: Function Overriding.

2. Compiletime Polymorphism.
Example: Function Overloading,
Operator Overloading
DYNAMIC
BINDING
 Its also known as late binding

 The code associated with a given procedure call is


not known until the time of the call at run time

 It is associated with polymorphism and inheritance

 In static binding the function definition and


function call are linked during the compile-time
whereas in dynamic binding the function calls are
not resolved until runtime. So they are not bound
until runtime.
Static Binding (Early Binding) – Compile-time

Dynamic Binding (Late Binding) - Runtime


MESSAGE PASSING

 Creating classes that define objects and their


behavior

 Creating objects from class definitions

 Establishing communication among objects


C++ DATA TYPES

USER-DEFINED TYPE BUILT IN TYPE DERIVED TYPE


structure Array
union Function
class Pointer
enumeration

INTEGRAL TYPE VOID FLOATING TYPE

int char float double


KEYWORDS

private virtual throw catch


protected friend new class
public try this delete template
operator inline
OPERATOR
S
 C++ has a rich set of operators

 All C operators are valid in C++

:: scope resolution operator


::* Pointer-to-member declarator
->* Pointer-to-member operator
.* Pointer to member operator
delete memory release operator
endl line feed operator
new memory allocation operator
setw field width operator
ARITHMETIC OPERATOR
RELATIONAL OPERATOR
LOGICAL OPERATOR
ASSIGNMENT OPERATOR
EXPRESSION
MANIPULATORS
CONTROL STRUCTURES

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy