Object-Oriented
Programming in C+
+
Concepts, Syntax, and Examples
Presented by: Group 3
Department of Computer Science and Engineering
(IoT)
Government Engineering College Vaishali
Introduction to OOPS
● OOP stands for Object-
Oriented Programming.
● It focuses on objects and
classes, encapsulating both
data and behavior.
● It promotes code reusability,
scalability, and modularity.
● For example, think of a car (an
object) that has attributes such
as color and model, along with
methods like drive() and
brake().
OOPS vs PPL
Feature
POP (Procedure-Oriented
Programming)
OOP (Object-Oriented
Programming)
Basic Approach
Focuses on functions and
procedures
Focuses on objects and classes
Code Structure Divided into functions Divided into classes and objects
Data Access
Global data shared by all
functions
Encapsulation restricts direct
access to data
Security
Less secure, data is freely
accessible
More secure, access control via
access modifiers
Reusability Limited function reuse
High reuse via inheritance and
polymorphism
Modularity
Difficult to manage in large
projects
Promotes modular and
maintainable code
Example Languages C, Pascal, Fortran C++, Java, Python, C#
Real-world Mapping Difficult Maps well to real-world entities
Suitability Small, simple programs Large, complex software systems
4 Pillars of OOPS
● 1. Encapsulation: Bundling data and
methods.
● 2. Abstraction: Hiding internal details,
exposing only functionality.
● 3. Inheritance: Acquiring properties of
a parent class.
● 4. Polymorphism: Many forms —
method overloading & overriding.
Class and Object
• Class is a blueprint for creating objects.
• Object is an instance of a class.
Example:
class Car {
public:
string brand;
void start() { cout << "Car started"; }
};
Void main(){
Car myCar;
myCar.start();
}
Encapsulation
• Keeps data safe from outside interference and
misuse.
• Achieved using access specifiers: private,
protected, public.
Example:
class Student {
private:
int age;
public:
void setAge(int a) { age = a; }
int getAge() { return age; }
Abstraction
• Only essential details are shown to the user.
• Implemented using abstract classes and
interfaces.
Example:
class Shape {
public:
virtual void draw() = 0;
};
class Circle : public Shape {
void draw() { cout << "Circle"; }
};
Inheritance
• Inherits attributes and methods from another
class.
• Promotes reusability.
Example:
class Animal {
public:
void eat() { cout << "Eating"; }
};
class Dog : public Animal {
void bark() { cout << "Barking"; }
};
Types of Inheritance in C+
+
• Single: One base class, one derived.
• Multiple: Multiple base classes, one derived.
• Multilevel: Derived class is the base of another class.
• Hierarchical: Multiple derived classes from one base.
• Hybrid: Combination of above types.
Polymorphism
• Polymorphism = Many forms.
• Compile-time: Function
Overloading
• Run-time: Function Overriding
with virtual functions
• Helps in achieving interface
flexibility.
Function Overloading
● Same function name with different parameter
lists.
Example:
int add(int a, int b);
double add(double a, double b);
string add(string a, string b);
Function Overriding &
Virtual Functions
• Base class method redefined in derived class.
• Mark base class method with virtual keyword.
• Supports dynamic dispatch.
Example:
class Base {
virtual void display();
};
class Derived : public Base {
void display();
};
Constructors and
Destructors
• Constructor initializes object state.
• Types: Default, Parameterized, Copy
constructor.
• Destructor cleans up resources.
~ClassName() gets called automatically.
Operator Overloading
• Redefines the meaning of an operator for user-
defined types.
• Makes code intuitive for custom objects.
Example:
Complex operator + (Complex c);
Use: c3 = c1 + c2;
Friend Functions & Classes
• Friend functions access
private/protected members.
• Declared with 'friend' keyword
inside class.
● Example:
friend void display(Student
s);
• Used when two classes need to
share data.
Dynamic Memory & this
Pointer
• 'new' allocates memory dynamically.
• 'delete' deallocates it.
• 'this' is a pointer to the current class instance.
● Useful in method chaining and disambiguation.
OOPs in Real-world
Projects
• GUI frameworks (Qt, GTK+)
• Game engines (Unreal Engine,
Unity C++)
• Simulation & Modelling tools
• Database Engines, OS Kernels
Conclusion & Q/A
● OOP is a powerful paradigm for software
design.
● Mastering OOP improves code quality
and scalability.
●Tips : Practice with real world projects
(e.g., Banking management System,
Library Management System,Rock Paper
Scissor Game etc.)
THANK YOU !!

OOP_in_CPP_Animesh_Animated_Diagram.pptx

  • 1.
    Object-Oriented Programming in C+ + Concepts,Syntax, and Examples Presented by: Group 3 Department of Computer Science and Engineering (IoT) Government Engineering College Vaishali
  • 2.
    Introduction to OOPS ●OOP stands for Object- Oriented Programming. ● It focuses on objects and classes, encapsulating both data and behavior. ● It promotes code reusability, scalability, and modularity. ● For example, think of a car (an object) that has attributes such as color and model, along with methods like drive() and brake().
  • 3.
    OOPS vs PPL Feature POP(Procedure-Oriented Programming) OOP (Object-Oriented Programming) Basic Approach Focuses on functions and procedures Focuses on objects and classes Code Structure Divided into functions Divided into classes and objects Data Access Global data shared by all functions Encapsulation restricts direct access to data Security Less secure, data is freely accessible More secure, access control via access modifiers Reusability Limited function reuse High reuse via inheritance and polymorphism Modularity Difficult to manage in large projects Promotes modular and maintainable code Example Languages C, Pascal, Fortran C++, Java, Python, C# Real-world Mapping Difficult Maps well to real-world entities Suitability Small, simple programs Large, complex software systems
  • 4.
    4 Pillars ofOOPS ● 1. Encapsulation: Bundling data and methods. ● 2. Abstraction: Hiding internal details, exposing only functionality. ● 3. Inheritance: Acquiring properties of a parent class. ● 4. Polymorphism: Many forms — method overloading & overriding.
  • 5.
    Class and Object •Class is a blueprint for creating objects. • Object is an instance of a class. Example: class Car { public: string brand; void start() { cout << "Car started"; } }; Void main(){ Car myCar; myCar.start(); }
  • 6.
    Encapsulation • Keeps datasafe from outside interference and misuse. • Achieved using access specifiers: private, protected, public. Example: class Student { private: int age; public: void setAge(int a) { age = a; } int getAge() { return age; }
  • 7.
    Abstraction • Only essentialdetails are shown to the user. • Implemented using abstract classes and interfaces. Example: class Shape { public: virtual void draw() = 0; }; class Circle : public Shape { void draw() { cout << "Circle"; } };
  • 8.
    Inheritance • Inherits attributesand methods from another class. • Promotes reusability. Example: class Animal { public: void eat() { cout << "Eating"; } }; class Dog : public Animal { void bark() { cout << "Barking"; } };
  • 9.
    Types of Inheritancein C+ + • Single: One base class, one derived. • Multiple: Multiple base classes, one derived. • Multilevel: Derived class is the base of another class. • Hierarchical: Multiple derived classes from one base. • Hybrid: Combination of above types.
  • 10.
    Polymorphism • Polymorphism =Many forms. • Compile-time: Function Overloading • Run-time: Function Overriding with virtual functions • Helps in achieving interface flexibility.
  • 11.
    Function Overloading ● Samefunction name with different parameter lists. Example: int add(int a, int b); double add(double a, double b); string add(string a, string b);
  • 12.
    Function Overriding & VirtualFunctions • Base class method redefined in derived class. • Mark base class method with virtual keyword. • Supports dynamic dispatch. Example: class Base { virtual void display(); }; class Derived : public Base { void display(); };
  • 13.
    Constructors and Destructors • Constructorinitializes object state. • Types: Default, Parameterized, Copy constructor. • Destructor cleans up resources. ~ClassName() gets called automatically.
  • 14.
    Operator Overloading • Redefinesthe meaning of an operator for user- defined types. • Makes code intuitive for custom objects. Example: Complex operator + (Complex c); Use: c3 = c1 + c2;
  • 15.
    Friend Functions &Classes • Friend functions access private/protected members. • Declared with 'friend' keyword inside class. ● Example: friend void display(Student s); • Used when two classes need to share data.
  • 16.
    Dynamic Memory &this Pointer • 'new' allocates memory dynamically. • 'delete' deallocates it. • 'this' is a pointer to the current class instance. ● Useful in method chaining and disambiguation.
  • 17.
    OOPs in Real-world Projects •GUI frameworks (Qt, GTK+) • Game engines (Unreal Engine, Unity C++) • Simulation & Modelling tools • Database Engines, OS Kernels
  • 18.
    Conclusion & Q/A ●OOP is a powerful paradigm for software design. ● Mastering OOP improves code quality and scalability. ●Tips : Practice with real world projects (e.g., Banking management System, Library Management System,Rock Paper Scissor Game etc.)
  • 19.