Product Class

Easy Classes & Objects
Solve in Playground →

Problem Statement

Write a C++ program defining a `Product` class with item name, unit price, and quantity, computing and printing total inventory cost.

Input Format

Name (string), Price (double), and Quantity (int).

Output Format

Print total cost.

Constraints

Price >= 0, Quantity >= 0

Sample Input

Laptop 750.50 4

Sample Output

Product: Laptop, Total Cost: 3002.00

Explanation

Calculates aggregate product values from quantities and pricing.

Starter Code

#include <iostream>
#include <string>
#include <iomanip>

class Product {
public:
    std::string name;
    double price;
    int quantity;
    
    void computeTotal() {
        // Write your code here
    }
};

int main() {
    Product p;
    if (std::cin >> p.name >> p.price >> p.quantity) {
        p.computeTotal();
    }
    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