Friend Classes

Medium Static Members & Friend Functions
Solve in Playground →

Problem Statement

Create a `Secret` class with a private integer `code` set via constructor. Declare `class Agent` as a friend inside `Secret`. Create the `Agent` class with a method `void reveal(Secret s)` that prints ‘Code: [code]’. Read an integer, instantiate `Secret`, instantiate `Agent`, and call `reveal`.

Input Format

A single integer.

Output Format

Print the formatted code.

Constraints

None

Sample Input

007

Sample Output

Code: 7

Explanation

When an entire class is declared as a friend, all of its member functions gain access to the private data of the granting class.

Starter Code

#include <iostream>

class Secret {
    // Define private member, constructor, and friend class declaration
};

class Agent {
public:
    // Implement reveal()
};

int main() {
    // Read input, instantiate Secret and Agent, call reveal
    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