So I need to create a modular class (a header, source and main file to implement this program). I have started the header file but not sure how to define the getters and setters.
So far I have created my header, source and main files
I think my header is good, I am questioning my use of the length and print function, I am unsure how to correctly implement in the sources and call in the main. Any ideas?
Line 9: remove. With both a default constructor and a constructor where all arguments have defaults, it's ambiguous which one should be called.
Line 10: public should be followed by a colon, not a semicolon.
Line 13: ); should be ):
Line 36: You need a semicolon after all declarations.
Getr() and Geti(): These should be returning the real and imaginary parts of the class. Check what those values are named.
Lines 88-97. It's hard to know how to define the function without knowing what it's supposed to do. It's declared like a default constructor. Lines 91&92 look like they are trying to compute the dot function. Line 94 looks like it's computing the absolute value of the complex number. I suggest that you comment out this entire function. The only reason not to delete it is because you might want to use some of the code later.
Ideally, the Print() function would be replaced by a << operator, but let's leave that for now. You should change it to be a member function.
Okay, those are enough compiler errors for now. The basic problem here is that you wrote a lot of code before testing any of it. Here is a copy with most of the functionality and main program #if 'ed out. Get this working. Then move the #if 0 in main() down past the next section. Get the newly exposed section working and repeat the process until everything works. Keep in mind that at each step the any problems you have are NOT in the section that is #if'ed out.
You define methods GetR() and GetI() but you call then with getR() and getI(). All names in C++ are case sensitive so you need to be consistent. I'd change to getR() and getI() because it involves fewer edits.
Line 96 should be return Complex(c.getR()+getR(), c.getI()+getI());
Line 101 should be real += c.getR(); imag +=c.getI();
Line 107: what is getY()?
There's a pattern here: GetR(), getR, getY(), these are all just incorrect method names. Programming requires you to be very specific, much more so that human interactions. Pay close attention to names and be sure to us the right names, the right way.
Lines 111 to 119: the math is wrong. You should review how to multiply and divide complex numbers.
Line 126: sgrt should be sqrt While this code works fine, you should know that it's faster to square a number by multiplying it by itself. The pow() function works with any real numbers and is thus pretty complex. So this would be better written as return (sqrt(real*real + imag*imag));