C++ Syllabus

C++ Syllabus

1. Basics of C++

Definition: C++ is a general-purpose programming language that supports procedural, object-oriented, and generic programming.

Explanation: Let's cover the foundational concepts:

  • Introduction to C++
  • Structure of a C++ Program
  • Input/Output Streams
  • Data Types and Variables
  • Operators
  • Comments

Example:

#include <iostream>
using namespace std;

int main() {
    cout << "Hello, World!";
    return 0;
}

2. Control Structures

  • Conditional Statements (if, else if, else)
  • Switch Case
  • Loops (for, while, do-while)

Example:

int x = 5;
if (x > 0) {
    cout << "Positive number";
} else {
    cout << "Non-positive number";
}

3. Functions

  • Defining and Calling Functions
  • Function Arguments and Return Types
  • Recursion

Example:

int add(int a, int b) {
    return a + b;
}

int main() {
    cout << add(3, 4); // Output: 7
}

4. Pointers and Memory Management

  • Pointers
  • Dereferencing and Pointer Arithmetic
  • Dynamic Memory Allocation (new, delete)

Example:

int* ptr = new int;  // Dynamic memory allocation
*ptr = 10;  // Assign value
cout << *ptr;  // Output: 10
delete ptr;  // Free allocated memory

5. Object-Oriented Programming (OOP)

  • Classes and Objects
  • Constructors and Destructors
  • Inheritance
  • Polymorphism (Function Overloading, Overriding)
  • Encapsulation and Abstraction
  • Access Modifiers (public, private, protected)

Example:

class Car {
public:
    string brand;
    string model;
    
    Car(string b, string m) {  // Constructor
        brand = b;
        model = m;
    }
    
    void display() {
        cout << "Car: " << brand << " " << model;
    }
};

int main() {
    Car car1("Toyota", "Corolla");
    car1.display();  // Output: Car: Toyota Corolla
}

6. Advanced C++ Concepts

  • Templates (Function and Class Templates)
  • Exception Handling
  • File Handling
  • STL (Standard Template Library): Vectors, Maps, Sets, Iterators
  • Multithreading
  • Lambda Expressions

Example: Template Function:

template <typename T>
T add(T a, T b) {
    return a + b;
}

int main() {
    cout << add(5, 3);   // Output: 8
    cout << add(3.5, 2.5); // Output: 6.0
}
Drag to resize