Object oriented programming

Hi,
working on an assignment we got at school.
And Im kind of stuck.
When i try to compile, I get an error message each time.
Tried different solutions to work around the problem,but diesnt seem to work.
We have been given a Main() prcedure that are supposed to work against the
files we are coding. Can't do changes to Main().
Is there anyone that can help me out?
Give me some advice?

I get an error referring to the call in the main procedure using this code:

void komplex::ganger(komplex &B)
{
double ar = finnRealdel();
double ai = finnImaginardel();
double br = B.finnRealdel();
double bi = B.finnImaginardel();
double Realdel = ((ar*br)-(ai*bi));
double Imaginardel = ((ar*bi)+(ai*bi));
//return Realdel,Imaginardel;
settKomplex(Realdel,Imaginardel);
return *this;
//settRealdel(Realdel);
//SettImaginardel(Imaginardel);

}

At these lines in the main I get an error:

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)

komplex C;
C = A.ganger(B);

The entire code is as follows:


Here is the Main procedure.

#include <iostream>
#include "komplex.h"
using namespace std;
void main()
{
komplex A(1,2);
cout << "A = " << A.findReal()
<< " + j(" << A.findImaginar() << ")";
cout << " = " << A.abs() << "/_ " << A.vink()
<< " rad" << endl;

komplex B(1,3);
komplex C;
C = A.ganger(B);
C.konjugert();
cout << "C = " << C.findReal()
<< " + j(" << C.findImaginar() << ")";

cout << endl;
system("pause");
}

Here is the Header file:
#pragma once
#include <iostream>
#include <cmath>

using namespace std;

class komplex
{
private:
double Realdel;
double Imaginardel;

public:
komplex();
komplex(
double initRealdel,
double initImaginardel);
double finnRealdel();
double finnImaginardel();
double abs();
double vink();
void ganger(komplex &B);
void konjugert();
void settRealdel(double);
void settImaginardel(double);
void settKomplex(double Real, double Imag);
};

Here are the implementations:

#include "komplex.h"

using namespace std;

komplex::komplex()
{
Realdel=0;
Imaginardel=0;
}

komplex::komplex(double initRealdel , double initImaginardel)
{
Realdel=initRealdel;
Imaginardel=initImaginardel;
}
void komplex::settKomplex(double Real, double Imag)
{
Realdel=Real;
Imaginardel=Imag;

}
double komplex::finnRealdel()
{
return Realdel;
}
double komplex::finnImaginardel()
{
return Imaginardel;
}
double komplex::vink()
{
const double Pi = 3.14159265358979;
double Real = finnRealdel();
double Imaginar = finnImaginardel();
double vinkelRad;
if (Realdel > 0)
{
vinkelRad = atan(Imaginar/Real);
}
else if (Realdel < 0)
{
vinkelRad = Pi+atan(Imaginar/Real);
}
else if (Real==0 && Imaginar > 0)
{
vinkelRad = Pi/2;
}
else if(Real==0 && Imaginar < 0)
{
vinkelRad = (Pi*-1)/2;
}
return vinkelRad;
}
double komplex::abs()
{
double abs=sqrt(pow(finnRealdel(),2)+pow(finnImaginardel(),2));
return abs;
}
void komplex::konjugert()
{
Imaginardel= finnImaginardel()*(-1);
}
void komplex::ganger(komplex &B)
{
double ar = finnRealdel();
double ai = finnImaginardel();
double br = B.finnRealdel();
double bi = B.finnImaginardel();
double Realdel = ((ar*br)-(ai*bi));
double Imaginardel = ((ar*bi)+(ai*bi));
//return Realdel,Imaginardel;
settKomplex(Realdel,Imaginardel);
return *this;
//settRealdel(Realdel);
//SettImaginardel(Imaginardel);

}
void komplex::settRealdel(double R)
{
Realdel = R;
}
void komplex::settImaginardel(double I)
{
Imaginardel = I;
}
Your function

 
void komplex::ganger(komplex &B)


is declared to return nothing (void), but you are attempting to assign the return value from that function to C here:

 
C = A.ganger(B);


(Though I notice that in the implementation of komplex::ganger(), you are attempting to return *this.)
Topic archived. No new replies allowed.