answersLogoWhite

0


Best Answer

#include<iostream.h> #include<conio.h> class complex { int r; int i; public: complex() { } complex(int a,int b) { r=a;i=b; } friend complex operator+(complex,complex); friend show(complex); complex operator+(complex c1,complex c2) { complex c3; c3.r=c1.r+c2.r; c3.i=c1.i+c2.i; return(c3); } show(complex c) { cout<<c.r<<"i+"<<c.i<<endl; } void main() { complex a,b,c; clrscr(); a.complex(3,6); b.complex(4,7); c=a+b; show(a); show(b); show(c); getch() }

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to write the sum of two complex number using friend function and overloading constractor?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the c plus plus program to calculate the area of a circle using function overloading?

Function overloading is used when you want to re-use the same function name with different argument types or a different number of arguments. Calculating the area of a circle isn't the sort of function that requires overloading since the only argument you need is the radius. double area_of_circle (const double radius) { const double pi=4*atan(1); return pi*radius*radius; }


What is main advantage of using constructors in java?

Constructors have the same name as the class itself and they do not specify a return type, not even void because they return the instance of the class itself. Because constructors have the same name as the class then they allow method overloading and also save memory and execution time of program. Program release memory of constructors function after using this function and it reduce program complexity.


C program to multiply two complex no?

/*C++ program to multiply two complex numbers using * operator overloading*/ #include&lt;iostream.h&gt; #include&lt;conio.h&gt; class complex { float x,y; public: complex() {} complex(float real,float img) { x=real; y=img; } complex operator*(complex); void display() { cout&lt;&lt;x&lt;&lt;" + "&lt;&lt;y&lt;&lt;"i"&lt;&lt;endl; } }; complex complex::operator*(complex e) { complex temp; temp.x=x*e.x+y*e.y*(-1); temp.y=x*e.y+y*e.x; return(temp); } void main() { clrscr(); complex c1(5,3),c2(3,2),c3=c1*c2; c1.display(); c2.display(); cout&lt;&lt;"Multiplication"&lt;&lt;endl; c3.display(); getch(); } OUTPUT: 5 + 3i 3 + 2i Multiplication 9 + 19i


Which function is supported by an application program?

which function is support by an application program


What are its program components?

the main() function,the#include Directive, the variable definition. function prototype, program statements, the function definition,program comments and braces are the components of program in C++


What are the normal results of vision training?

A carefully and individually tailored program of vision therapy should result in a gradual improvement in whatever complex visual function is being addressed.


What is the name of the function which must be defined in a Java program?

The main function. Every program must have a main function and it must be declared static.


C program always begins with which function?

That's up to you, but the execution of the program begins with function main.


Where is the fuction call of main function?

The main function is the entry point into a program. When the Operating System launches the program the main function gets executed.


What is the difference between agent function and agent program in AI?

From what I understand, agent function is a program that maps the percepts to action and update the internal state. an agent program actually implements the agent function


Where do we write main function in a c program?

Into the source program.


Function to translate source program to object program?

computer