Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Create a class that represents a complex number with methods to add and multiply complex numbers.

Hard

Problem Statement

Create a class that represents a complex number with methods to add and multiply complex numbers.

Sample Input

Complex c1(2, 3); Complex c2(4, 5);

Sample Output

Sum: 6 + 8i
Product: -7 + 22i

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
#include <iostream> class Complex { private: double real, imag; public: Complex(double r, double i); Complex add(Complex other); Complex multiply(Complex other); void display(); }; int main() { // Logic to demonstrate Complex functionality return 0; }
Log in or sign up to run or submit your code.Log inSign up
Input
Complex c1(2, 3); Complex c2(4, 5);
Expected Output
Sum: 6 + 8i
Product: -7 + 22i