You are on page 1of 2

#include <iostream>

#include <cmath>
#include <string>
#include <iomanip>

using namespace std;


class Complex
{
float real;
float imag;
float add_i, add_j;
float diff_i, diff_j;
float mod;

public:
void input_number()
{
cout << "Enter the real part: " << endl;
cin >> real;
cout << "Enter the imagnary part: " << endl;
cin >> imag;
}
void Display_complex()
{
cout << "The given Complex number is: (" << real << "+" << imag << "i)" <<
endl;
}
void Addition(Complex o1)
{
add_i = real + (o1.real);
add_j = imag + (o1.imag);
cout << "The Addition of Complex number is: (" << add_i << "+" << add_j <<
"i)" << endl;
}
void Substraction(Complex o1)
{
diff_i = real - (o1.real);
diff_j = imag - (o1.imag);
cout << "The Substraction of Complex number is: (" << diff_i << "+" <<
diff_j << "i)" << endl;
}
void Modulus()
{
mod = sqrt(pow(real, 2) + pow(imag, 2));
cout << "The Modulus of Complex number is: " << mod << endl;
}
};

int main()
{
Complex c1, c2;
c1.input_number();
c2.input_number();
cout << endl;
for (int i = 1; i>0; i++)
{
int n;
cout << "Enter 1 for Display complex numbers:" << endl;
cout << "Enter 2 for Addition:" << endl;
cout << "Enter 3 for Substraction:" << endl;
cout << "Enter 4 for modulus:" << endl;
cin >> n;
if (n == 1)
{
c1.Display_complex();
c2.Display_complex();
cout << endl;
}
else if (n == 2)
{
c1.Addition(c2);
cout << endl;
}
else if (n == 3)
{
c1.Substraction(c2);
cout << endl;
}
else if (n == 4)
{
c1.Modulus();
c2.Modulus();
cout << endl;
}
}

return 0;
}

You might also like