Build a Computer with CPU and RAM Components

Medium Composition & Aggregation PRO
🔒 Login to Unlock

Problem Statement

Use strict composition. Build `CPU` (takes `float speed`) and `RAM` (takes `int size`) classes. Build a `Computer` class that takes both inputs and instantiates `CPU` and `RAM` internally as direct objects (not pointers) using an initializer list. Add a `specs()` method that prints ‘CPU: [speed]GHz\nRAM: [size]GB’.

Input Format

A float (CPU speed) and an integer (RAM size) separated by space.

Output Format

Print the specs using strict formatting.

Constraints

None

Sample Input

3.5 16

Sample Output

CPU: 3.5GHz
RAM: 16GB

Explanation

A complete composition example. The computer manages the strict lifecycles of its internal hardware components.

Starter Code

#include <iostream>

class CPU {
public:
    // Write your code here
};

class RAM {
public:
    // Write your code here
};

class Computer {
public:
    // Write your code here
};

int main() {
    // Construct computer and show specs
    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