(OOP)
1.1 Definition
Object-Oriented Programming (OOP) is a programming paradigm based
on the concept of “objects,” which represent real-world entities. These
objects contain both data (attributes) and functions (behaviors) that
operate on that data. Instead of focusing on actions and logic as in
procedural programming, OOP focuses on structuring software around
objects and their interactions.
1.2 Importance of OOP
OOP helps in creating modular, reusable, and maintainable code. It
models software similar to how humans perceive real-world systems
through objects and their interactions. This makes it easier to design
complex systems and reduces redundancy.
1.3 Key Characteristics of OOP
OOP is built around four fundamental principles:
1. Encapsulation: Bundling data and methods that operate on that data
within a single unit (class).
2. Abstraction: Showing only essential features of an object and hiding
unnecessary details.
3. Inheritance: Creating new classes from existing ones to promote
reusability.
4. Polymorphism: Using a single interface to represent different data
types or behaviors.
2. Introduction to Classes
2.1 Definition
A class is a blueprint or template that defines the structure and behavior (data and
functions) of objects. It does not occupy memory until an object is created from it.
In simple words, a class acts as a plan, and an object is the actual building
constructed from that plan.
, 2.2 Syntax of a Class in C++
class ClassName {
public:
// Data Members
int data;
// Member Function
void display() {
cout << "Value: " << data;
}
};
2.3 Explanation
Class keyword is used to define a class.
Data Members are variables that hold object data.
Member Functions are methods that define behavior.
Access Specifiers (like public, private, and protected) determine the
accessibility of class members.
Example:
#include <iostream>
using namespace std;
class Car {
public:
string brand;
int speed;
void displayInfo() {
cout << "Brand: " << brand << ", Speed: " << speed << " km/h" <<
endl;