Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
776 B
4
Indexable
Never
// CPP shell
#include <iostream>
//OOP to add 2 complex numbers using passing objects as arguments.
using namespace std;

class complex{
   public: 
        int re,im;

complex method1(complex c1, complex c2){
    int sum1=c1.re+c2.re;
    int sum2=c1.im+c2.im;
    
    if (sum2>=0){
        cout << "Complex number is "<<sum1 <<"+"<<sum2<<"i"<<endl;
    }
    else{
        cout << "Complex number is "<<sum1 <<"-"<<sum2<<"i"<<endl;
    }
}
};
int main() {
   complex num1 ,num2;
   
   
   cout<< "Enter the 1st real number and the imaginary number:";
   cin>>num1.re>>num1.im;
   
   cout<< "Enter the 2nd real number and the imaginary number:";
   cin>>num2.re>>num2.im;
   
   complex sum;
   sum=sum.method1(num1,num2);
    return 0;
}