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

Compiler 2

The document contains a C++ program that defines a class for complex numbers with methods for summation and display. It demonstrates the creation of complex number objects, their summation, and outputs the results. The output shows the values of three complex numbers A, B, and C after performing the sum operation.

Uploaded by

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

Compiler 2

The document contains a C++ program that defines a class for complex numbers with methods for summation and display. It demonstrates the creation of complex number objects, their summation, and outputs the results. The output shows the values of three complex numbers A, B, and C after performing the sum operation.

Uploaded by

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

// Online C++ compiler to run C++ program online

// Compiler program

#include <iostream>

using namespace std;

class complex

float x,y;

public:

complex(){}

complex(float a){x=y=a;}

complex(float real,float imag)

x=real;

y= imag;

friend complex sum(complex, complex);

friend void show(complex);

};

complex sum(complex c1, complex c2)

complex c3;

c3.x =c1.x + c2.x;

c3.y =c1.y + c2.y;

return(c3);

void show(complex c)

cout<< c.x<<" + j"<<c.y<<"\n";

int main ()

{
complex A(2.7, 3.5);

complex B(1.6);

complex C;

C=sum(A,B);

cout<<"A="; show(A);

cout<<"B= "; show(B);

cout<<"C= "; show(C);

return 0;

Output:

A=2.7 + j3.5

B= 1.6 + j1.6

C= 4.3 + j5.1

You might also like