Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views4 pages

Oop Lab 6 Boo

The document contains a C++ program that defines a class for complex numbers, allowing for basic operations such as addition, subtraction, multiplication, and division. The program prompts the user to input real and imaginary parts of two complex numbers, performs the operations, and displays the results. The output demonstrates the operations with example inputs.

Uploaded by

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

Oop Lab 6 Boo

The document contains a C++ program that defines a class for complex numbers, allowing for basic operations such as addition, subtraction, multiplication, and division. The program prompts the user to input real and imaginary parts of two complex numbers, performs the operations, and displays the results. The output demonstrates the operations with example inputs.

Uploaded by

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

PROGRAM

#include<iostream>

using namespace std;

class complex

public:

int a,b;

void get()

cout<<"Enter real numbers: ";

cin>>a;

cout<<"Enter imaginary numbers: ";

cin>>b;

void display()

if(b<0)

cout<<a<<b<<"i"<<endl;

else

cout<<a<<"+"<<b<<"i"<<endl;

complex operator +(complex c)

complex c3;

c3.a=a+c.a;

c3.b=b+c.b;
return c3;

complex operator -(complex c)

complex c3;

c3.a=a-c.a;

c3.b=b-c.b;

return c3;

complex operator *(complex c)

complex c3;

c3.a=a*c.a;

c3.b=b*c.b;

return c3;

complex operator /(complex c)

complex c3;

c3.a=a/c.a;

c3.b=b/c.b;

return c3;

};

int main()

complex c1,c2,c3;

c1.get();

c1.display();

c2.get();

c2.display();
cout<<"The addition of complex numbers is : "<<endl;

c3=c1+c2;

c3.display();

cout<<"The subtraction of complex numbers is : "<<endl;

c3=c1-c2;

c3.display();

cout<<"The multiplication of complex numbers is : "<<endl;

c3=c1*c2;

c3.display();

cout<<"The division of complex numbers is : "<<endl;

c3=c1/c2;

c3.display();

return 0;

OUTPUT

Enter real numbers: 10

Enter imaginary numbers: 20

10+20i

Enter real numbers: 5

Enter imaginary numbers: 4

5+4i

The addition of complex numbers is :

15+24i

The subtraction of complex numbers is :

5+16i

The multiplication of complex numbers is :

50+80i

The division of complex numbers is :

2+5i
--------------------------------

Process exited after 14.12 seconds with return value 0

Press any key to continue . . .

You might also like