C++ Beginner to Advanced Course Module

C++ Beginner to Advanced Course Module

C++ Beginner to Advanced Course Module

Beginner to Intermediate Modules

Module 1: Introduction to C++

Real-life Application: Basic Console Programs

Instructions:

  • Use basic syntax to create a simple calculator or a program that takes user input and displays a message.
  • Example:
#include <iostream>
using namespace std;

int main() {
    int a, b;
    cout << "Enter two numbers: ";
    cin >> a >> b;
    cout << "Sum: " << a + b << endl;
    return 0;
}
        

Module 2: Control Structures

Real-life Application: Decision-making Programs

Instructions:

  • Create a program that makes decisions based on user input, such as a simple grade calculator or a menu-driven application.
  • Example:
#include <iostream>
using namespace std;

int main() {
    int score;
    cout << "Enter your score: ";
    cin >> score;
    if (score >= 90) cout << "Grade: A" << endl;
    else if (score >= 80) cout << "Grade: B" << endl;
    else if (score >= 70) cout << "Grade: C" << endl;
    else cout << "Grade: F" << endl;
    return 0;
}
        

Module 3: Functions

Real-life Application: Modular Programs

Instructions:

  • Break down a larger program into smaller functions to improve readability and reusability, like a program that calculates areas of different shapes.
  • Example:
#include <iostream>
using namespace std;

double areaOfCircle(double radius) {
    return 3.14159 * radius * radius;
}

double areaOfRectangle(double length, double width) {
    return length * width;
}

int main() {
    double radius, length, width;
    cout << "Enter radius of circle: ";
    cin >> radius;
    cout << "Area of circle: " << areaOfCircle(radius) << endl;

    cout << "Enter length and width of rectangle: ";
    cin >> length >> width;
    cout << "Area of rectangle: " << areaOfRectangle(length, width) << endl;

    return 0;
}
        

Module 4: Arrays and Strings

Real-life Application: Data Storage and Manipulation

Instructions:

  • Use arrays to store a collection of data and perform operations on them, like finding the largest number or reversing a string.
  • Example:
#include <iostream>
#include <string>
using namespace std;

int main() {
    int arr[5] = {1, 2, 3, 4, 5};
    int max = arr[0];
    for (int i = 1; i < 5; ++i) {
        if (arr[i] > max) max = arr[i];
    }
    cout << "Max value: " << max << endl;

    string str = "hello";
    string reversedStr = string(str.rbegin(), str.rend());
    cout << "Reversed string: " << reversedStr << endl;

    return 0;
}
        

Module 5: Pointers and References

Real-life Application: Dynamic Memory Management

Instructions:

  • Use pointers to dynamically allocate memory and manage resources, like creating a dynamic array or linked list.
  • Example:
#include <iostream>
using namespace std;

int main() {
    int* arr = new int[5];
    for (int i = 0; i < 5; ++i) {
        arr[i] = i + 1;
    }

    for (int i = 0; i < 5; ++i) {
        cout << arr[i] << " ";
    }
    cout << endl;

    delete[] arr;
    return 0;
}
        

Intermediate to Advanced Modules

Module 6: Object-Oriented Programming Basics

Real-life Application: Designing Classes for Real-world Entities

Instructions:

  • Design classes to represent real-world entities, like creating a `Car` class with attributes and methods.
  • Example:
#include <iostream>
using namespace std;

class Car {
private:
    string model;
    int year;

public:
    Car(string m, int y) : model(m), year(y) {}

    void displayInfo() {
        cout << "Model: " << model << ", Year: " << year << endl;
    }
};

int main() {
    Car car1("Toyota", 2020);
    car1.displayInfo();

    return 0;
}
        

Module 7: Advanced Object-Oriented Programming

Real-life Application: Designing Complex Systems

Instructions:

  • Use advanced class design features to build complex systems like a library management system or a banking system.
  • Example:
#include <iostream>
using namespace std;

class Account {
private:
    string owner;
    double balance;

public:
    Account(string owner, double balance) : owner(owner), balance(balance) {}

    void deposit(double amount) {
        balance += amount;
    }

    void withdraw(double amount) {
        if (amount <= balance) balance -= amount;
        else cout << "Insufficient funds" << endl;
    }

    void display() const {
        cout << "Owner: " << owner << ", Balance: $" << balance << endl;
    }
};

int main() {
    Account acc("John Doe", 1000.0);
    acc.deposit(500.0);
    acc.withdraw(200.0);
    acc.display();

    return 0;
}
        

Module 8: Memory Management

Real-life Application: Efficient Resource Management

Instructions:

  • Use dynamic memory management to handle resources efficiently, especially in large applications that require a lot of memory operations.
  • Example:
#include <iostream>
#include <memory>
using namespace std;

class Resource {
public:
    Resource() { cout << "Resource acquired" << endl; }
    ~Resource() { cout << "Resource destroyed" << endl; }
};

void useResource() {
    unique_ptr<Resource> res(new Resource());
    // Use res
}

int main() {
    useResource();
    return 0;
}
        

Module 9: Concurrency and Multithreading

Real-life Application: Building Responsive Applications

Instructions:

  • Implement multithreading to make applications responsive, such as a file downloader that can download multiple files simultaneously.
  • Example:
#include <iostream>
#include <thread>
using namespace std;

void downloadFile(int fileNumber) {
    cout << "Downloading file " << fileNumber << "..." << endl;
    this_thread::sleep_for(chrono::seconds(3));
    cout << "File " << fileNumber << " downloaded" << endl;
}

int main() {
    thread t1(downloadFile, 1);
    thread t2(downloadFile, 2);

    t1.join();
    t2.join();

    return 0;
}
        

Module 10: Advanced Standard Template Library (STL)

Real-life Application: Efficient Data Handling

Instructions:

  • Use advanced STL algorithms and containers for efficient data handling, such as using maps for fast lookups or vectors for dynamic arrays.
  • Example:
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main() {
    map<string, int> nameToAge;
    nameToAge["Alice"] = 30;
    nameToAge["Bob"] = 25;

    for (const auto& [name, age] : nameToAge) {
        cout << name << ": " << age << endl;
    }

    vector<int> numbers = {1, 2, 3, 4, 5};
    for (int num : numbers) {
        cout << num << " ";
    }
    cout << endl;

    return 0;
}
        

Post a Comment

Post a Comment (0)

Previous Post Next Post