Overloading with Different Number of Arguments

Easy Polymorphism & Function Overloading
Solve in Playground →

Problem Statement

Create a `Calculator` class. Overload an `add` method so that it can accept either two integers or three integers, returning their sum. Read three integers. First print the sum of the first two integers, then print the sum of all three.

Input Format

Three space-separated integers.

Output Format

Print 'Sum of 2: [val]' followed by 'Sum of 3: [val]'.

Constraints

None

Sample Input

5 10 15

Sample Output

Sum of 2: 15
Sum of 3: 30

Explanation

Methods can be cleanly overloaded based strictly on the number (arity) of arguments passed into them.

Starter Code

#include <iostream>

class Calculator {
public:
    // Write your overloaded add methods here
};

int main() {
    // Read input and test overloads
    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