Final Capstone Smart Pointers Project

Hard Smart Pointers PRO
🔒 Login to Unlock

Problem Statement

Write a C++ program implementing a robust resource manager and node graph using `std::unique_ptr`, `std::shared_ptr`, and `std::weak_ptr` to manage ownership hierarchies safely.

Input Format

Owner ID (int) and shared resource value (int).

Output Format

Print resource value accessed via shared and weak pointer observers.

Constraints

IDs >= 0

Sample Input

101 5000

Sample Output

Owner 101 Accessing Resource: 5000, Active References: 2

Explanation

Capstone project integrating unique ownership, shared reference counting, and weak pointer observation for complex object graphs.

Starter Code

#include <iostream>
#include <memory>

class Resource {
private:
    int val;
public:
    Resource(int v) : val(v) {}
    int getVal() const { return val; }
};

class Owner {
private:
    int id;
    std::shared_ptr<Resource> res;
    std::weak_ptr<Resource> observer;
public:
    Owner(int i, std::shared_ptr<Resource> r) : id(i), res(r), observer(r) {}

    void inspect() {
        // Implement weak_ptr lock and inspection logic here
    }
};

int main() {
    int id, val;
    if (std::cin >> id >> val) {
        auto sharedRes = std::make_shared<Resource>(val);
        Owner owner(id, sharedRes);
        owner.inspect();
    }
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used