Answer to Question #193018 in C++ for Ajith M

Question #193018

Develop a C++ program to negate the complex number by using unary minus operator overloading


1
Expert's answer
2021-05-14T23:49:53-0400


#include<iostream>
#include<bits/stdc++.h>
using namespace std;


class Complex{
	
	public:
		int real, img;
		
		Complex(int real, int img)
		{
			this->real = real;
			this->img = img;
		}
		
		void operator-()
		{
			this->real = -real;
			this->img = -img;
		}
};


int main()
{
	int real, img;
	cout<<"Enter Real part of complex number : ";
	cin>>real;
	cout<<endl<<"Enter Imaginary part of complex number : ";
	cin>>img;
	
	Complex c1(real, img);
	cout<<endl<<"Before Negation of Complex number : ";
	cout<<"("<<c1.real<<") + ("<<c1.img<<")i";
	
	c1.operator-();
	
	cout<<endl<<"After Negation of Complex number : ";
	cout<<"("<<c1.real<<") + ("<<c1.img<<")i";
	
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog