Answer to Question #194064 in C++ for Sarivinkumar M

Question #194064

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

Runtime input

2

-3


1
Expert's answer
2021-05-16T23:48:25-0400
/*
    C++ program to negate the complex number by using unary minus operator overloading
*/
#include<iostream>
#include<bits/stdc++.h>
using namespace std;

class ClassComplex{


	public:
		int num, imaginaryNum;

		//Default constructor
        ClassComplex(){

        }
        //Parameterized constructor
		ClassComplex(int num, int imaginaryNum){
			this->num = num;
			this->imaginaryNum = imaginaryNum;
		}
        //Unary minus operator overloading
		void operator-(){
			this->num = -num;
			this->imaginaryNum = -imaginaryNum;
		}
		//Default constructor
		~ClassComplex(){

		}
};

int main(){
	int num, imaginaryNum;
	cout<<"Enter real number part of the complex number: ";
	cin>>num;
	cout<<endl<<"Enter part of the complex number: ";
	cin>>imaginaryNum;


	ClassComplex cc(num, imaginaryNum );
	cout<<endl;
	cout<<"Before complex number negation: ";
	cout<<"["<<cc.num<<"] + ["<<cc.imaginaryNum<<"]i";


	cc.operator-();
    cout<<endl;
	cout<<"After complex number negation: ";
	cout<<"["<<cc.num<<"] + ["<<cc.imaginaryNum<<"]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
APPROVED BY CLIENTS