Default Arguments in Constructors

Medium Object Lifecycle (Constructors & Destructors)
Solve in Playground →

Problem Statement

Create a `Greeting` class taking `std::string name = “Guest”` as a default parameter in its constructor. The constructor should print ‘Hello, [name]’. Read a string. If the string is ‘NONE’, instantiate the object without arguments. Otherwise, instantiate it with the string.

Input Format

A single string.

Output Format

Print the greeting.

Constraints

String contains no spaces.

Sample Input

Alice

Sample Output

Hello, Alice

Explanation

Default arguments allow a single constructor to handle varying numbers of arguments seamlessly.

Starter Code

#include <iostream>
#include <string>

class Greeting {
public:
    // Implement constructor with default argument
};

int main() {
    std::string input;
    if (std::cin >> input) {
        // Instantiate appropriately based on input
    }
    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