 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can overload plus equals to and minus equals to operators in C++. Before starting, you can note my information, you can connect with me by following these details which are available in front of you. Now, coming onto the topic, you can see a comment overloading plus equals to and minus equals to operators in C++. This is our objective, so I am going to demonstrate how you can do this. First, I have included a header file IO stream. Then I have used a namespace STD. Then class name is complex, so I will be adding two complex numbers and I will be subtracting two complex numbers by overloading plus equals to and minus equals to operators. Then in teaser real and imaginary, R and I variables are declared which are attributes. Then in public section, read function is implemented which will display enter real and imaginary values message on console through C out and the entered values will be stored inside R and I. These values will be received through CN statement. Then inside print function, C out statement will print values of real and imaginary along with the captions. Now, you can see two definitions. This is first function definition which is plus equals to. So this is overloaded operator function definition and it is overloading plus equals to operator. So here two arguments will be passed because it is binary operator. One is implicit and second will be explicit. So explicit argument will be stored inside C. Here you can see I have used C dot R and C dot I. So this is representing explicit argument and then I have used R equals to R plus. So these are are representing values of implicit argument. So you can say implicit argument is adding and with explicit arguments value and the result will be again assigned into implicit arguments value. You can also write this R equals to R plus C dot R like this R plus equals to C dot R and I plus equals to C dot I. Then similar to plus equals to minus equals to operator definition is also available. Here plus is replaced with I only. Rest of the things are same. This is also overloaded operator function. So this way I have overloaded plus equals to and minus equals to operators by using binary operator overloading concept. Now in main function you can see I have created three objects then C1 dot read C2 dot read. These are calling read functions. So C1 and C2 will receive values from user. Now I want to assign addition inside C3. So first I have copied values of C1 into C3. Then here plus equals to operator is overloaded. So C3 that is containing values of C1 will be passed implicitly and C2 will be passed explicitly. So now you can check the definition. Values of C3 will be calculated here using only R and I variables and C2 is passed inside the C object and C dot R and C dot I is representing values of C2. So C3 and C2 both are added and the results are assigned into C3. That's why this C3 is printing all the values of real and imaginary by calling this print function. So right now I have only called plus equals to overloaded operator function. So first I am executing this code. I am entering two two and two two. You can see the output real and imaginary both are printing four and four. Now I am copying these instructions and I am pasting them and I am making these statements as comment. This time I am calling C3 minus equals to C2. So here minus equals to operator will be overloaded. C3 will be passed implicitly and C2 will be passed explicitly. So now I am again executing this code. It is asking for real and imaginary values. So first I am entering four four and then I am entering two two. So you can see the result subtraction is performed and real and imaginary values are printing two and two. So this way I have executed this. If you want to perform both the operations at once, you can uncomment these instructions and you can copy these read function calls also. So this time first complex number and second complex number will be read and the addition will be stored inside C3. Then you have to enter new values and subtraction will be performed. So let's check it. I am entering two two two two. You can see four and four are printing again. It is asking for real and imaginary. I am entering four four and two two. It is printing real two and imaginary two. So this way I have called both the overloaded operator function plus equals to and minus equals to in main function. I hope you have understood how we can overload plus equals to and minus equals to operators in C++ through binary operator overloading. If you want to watch more programming related videos, you can subscribe my YouTube channel that is Sanjay Gupta underscore tech school. Follow this channel. Thank you for watching this video.