Creating Read-Only Attributes

Medium Encapsulation, Access Specifiers & The this Pointer
Solve in Playground →

Problem Statement

Create a `Circle` class with a private integer `radius`. Use a parameterized constructor to set the radius upon creation. Provide a public getter `getRadius()` but NO setter, making it read-only. In `main()`, instantiate the class with an input radius and print its diameter (2 * radius).

Input Format

A single integer.

Output Format

Print 'Diameter: [val]'.

Constraints

None

Sample Input

5

Sample Output

Diameter: 10

Explanation

Omitting a setter enforces read-only immutability for a specific property after object construction.

Starter Code

#include <iostream>

class Circle {
    // Write the constructor and getter
};

int main() {
    // Instantiate and calculate diameter
    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