Complex Number

Medium Classes & Objects
Solve in Playground →

Problem Statement

Write a C++ program defining a `Complex` class to add two complex numbers and display the result in `a + bi` format.

Input Format

Real1, Imag1, Real2, and Imag2 as floating-point numbers.

Output Format

Print resulting complex number.

Constraints

Standard real/imaginary values

Sample Input

3.5 2.0 1.5 4.0

Sample Output

Sum: 5.00 + 6.00i

Explanation

Combines member properties across objects for arithmetic operations.

Starter Code

#include <iostream>
#include <iomanip>

class Complex {
public:
    double real;
    double imag;
    
    void addAndDisplay(Complex c1, Complex c2) {
        // Write your code here
    }
};

int main() {
    Complex c1, c2, res;
    if (std::cin >> c1.real >> c1.imag >> c2.real >> c2.imag) {
        res.addAndDisplay(c1, c2);
    }
    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