The trouble is you think you have time. Your success depends on how you utilize your time.

C++ Program which will give the sum of two complex numbers by taking imaginary and real part as input using classes and objects

How to write a C++ Program which will print the sum of two complex numbers by taking imaginary part and real part as input using classes and objects.

#include <iostream>
using namespace std;

class Imagin{
public:

double x,y;

Imagin(double nx, double ny){

x=nx;y=ny;}
};

int main(){
cout<<"www.moznum.blogspot.com"<<endl<<endl;

double nu1,nu2;
cout <<"First number \n";
cout<< "Enter the real part: ";
cin>> nu1;
cout<< "Enter the imaginary part: ";
cin>> nu2;
Imagin number1(nu1,nu2);
cout << "Second number \n";
    double nu3,nu4;
cout<< "Enter the real part: ";
cin>> nu3;
cout<< "Enter the imaginary part: ";
cin>> nu4;
Imagin number2(nu3,nu4);

double real;

    real = number1.x +number2.x;

    double imagin;

    imagin = number2.y + number1.y;
cout <<endl<<"The sum of the complex number is: "<< real << " + "<<imagin<<"i";
    
    return 0;
}

No comments:

Post a Comment