Build a Dynamically Managed Inventory System

Hard Dynamic Memory & Smart Pointers PRO
🔒 Login to Unlock

Problem Statement

Combine the concepts! Build an `Inventory` class managing a dynamic array of integers (using `new[]`). Read an integer N, dynamically allocate the array to hold N items, read N integers to populate the inventory, print them all, and strictly use `delete[]` in the destructor to prevent memory leaks. Print ‘Inventory Cleared’ inside the destructor.

Input Format

Line 1: N (capacity). Line 2: N space-separated integers.

Output Format

Print each item on a new line, followed by the destructor cleanup message.

Constraints

Must utilize manual dynamic memory management.

Sample Input

3
101 102 103

Sample Output

Item: 101
Item: 102
Item: 103
Inventory Cleared

Explanation

An end-to-end simulation of object lifecycle handling, emphasizing dynamic arrays and strict destructor cleanup routines.

Starter Code

#include <iostream>

class Inventory {
public:
    // Implement dynamic allocation and destructor
};

int main() {
    // Setup Inventory and run workflow
    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