Write a program to compare the magnitude of a complex number by overloading the <,>,==,!= operator.

Its output will come as follows.

Explanation now comes as follows.

Our target of this program is to overload relational operators for comparing objects of money class.

So, we will divide money into paisa and rupees.

And, then we will take 2 inputs and compare those values(obviously its sum).

So if I input 100 rupees 20 paisa and again 100 rupees 20 paisa, then it will show “equal”.

Create a class named city, that will have 2 members variables, cityname(char[20]) and distfromA(float). Add member functions to set and retrieve the cityname and distfromA separately. Add operator overloading to find the distance between the cities(just find the difference of distfromA) and sum of idstance of those cites from A. In the main fxn, initialise three city objects. Set the first and second city to be B and C. Display the sum of distfromA of B and C and the distance between B and C.

note-: u can assume the necessary data ðŸ™‚

Its output comes as follows.

The working of program above is as follows. Firstly, A,B and C are displayed with the distances. Then, again it will do c1-c2/c1+c2 and finally displayed the subtraction and addition.

The working of above program can be known by deeply looking inside the main function.

d1,d2,d3,d4 are the objects of the class. and we did d3=d1+d2 to add whereas, d4=d1-d2. These are the basic syntax in programming operator overloading that; if you remember; it will be better.

Next topic will be about the conversion of data types from one type to another.

Before you go-:

Subscribe to this blog(by bookmarking) we don’t send notifications to you.

Motivational-: