Skip to content

Instantly share code, notes, and snippets.

@lazypower
Created May 1, 2011 19:27
Show Gist options
  • Save lazypower/950769 to your computer and use it in GitHub Desktop.
Save lazypower/950769 to your computer and use it in GitHub Desktop.
// TO save time i'm going with a single file class. Prototyped at the top, defined at the bottom.
#ifndef COMPLEX_H
#define COMPLEX_H
#include <iostream>
using namespace std;
class Complex
{
public:
Complex();
Complex( double, double );
Complex add( Complex & );
Complex subtract ( Complex & );
void printComplex();
private:
void setReal( double );
void setImaginary( double );
double getReal();
double getImaginary();
double real;
double imaginary;
};
#endif
Complex::Complex()
{
setReal(0);
setImaginary(0);
}
Complex::Complex ( double real, double imaginary )
{
setReal(real);
setImaginary(imaginary);
}
Complex Complex::add( Complex &right )
{
// stuff goes here
return Complex(getReal() + right.getReal(), getImaginary() + right.getImaginary());
}
Complex Complex::subtract( Complex &right )
{
}
void Complex::setReal( double real )
{
Complex::real = real;
}
void Complex::setImaginary( double imaginary )
{
Complex::imaginary = imaginary;
}
double Complex::getReal()
{
return Complex::real;
}
double Complex::getImaginary()
{
return Complex::imaginary;
}
void Complex::printComplex()
{
cout << '(' << real << ", " << imaginary << ")";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment