Object-Oriented Programming in C++ (BIT154CO)
Object-oriented paradigms, classes and objects, constructors and destructors, operator overloading, inheritance and derived classes, virtual functions, abstract classes and runtime polymorphism, templates and generic programming, namespaces, exception handling, and streams and file handling in C++.
Unit 1: Introduction to Object-Oriented Programming2 hrs
- Limitations of procedural programming and structured paradigm pitfalls
- Paradigm shift: Procedure-Oriented Programming (POP) vs Object-Oriented Programming (OOP)
- Core fundamental principles of OOP: Objects, Classes, Data abstraction, Encapsulation, Inheritance, Polymorphism, Dynamic binding, and Message passing
- Software reusability, modularity, maintainability, and enterprise applications of OOP
Unit 2: C++ Programming Concepts and Language Extensions3 hrs
- Evolution and history of C++ (Bjarne Stroustrup, C with Classes)
- Structure of a modern C++ program and compilation pipeline
- Tokens, keywords, identifiers, constants, and basic vs user-defined data types
- Reference variables: Definition, syntax, and comparison with pointers
- Dynamic memory management: new and delete operators vs malloc() and free()
- Scope resolution operator (::), member dereferencing operators (.* and ->*)
- Type casting operators (static_cast, const_cast, reinterpret_cast, dynamic_cast)
- Stream I/O manipulators: endl, setw, setprecision, setfill, and flags in <iomanip>
Unit 3: Functions in C++3 hrs
- Function prototyping and type-safe linkage in C++
- Parameter passing mechanisms: Call by value, Call by pointer, and Call by reference
- Return by reference and returning lvalues from functions
- Inline functions: Definition, compiler expansion mechanism, benefits, and execution constraints
- Default arguments in functions: Rules, declaration syntax, and restrictions
- Constant function parameters (const correctness) and const return types
- Function overloading: Compile-time polymorphism, resolution rules, and ambiguous calls
Unit 4: Classes and Objects7 hrs
- Specifying a class: Class declaration, data members, and member functions
- Access specifiers: private, protected, and public visibility rules
- Defining member functions inside the class (implicit inlining) and outside using scope resolution (::)
- Nesting of member functions and private helper functions
- Memory allocation for objects: Shared member functions and independent data members
- Static data members: Class-wide shared variables, external definition, and initialization
- Static member functions: Characteristics, restrictions (cannot access this pointer or non-static members)
- Arrays of objects and object pointer indexing
- Objects as function arguments: Pass by value and pass by reference
- Friend functions: Need, syntax, accessing private members, and bridging disparate classes
- Friend classes: Complete encapsulation sharing between cooperating classes
- Returning objects from functions and anonymous temporary objects
Unit 5: Constructor and Destructor3 hrs
- Constructors: Definition, automatic invocation, naming rules, and characteristics
- Default constructor: Compiler-synthesized vs user-defined default constructors
- Parameterized constructors: Initialization with arguments and explicit calls
- Constructor overloading in a class and constructor chaining
- Constructors with default arguments and ambiguity resolution
- Dynamic initialization of objects through constructors at runtime
- Copy constructor: Definition, shallow copy vs deep copy, dynamic memory replication, and pass-by-value invocation
- Dynamic constructors using new operator inside constructors
- Destructors: Characteristics, no-argument rule, cleanup of dynamically allocated resources
- Order of invocation of constructors and destructors for global, local, and dynamic objects
Unit 6: Operator Overloading6 hrs
- Operator overloading: Concept, syntax, and operator keyword
- Rules and limitations: Operators that cannot be overloaded (. , .* , :: , ?: , sizeof)
- Overloading unary operators: Unary minus (-), logical NOT (!), and increment/decrement (++ and --)
- Distinguishing prefix and postfix increment/decrement operators using dummy int argument
- Overloading binary arithmetic operators (+, -, *, /) using member functions
- Overloading binary operators using friend functions (handling commutative operands like int + Object)
- Overloading stream insertion (<<) and stream extraction (>>) operators for custom classes
- Overloading comparison and assignment operators (operator=, deep copy, and self-assignment checks)
- Data conversion: Basic type to class type (using single-argument constructor)
- Data conversion: Class type to basic type (using custom conversion operator functions)
- Data conversion: Class type to another class type (using constructor in destination class or conversion routine in source class)
Unit 7: Inheritance6 hrs
- Inheritance: Concept, base class, derived class, and software reusability
- Access control in derived classes: public, protected, and private derivation modes and member visibility matrix
- Forms of inheritance: Single inheritance, Multilevel inheritance, Multiple inheritance, Hierarchical inheritance, and Hybrid inheritance
- Multipath inheritance and member duplication ambiguity: The Diamond Problem
- Virtual base classes: Syntax, internal shared memory mechanism, and resolving diamond ambiguity
- Constructors and destructors in derived classes: Passing arguments from derived to base constructors
- Member initialization list (MIL) syntax, order of execution, and member initialization order
- Overriding base class member functions and accessing overridden members using scope resolution
Unit 8: Virtual Functions and Polymorphism4 hrs
- Pointers to objects, object pointer arithmetic, and the this pointer
- Pointers to derived classes: Base class pointer pointing to derived class object (Upcasting)
- Compile-time polymorphism (early binding) vs Run-time polymorphism (late binding / dynamic dispatch)
- Virtual functions: virtual keyword, mechanics of dynamic dispatch, and rules for virtual functions
- Virtual method table (vtable) and virtual pointer (vptr) internal implementation mechanism
- Pure virtual functions (= 0 syntax) and Abstract Base Classes (interfaces)
- Virtual destructors: Preventing partial destruction and memory leaks when deleting derived objects via base pointers
Unit 9: File Handling6 hrs
- Streams in C++: Standard input/output streams and hierarchy of stream classes in <iostream> and <fstream>
- File stream classes: ifstream (input), ofstream (output), and fstream (input/output)
- Opening and closing files using constructors and open() member function
- File opening modes: ios::in, ios::out, ios::app, ios::ate, ios::binary, ios::trunc, and bitwise OR combining
- Detecting end-of-file: eof() function, good(), fail(), and bad() stream status flags
- File pointers and manipulators: get pointer (seekg, tellg) and put pointer (seekp, tellp)
- Random access in files using seekg/seekp with ios::beg, ios::cur, and ios::end offsets
- Formatted text file I/O vs Unformatted binary file I/O
- Reading and writing binary records/objects using read() and write() member functions with reinterpret_cast<char*>
- Updating, searching, modifying, and deleting records in binary data files
Unit 10: Templates and Namespaces3 hrs
- Generic programming philosophy and type independence
- Function templates: Syntax, template type parameters, and automatic template argument deduction
- Function templates with multiple type arguments and non-type template arguments
- Overloading function templates with ordinary functions and other templates
- Class templates: Definition, syntax, member function definitions outside template class
- Class templates with default parameters and multiple parameters
- Generic data structures implementation: Generic Stack and Generic Queue using class templates
- Namespaces: Resolving identifier collisions, defining namespaces, and the std standard namespace
- Accessing namespace members: Explicit qualification (::), using declaration, and using directive
- Nested namespaces, aliased namespaces, and unnamed (anonymous) namespaces
Unit 11: Exception Handling2 hrs
- Traditional error handling vs C++ structured exception handling
- Exception handling architecture: try block, throw statement, and catch handler blocks
- Control flow in exception handling, stack unwinding, and automatic destruction of local objects
- Catching multiple exceptions and catch-all handler (catch(...))
- Re-throwing exceptions from catch handlers and nested try-catch blocks
- Exception specifications (throw() lists) and modern noexcept specifier
- Standard library exceptions hierarchy in <stdexcept> (exception, runtime_error, out_of_range, bad_alloc)
Reference books
- E. Balagurusamy, Object Oriented Programming with C++ (8th ed.), McGraw-Hill.
- Robert Lafore, Object-Oriented Programming in C++ (4th ed.), Sams Publishing.
- Bjarne Stroustrup, The C++ Programming Language (4th ed.), Addison-Wesley.
- Herbert Schildt, C++: The Complete Reference (4th ed.), McGraw-Hill.
- Stanley B. Lippman, Josee Lajoie, and Barbara E. Moo, C++ Primer (5th ed.), Addison-Wesley.