Code:
#include<iostream>
#include<math.h>
using namespace std;
class komplex{
private:
double real, imag,arg;
public:
komplex()
{
real=0;
imag=0;
arg=0;
}
~komplex()
{}
komplex(const komplex &);
komplex& operator=(const komplex &);
komplex& operator+(const komplex &);
komplex& operator-(const komplex &);
komplex& operator*(const komplex &);
komplex& operator/(const komplex &);
friend komplex& operator+(const komplex &,const komplex &);
friend komplex& operator-(const komplex &,const komplex &);
friend komplex& operator*(const komplex &,const komplex &);
friend komplex& operator/(const komplex &,const komplex &);
void set()
{
cout<<"real=";
cin>>real;
cout<<"imag=";
cin>>imag;
cout<<endl;
arg=atan(imag/real);
}
void print()
{
cout<<"real="<<real<<endl;
cout<<"imag="<<imag<<endl;
cout<<"arg="<<arg<<endl;
}
};
komplex::komplex(const komplex &a)
{
real=a.real;
imag=a.imag;
arg=a.arg;
}
komplex& komplex::operator=(const komplex &a)
{
real=a.real;
imag=a.imag;
arg=a.arg;
return *this;
}
komplex& komplex::operator+(const komplex &a)
{
real+=a.real;
imag+=a.imag;
arg=atan(imag/real);
return *this;
}
komplex& operator+(const komplex &a1,komplex &a2)
{
komplex x(a1);
x=x+a2;
return x;//ovako nece
}
komplex& komplex::operator-(const komplex &a)
{
real-=a.real;
imag-=a.imag;
arg=atan(imag/real);
return *this;
}
komplex& operator-(const komplex &a,komplex &b)
{
return a-b;//ovako isto nece
}
komplex& komplex::operator*(const komplex &a)
{
real*=a.real;
imag*=a.imag;
arg=atan(imag/real);
return *this;
}
komplex& operator*(const komplex &a,komplex &b)
{
return a-b;
}
komplex& komplex::operator/(const komplex &a)
{
if(a.real || a.imag)
{
real/=a.real;
imag/=a.imag;
arg=atan(imag/real);
return *this;
}
}
komplex& operator/(const komplex &a,komplex &b)
{
return a/b;
}
int main(int argc,char *argv[])
{
komplex x,y,z;
x.set();
y.set();
z=y;
z=x+y;
x=z*y;
y=x/z;
z.print();
return 0;
}
#include<iostream>
#include<math.h>
using namespace std;
class komplex{
private:
double real, imag,arg;
public:
komplex()
{
real=0;
imag=0;
arg=0;
}
~komplex()
{}
komplex(const komplex &);
komplex& operator=(const komplex &);
komplex& operator+(const komplex &);
komplex& operator-(const komplex &);
komplex& operator*(const komplex &);
komplex& operator/(const komplex &);
friend komplex& operator+(const komplex &,const komplex &);
friend komplex& operator-(const komplex &,const komplex &);
friend komplex& operator*(const komplex &,const komplex &);
friend komplex& operator/(const komplex &,const komplex &);
void set()
{
cout<<"real=";
cin>>real;
cout<<"imag=";
cin>>imag;
cout<<endl;
arg=atan(imag/real);
}
void print()
{
cout<<"real="<<real<<endl;
cout<<"imag="<<imag<<endl;
cout<<"arg="<<arg<<endl;
}
};
komplex::komplex(const komplex &a)
{
real=a.real;
imag=a.imag;
arg=a.arg;
}
komplex& komplex::operator=(const komplex &a)
{
real=a.real;
imag=a.imag;
arg=a.arg;
return *this;
}
komplex& komplex::operator+(const komplex &a)
{
real+=a.real;
imag+=a.imag;
arg=atan(imag/real);
return *this;
}
komplex& operator+(const komplex &a1,komplex &a2)
{
komplex x(a1);
x=x+a2;
return x;//ovako nece
}
komplex& komplex::operator-(const komplex &a)
{
real-=a.real;
imag-=a.imag;
arg=atan(imag/real);
return *this;
}
komplex& operator-(const komplex &a,komplex &b)
{
return a-b;//ovako isto nece
}
komplex& komplex::operator*(const komplex &a)
{
real*=a.real;
imag*=a.imag;
arg=atan(imag/real);
return *this;
}
komplex& operator*(const komplex &a,komplex &b)
{
return a-b;
}
komplex& komplex::operator/(const komplex &a)
{
if(a.real || a.imag)
{
real/=a.real;
imag/=a.imag;
arg=atan(imag/real);
return *this;
}
}
komplex& operator/(const komplex &a,komplex &b)
{
return a/b;
}
int main(int argc,char *argv[])
{
komplex x,y,z;
x.set();
y.set();
z=y;
z=x+y;
x=z*y;
y=x/z;
z.print();
return 0;
}
gdje grijesim uvijek mi javi gresku kad koristim neku od operacija koje sam ja definisao na komplexnim brojevima
Error 1 error C2666: 'komplex::operator +' : 3 overloads have similar conversions d:\c\refa\visual studio 2005\projects\matr-strukt\matr-strukt\program.cpp 68
to je error koji dobijem
ludim, uradio sam sabiranje, oduzimanje i mnozenje matrica, zapravo vi ste mi pomogli dodavanjem friend funkcija i to radi, ali ovo me izludje a ne znam u cemu je problem.
refa