0% found this document useful (0 votes)
3 views

Rohini Pract 1.cpp

Se Artificial intelligence and data science

Uploaded by

tejasrahane27
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)
3 views

Rohini Pract 1.cpp

Se Artificial intelligence and data science

Uploaded by

tejasrahane27
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/ 2

#include<iostream>

using namespace std;


class complex
{
int real, imag;
public:
complex()
{
real=0;
imag=0;
}
void read()
{
cout<<"\n enter real and imag part";
cin>>real>>imag;
}
void display()
{
cout<<real<<"+"<<imag<<"i";
}
complex operator +(complex c2)
{
complex c3;
c3.real=real+c2.real;
c3.imag=imag+c2.imag;
return c3;
}
complex operator *(complex c2)
{
complex c4;
c4.real=(real*c2.real)+(imag*c2.imag);
c4.imag=(real*c2.imag)+(imag*c2.real);
return c4;
}
};
int main()

{
complex c1,c2,c3,c4;
int ch;
char choice;
do
{
cout<<"\n 1. read complex numbers\n 2. Add two complex numbers \n 3.Multiply
two complex number";
cout<<"\n enter your choice ";
cin>>ch;
switch(ch)
{
case 1: c1.read();
c2.read();
break;
case 2:
c3=c1+c2;
c1.display();
c2.display();
cout<<"\n Addition";
c3.display();
break;
case 3:c4=c1*c2;
c1.display();
c2.display();
cout<<"\n Multiplication";
c4.display();
default:cout<<"\n Invalid choice";

}
cout<<"\n Do you want to continue(y/n)";
cin>>choice;
}while(choice=='y');
return 0;
}

You might also like