Object-Oriented Programming Using C++ - Unit Summary
Object-Oriented Programming Using C++: Unit-Wise Explanation with Key Programs
UNIT 1: Introduction to OOP & Basics of C++
- OOP Concepts: Encapsulation, Abstraction, Inheritance, Polymorphism, Message Passing.
- Benefits: Modularity, reusability, scalability, security.
- POP vs OOP: OOP focuses on data and objects; POP on functions and logic.
- C++ Basics: main(), cin, cout, #include, comments, using namespace std
Example Program:
class Student {
string name;
int age;
public:
void setData(string n, int a) { name = n; age = a; }
void display() { cout << name << " " << age; }
};
UNIT 2: Constructors & Destructors
- Constructor: Initializes objects; same name as class.
- Types: Default, Parameterized, Copy.
- Destructor: Cleans memory, uses ~ prefix.
Example:
class Demo {
int x;
public:
Demo() { x = 0; }
Demo(int a) { x = a; }
~Demo() { cout << "Destroyed"; }
};
UNIT 3: Function Overloading & Compile-Time Polymorphism
- Function Overloading: Multiple functions with same name.
Page 1
Object-Oriented Programming Using C++ - Unit Summary
- Default Arguments, Inline Functions, Static Members.
Example:
void show(int a) { cout << a; }
void show(float b) { cout << b; }
UNIT 4: Inheritance
- Types: Single, Multiple, Multilevel, Hierarchical, Hybrid.
- Base & Derived classes.
Example:
class A { public: void showA() { cout << "A"; } };
class B : public A { public: void showB() { cout << "B"; } };
UNIT 5: Operator Overloading & Type Conversion
- Overload operators like +, -, == for objects.
- Use of this pointer.
Example:
Complex operator + (Complex c) {
return Complex(real + c.real, imag + c.imag);
UNIT 6: Runtime Polymorphism & Virtual Functions
- Virtual Functions: Late binding at runtime.
- Function Overriding, Abstract Classes.
Example:
class Base { public: virtual void show() { cout << "Base"; } };
class Derived : public Base { void show() { cout << "Derived"; } };
UNIT 7: Working with Files
- File Streams: ifstream, ofstream, fstream.
Page 2
Object-Oriented Programming Using C++ - Unit Summary
- Open, read, write, close files.
Example:
ofstream fout("data.txt"); fout << "Hello"; fout.close();
ifstream fin("data.txt"); fin >> data;
UNIT 8: Templates
- Generic Programming using Function and Class Templates.
Example:
template<class T> T add(T a, T b) { return a + b; }
UNIT 9: Exception Handling
- try, throw, catch blocks.
Example:
try { throw 0; } catch(int e) { cout << "Error"; }
UNIT 10: Namespaces & Advanced Features
- Namespaces prevent name conflict.
Example:
namespace test { int x = 5; }
cout << test::x;
Page 3