Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, my proffesor says this is wrong.... \" Why are you printing on every func

ID: 3772361 • Letter: H

Question

Hello,
my proffesor says this is wrong.... " Why are you printing on every function. This is not right" i am very confused now can someone help me?

This are the instructions:
Create the implementation portion of the complex class described in the complex definition file "complex.h"
Thank you!

#include <iostream>

#include <cmath>
#include "complex.h"//header file

using namespace std;
complex::complex()

{//constructor without argument present in complex
real=0;
  
imag=0;
cout<<"real="<<real<<", imag="<<imag<<endl;
}
complex::complex(double a)

{//constructor with one argument
  
real=a;
  
imag=a;
cout<<"real="<<real<<"imag"<<imag<<endl;
  
}

complex::complex(double a,double b)

{//constructor with two arguments
  
real=a;
  
imag=b;
cout<<"real="<<real<<","<<"imag="<<imag<<endl;
  
}

complex::complex(int a,int b)

{//constructor with two arguments
  
real=a;
  
imag=b;
cout<<"real="<<real<<","<<"imag="<<imag<<endl;   
}
double complex::getImag() const

{//class complex contains getImage method
  
return imag;
cout<<"imag="<<imag<<endl;
  
}
double complex::getReal() const

{//getReal method present in complex class
  
return real;
  
}
void complex::print() const

{//print method in complex
  
cout<<getReal()<<"+j"<<getImag()<<endl;
  
}



void complex::get(double& a,double& b) const

{//constructor with object arguments
  
a=real;
  
b=imag;
cout<<"a="<<a<<"b="<<b<<endl;
  
}
complex complex:: operator+ (double& a)

{//opeator overloading with object argumnet
  
return complex(a+real, a+imag);
  
  
}
complex complex::operator+ ( complex& c2)

{//operating overloading with constructor as object
  
return complex(real+c2.real+imag+c2.imag);
  
}
complex complex:: operator*= (double& a)

{//operator overloading *
  
real=real*a;
  
imag=imag*a;
  
return *this;
  
}
complex complex:: conj() const

{//conj method in complex
  
return complex(real,-imag);
  
}



double complex::norm() const

{//norm method in complex
  
return (real*real+imag*imag);
  
}
double complex :: modulus() const

{
  
  
cout<<"sqrt(real*real+imag*imag)="<<sqrt(real*real+imag*imag);
  
}
ostream &operator<<(std::ostream &out, complex c)

{
  
out<<"Complex Number is"<<endl;
  
out<<c.real<<"+j"<<c.imag;
  
return out;
  
}

int main(){

complex c;//calling all methods in class complex
complex c1(1.3);
complex c2(1.2,1.4);
complex c3(10,20);
complex c4;
c4.getImag();
complex c5;
c5.getReal();
complex c6;
c6.print();
double x(10);
double y(10);
complex c7;
c7.get(x,y);
double m(10.23);
double n(20.12);
double o=m+n;
cout<<"o="<<o<<endl;
complex c8(10);
complex c9(20);
complex c10=c8+c9;
double f(10.23);
double g(20.12);
double h=f*g;
cout<<"h="<<h<<endl;
complex c11;
c11.conj();
c11.norm();
c11.modulus();
double k(1.2);
complex c12(12);
return 0;
}

Explanation / Answer

remove the cout statemnets in all constructors and create a new function and when you have to output the values call that fuction simply.

Dr Jack
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote