0% found this document useful (0 votes)
31 views2 pages

Ans 1

The document defines a complex number class with private real and imaginary number variables. It includes three constructors and friend functions to add two complex numbers and display the output. The main function creates two complex objects, calls the add function to sum them and display the result.

Uploaded by

Sanket Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Ans 1

The document defines a complex number class with private real and imaginary number variables. It includes three constructors and friend functions to add two complex numbers and display the output. The main function creates two complex objects, calls the add function to sum them and display the result.

Uploaded by

Sanket Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<iostream>

using namespace std;

class complex{

private:

int realnum, imagnum;

char ch='+';

char ch1='i';

public:

complex(){

realnum = 0;

imagnum = 0;

complex(int j){

realnum = j;

imagnum = j;

complex(int a, int b){

realnum = a;

imagnum = b;

friend void add(complex, complex);

friend void display();

};

void add(complex c1, complex c2){


complex c3;

c3.realnum = c1.realnum + c2.realnum;

c3.imagnum = c1.imagnum + c2.imagnum;

cout<<c3.realnum << c3.ch << c3.imagnum << c3.ch1;

void display(){

cout<<"The sum of two complex numbers is: ";

int main(){

complex c1(5,3);

complex c2(2,4);

add(c1,c2);

return 0;

You might also like