C++ program to find the sum of two complex numbers

 C++ program to find the sum of two complex numbers 


#include <iostream>  

using namespace std;  

class complex  

{  

    private:  

float r;  

float i;  

public:  

void set(float real, float img)  

{  

    r = real;  

i = img;  

}  

complex sum(complex c)  

{  

    complex t;  

t.r = r + c.r;  

t.i = i + c.i;  

return t;  

}  

void disp()  

{  

    if (i == -1)   

{  

    cout<< r << " + -i" <<endl;  

}  

else if (i == 1)   

{  


   cout<< r << " + i" <<endl;  

}  

else if (i == 0)   


{  

    cout<< r <<endl;  

}  

else   

{  


   cout<< r << " + " <<i<< "i" <<endl;  

}  

    }  

};  

int main()  

{  

 complex c1, c2, c3;  

c1.set(2.5, 3.5);  

c2.set(1.5, 5.5);  

c3 = c1.sum(c2);  

cout<<"Code by Code.Champ "<<endl;  

cout<<"Complex Number 1 = ";  

c1.disp();  

cout<<"Complex Number 2 = ";  

c2.disp();  

cout<<"Complex Number 3 = "; 

c3.disp();  

return 0; 



For more follow on Instagram: Code Champ

Draw Shin Chan using Python Turtle: https://youtu.be/JqS5NJV2chk
Draw Doremon using Turtle in python : https://youtu.be/mfPfSERU2K0
Print name using Python Turtle: https://youtu.be/5XcSBJqQMIc
Indian Flag using Python Turtle: https://youtu.be/XSulTcyWAoE
Amazing Design/ pattern using Python Turtle: https://youtu.be/fIYzTIjJdT4 
Amazing 2Design/ pattern using Python Turtle:  https://youtu.be/5gX09uVdjlo

Difference  between C++ and Java: https://youtu.be/oSLL27bIXKQ

Types of application in java: https://www.instagram.com/p/CUIBrSmv6LM/


For Flipkart and Amazon best deals visit:

No comments:

Powered by Blogger.