Inventory

Medium Classes & Objects
Solve in Playground →

Problem Statement

Write a C++ program defining an `Inventory` class to manage stock additions and removals, then display the remaining stock count.

Input Format

Initial stock (int), added stock (int), and sold stock (int).

Output Format

Print final available stock.

Constraints

Stock values >= 0

Sample Input

100 50 30

Sample Output

Final Stock: 120

Explanation

Tracks dynamic stock level adjustments inside an inventory class.

Starter Code

#include <iostream>

class Inventory {
private:
    int stock;
public:
    void setStock(int s) { stock = s; }
    void addStock(int qty) {
        // Write your code here
    }
    void removeStock(int qty) {
        // Write your code here
    }
    void display() {
        std::cout << "Final Stock: " << stock << "n";
    }
};

int main() {
    Inventory inv;
    int init, add, rem;
    if (std::cin >> init >> add >> rem) {
        inv.setStock(init);
        inv.addStock(add);
        inv.removeStock(rem);
        inv.display();
    }
    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