#include<iostream>
#include<stdlib.h>
using namespace std;
class COMPLEX
{
float real,imag;
public:
void getinfo();
COMPLEX add(float,COMPLEX);
COMPLEX add(COMPLEX,COMPLEX);
void display(COMPLEX,COMPLEX);
};
void COMPLEX::getinfo()
{
cout<<"\nenter real and imaginary part for complex no\n";
cin>>real>>imag;
}
COMPLEX COMPLEX::add(float a,COMPLEX s1)
{
COMPLEX s3;
s3.real=a+s1.real;
s3.imag=s1.imag;
return s3;
}
COMPLEX COMPLEX::add(COMPLEX s1,COMPLEX s2)
{
COMPLEX s4;
s4.real=s1.real+s2.real;
s4.imag=s1.imag+s2.imag;
return s4;
}
void COMPLEX::display(COMPLEX s3,COMPLEX s4)
{
cout<<"\nsum = "<<s3.real<<" +i "<<s3.imag<<endl;
cout<<"\nsum = "<<s4.real<<" +i "<<s4.imag<<endl;
}
int main()
{
COMPLEX c1,c2,c3,c4,c5;
float a;
system("clear");
c1.getinfo();
c2.getinfo();
cout<<"enter an integer no\n";
cin>>a;
c3=c3.add(a,c1);
c4=c4.add(c1,c2);
c5.display(c3,c4);
return 1;
}
#include<stdlib.h>
using namespace std;
class COMPLEX
{
float real,imag;
public:
void getinfo();
COMPLEX add(float,COMPLEX);
COMPLEX add(COMPLEX,COMPLEX);
void display(COMPLEX,COMPLEX);
};
void COMPLEX::getinfo()
{
cout<<"\nenter real and imaginary part for complex no\n";
cin>>real>>imag;
}
COMPLEX COMPLEX::add(float a,COMPLEX s1)
{
COMPLEX s3;
s3.real=a+s1.real;
s3.imag=s1.imag;
return s3;
}
COMPLEX COMPLEX::add(COMPLEX s1,COMPLEX s2)
{
COMPLEX s4;
s4.real=s1.real+s2.real;
s4.imag=s1.imag+s2.imag;
return s4;
}
void COMPLEX::display(COMPLEX s3,COMPLEX s4)
{
cout<<"\nsum = "<<s3.real<<" +i "<<s3.imag<<endl;
cout<<"\nsum = "<<s4.real<<" +i "<<s4.imag<<endl;
}
int main()
{
COMPLEX c1,c2,c3,c4,c5;
float a;
system("clear");
c1.getinfo();
c2.getinfo();
cout<<"enter an integer no\n";
cin>>a;
c3=c3.add(a,c1);
c4=c4.add(c1,c2);
c5.display(c3,c4);
return 1;
}
No comments:
Post a Comment