Unit I: Principles of Object-Oriented Programming
1.1 Procedure-Oriented Programming (POP) vs Object-Oriented Programming (OOP)
-----------------------------------------------------------------------------
| Aspect | POP | OOP |
|---------------------|------------------------------|------------------------------|
| Approach | Focuses on functions. | Focuses on objects/classes. |
| Data Access | Globally accessible. | Encapsulated in objects. |
| Security | Less secure. | More secure. |
| Examples | C, Fortran. | C++, Java, Python. |
1.2 Features of Object-Oriented Programming (OOP)
--------------------------------------------------
- Encapsulation: Wrapping data and functions into a class.
- Abstraction: Hiding implementation details.
- Inheritance: Reusing existing classes.
- Polymorphism: Same operation behaving differently.
- Dynamic Binding: Runtime execution depends on conditions.
- Message Passing: Communication via methods.
Examples: C++, Java, Python
Applications: Game Development, GUI-Based Applications, Web Development.
1.3 Data Types in C++
---------------------
- Basic: int, float, char, etc.
- Derived: Arrays, Pointers.
- User-Defined: struct, class.
Dynamic Initialization:
-----------------------
int x = 5, y = 10;
int sum = x + y; // Initialized dynamically
Reference Variables:
-------------------
int a = 10;
int &ref = a;
1.4 Special Operators in C++
----------------------------
- Scope Resolution Operator (::): Used to access global variables.
- Memory Management Operators: `new`, `delete`.
- Manipulators: Formatting output (e.g., endl, setw).
1.5 Structure of a C++ Program
------------------------------
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!";
return 0;
}
1.6 Class & Object
------------------
Classes are blueprints. Objects are instances.
Example:
class Car {
public:
string brand;
};
Car myCar;
myCar.brand = "Tesla";