OOPs Using C++ - Very Important Notes (Exam Oriented)
1. Basic Concepts of OOP
- Class & Object: Class = blueprint; Object = real entity.
- Encapsulation: Data + functions ko ek unit mein rakhna.
- Abstraction: Sirf necessary details show karna.
- Inheritance: Ek class doosri class ke features le sakti hai.
- Polymorphism: Ek function ka multiple forms (Function Overloading, Operator Overloading).
- Data Hiding: Private members directly access nahi hote.
2. Tokens, Expressions & Control Structures
- Tokens: Keywords, Identifiers, Constants, Strings, Operators.
- Operators: Arithmetic (+, -, *, /, %), Relational (==, !=, <, >), Logical (&&, ||, !), Assignment (=, +=,
-=)
- Control Structures: if, if-else, switch, for, while, do-while
3. Functions in C++
- Call by Value vs Call by Reference
- Default Arguments
- Function Overloading
4. Classes and Objects
class Student {
private:
int roll;
public:
void setRoll(int r) { roll = r; }
void display() { cout << roll; }
};
5. Constructors & Destructors
- Constructor: Class name jaisa function, object banate hi call hota hai.
- Types: Default, Parameterized, Copy
- Destructor: ~ClassName() - object destroy hone pe call hota hai.
6. Inheritance
- Types: Single, Multiple, Multilevel, Hierarchical, Hybrid
class A { };
class B : public A { }; // Single Inheritance
- Access control: Public, Private Inheritance
7. Polymorphism
- Compile Time: Function Overloading, Operator Overloading
- Run Time: Virtual Functions (base class pointer to derived object)
8. File Handling
#include<fstream>
ofstream fout("file.txt");
fout << "Hello!";
fout.close();
- Classes: ifstream, ofstream, fstream
- Modes: ios::in, ios::out, ios::app
9. Templates & Exception Handling
template <class T>
T add(T a, T b) { return a + b; }
try {
// risky code
} catch(...) {
// error handle