Unit 1 Deepseek
Unit 1 Deepseek
---
1. **Encapsulation**:
- Bundling data (attributes) and methods (functions) that operate on the data into a single unit
(object).
- Protects data from outside interference by restricting direct access (using access modifiers like
`private`, `public`, etc.).
2. **Abstraction**:
- Hiding complex implementation details and showing only the necessary features of an object.
- Example: A car’s steering wheel hides the complexity of the steering mechanism.
3. **Inheritance**:
4. **Polymorphism**:
- Example: A function can behave differently depending on the object that calls it (e.g., method
overriding).
---
1. **Classes**:
class Dog {
public:
};
```
2. **Objects**:
- Instances of a class.
3. **Functions/Methods**:
4. **Variables/Attributes**:
5. **Main Function**:
- Example:
```cpp
int main() {
Dog myDog;
myDog.name = "Buddy";
return 0;
```
---
2. **Class Definition**:
3. **Main Function**:
---
|---------------------------|----------------------------------------------------|-------------------------------------------------|
| **Data Security** | No data hiding; all data is accessible. | Data is secured using
encapsulation. |
---
#include <stdio.h>
return a + b;
int main() {
return 0;
```
---
```cpp
#include <iostream>
class Calculator {
public:
return a + b;
};
int main() {
Calculator calc;
cout << "Result: " << result << endl; // Output: Result: 15
return 0;
}
```
---
- OOP is about organizing code using **objects**, making it modular and reusable.
- C++ extends C by adding OOP features like classes, objects, inheritance, and polymorphism.
- Procedure-oriented programming (C) focuses on functions, while OOP (C++) focuses on objects and
their interactions.