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

Need help ASAP please, So I have create the implementation portion of the comple

ID: 3772455 • Letter: N

Question

Need help ASAP please, So I have create the implementation portion of the complex class described in the complex definition file "complex.h"

What I have thus far is include below class, the ones I can't I figure out are highlighted could you please correct?

#ifndef COMPLEX_H
#define COMPLEX_H


class complex {

public:
complex();
complex(double a);
complex(double a,double b);
complex(int a,int b);
void print() const;
void set(double a=0,double b=0);
void set(int a=0,int b=0);
double getReal() const;
double getImag() const;
void get(double&,double&) const;

complex operator+ (double&);
complex operator+ (complex&);
complex operator+= (complex&);
complex operator+= (int&);
complex operator++ (int);
complex operator++ ();
complex operator- (double&);
complex operator- (complex&);
complex operator-= (complex&);
complex operator-= (double&);
complex operator-- (int);
complex operator-- ();
complex operator* (complex&);
complex operator* (double&);
complex operator*= (complex&);
complex operator*= (double&);
complex operator/ (complex&);
complex operator/= (complex&);
complex operator/= (double);
complex operator/ (double);
void operator= (const complex&);
bool operator== (complex&);
bool operator!=(complex &c);
friend std::istream &operator>> (std::istream &in, complex& c);
friend std::ostream &operator<<(std::ostream &out, complex c);

complex conj() const;
double norm() const;
double modulus() const;

private:
double real;
double imag;
};

#endif // COMPLEX_H

#include
#include "complex.h"
#include


using namespace std;


complex::complex(){
real = 0;
imag = 0;
}

complex::complex(double a){
real=a;
imag = 0;
}

complex::complex (double a, double b){
real=a;
imag=b;
}

complex::complex (int a, int b){
real=a;
imag=b;
}

complex complex::operator+ (double& a){
return complex(real + a, imag);
}

complex complex::operator+ (complex& a){
return complex(real + a.real, imag + a.imag);
}
complex complex::operator+= (complex& a){
return complex (real+=a.real, imag+=a.imag);
}

complex complex::operator+= (int& a){
return complex (real+=a, imag);
}
complex complex::operator++ (int a){
return complex (real, imag);
}

complex complex::operator++ ( ){
complex a=complex(real, imag);
real+=1;
return a;
}
complex complex::operator- (double& a){
return complex(real + a, imag);
}
complex complex::operator- (complex& a){
return complex(real - a.real, imag - a.imag);
}
complex complex::operator-= (complex& a){
return complex (real-=a.real, imag-=a.imag);
}
complex complex::operator-= (double& a){
return complex (real-=a.real, imag);
}

complex complex::operator-- (int a){
return complex (real--=a.real, imag);
}

complex complex::operator-- (a){
return complex (real--=a.real);
}


complex complex::operator* (complex& a){
return complex(real * a.real- imag* a.imag, real*a.imag +imag*a.real);
}

complex complex::operator* (double& a){
return complex(real * a.real- imag* a.imag, real*a.imag +imag*a.real);
}

complex complex::operator*= (complex& a)
return complex (real*=a.real, imag*=a.imag);


complex complex::operator*= (double& a){
return complex(real*= a, imag);
}

complex complex:: operator/ (complex& a){
double norm2 = a.real*a.real + a.imag*a.imag;
return complex((real*a.real - imag*a.imag)/norm2, -(real*a.imag + imag*a.real)/norm2);
}

complex complex::operator/= (complex& a){
return complex(real /= a.real, imag /= a.imag);
}
complex complex:: operator/= (double a){
return complex(real /= a.real, imag);
}
complex complex::operator/ (double a){
return complex(real / a.real, imag );
}

void operator= (const complex a&){
real=a.real;
imag=a.imag;
}
bool operator== (complex&);
complex& complex::operator==(complex& ){

if ((real == a.real) && (imag == a.imag))
return true;
else
return false;
  
bool operator!=(complex &c);
bool complex complex::operator!=(complex &c){

if ((real != a.real) && (imaginary != a.imag))
return true;
else
return false;
friend istream& operator >> (istream &in, complex& c){
in >>a.real
in >>a.imag

return complex(in);
}

friend ostream &operator <<(std::ostream &out, complex c){
out < out< return complex(out);
}

complex complex::conj() {
return complex(real,-imag)
}


complex complex::double norm(){
return sqrt(real*real + imag *imag);
}

complex complex::double modulus(){
return sqrt(real*real + imag *imag);
}
int main()
{

return 0;

Explanation / Answer

#include "complex.h"
#include<math.h>
int main()
{
   complex c1(1,2);
   c1.print();
   double d=2;
   complex c3=c1/d;
   c3.print();
   c1/=d;
   c1.print();
   return 0;  
}

complex::complex()
{
   real=0;
   imag=0;
}
complex::complex(double a)
{
   real=a;
}
complex::complex(double a,double b)
{
   real=a;
   imag=b;
}
complex::complex(int a,int b)
{
   real=a;
   imag=b;
}
void complex::print() const
{
   cout<<real<<"+i "<<imag<<endl;
}
void complex::set(double a,double b)
{
   real=a;
   imag=b;
}
void complex::set(int a,int b)
{
   real=a;
   imag=b;
}
double complex::getReal() const
{
   return real;
}
double complex::getImag() const
{
   return imag;
}
std::ostream& operator<< (std::ostream& out, complex const& value) {
    return out << value.getReal() << " " << value.getImag();
}

std::istream& operator>> (std::istream& in, complex& c) {
    double h, j;
    if (in >> h >> j) {
        c.set(h, j);
    }
    return in;
}

void complex::get(double& a,double& b) const
{
   a=getReal();  
   b=getImag();
}
complex complex::operator+ (double&a)
{
   return complex(real+a,imag);
}
complex complex::operator+ (complex&c)
{
   return complex(real+c.real,imag+c.imag);
}

complex complex::operator+= (complex&c)
{
   return complex(real+=c.real,imag+=c.imag);
}

complex complex::operator+= (int&i)
{
   return complex(real+=i,imag+=i);
}

complex complex::operator++ (int i)
{
   return complex(real++,imag++);
}

complex complex::operator++ ()
{
   return complex(++real,++imag);
}
complex complex::operator- (double&i)
{
   return complex(real-i,imag);
}
complex complex::operator- (complex&c)
{
   return complex(real-c.real,imag-c.imag);
}
complex complex::operator-= (complex&c)
{
   return complex(real-=c.real,imag-=c.imag);
}
complex complex::operator-= (double&d)
{
   return complex(real-d,imag-d);
}
complex complex::operator-- (int i)
{
   return complex(real--,imag--);
}
complex complex::operator-- ()
{
   return complex(--real,--imag);
}

complex complex::operator* (complex&c)
{
   return(complex(   (real*c.real-imag*c.imag), (real*c.imag+imag*c.real) ));
}
complex complex::operator* (double&d)
{
   return(complex(real*d, imag));
}
complex complex::operator*= (complex&c1)
{
   complex c2;
   c2.real=(real*c1.real-imag*c1.imag);
   c2.imag=(real*c1.imag+imag*c1.real);
   return (real=c2.real,imag=c2.imag);  
}
complex complex::operator*= (double&d)
{
   real=real*d;
   imag=imag;
   return complex(real,imag);
}
complex complex::operator/ (complex&c)
{
   return(complex( ( (real*c.real+imag*c.imag) / (c.real*c.real + c.imag*c.imag) ), (    (imag*c.real-real*c.imag) / (c.real*c.real + c.imag*c.imag) )));
}
complex complex::operator/= (complex&c)
{
   complex c2;
   c2.real=(real*c.real+imag*c.imag) / (c.real*c.real + c.imag*c.imag);
   c2.imag= (imag*c.real-real*c.imag) / (c.real*c.real + c.imag*c.imag);
   return (real=c2.real,imag=c2.imag);  
}
complex complex::operator/= (double d)
{
   real=real/d;
   imag=imag;
   return complex(real,imag);
}
complex complex::operator/ (double d)
{
   return(complex(real/d, imag));
}
void complex::operator= (const complex&c)
{
   real=c.real;
   imag=c.imag;
}
bool complex::operator== (complex&c)
{
   if(c.real==real && c.imag==imag)
   {
       return true;
   }
   else
   {
       return false;
   }
}
bool complex::operator!=(complex &c)
{
   if(c.real!=real || c.imag!=imag )
   {
       return true;
   }
   else
   {
       return false;
   }
}
complex complex::conj() const
{
   return complex(real,(-1*imag));
}
double complex::norm() const
{
   return ((real*real)+(imag*imag));
}
double complex::modulus() const
{
   return (sqrt((real*real)+(imag*imag)));
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote