Hello,

I am working on this program and am having problems trying to figure out how to display my results. I know I need to create a void display() option, but I'm not sure what to define within it.... Here's what I have....

class Complex
{
	public:
		Complex(int r = 0, int i = 0);
		Complex(Complex const &);
		void display() const;
		int getReal()const;
		int getImag() const;

	private:
		int real, imag;
};
Complex const add(Complex const &first, Complex const &second);

#endif

#include "complex.h"

Complex getComplexNumber()
{
	cout << "Enter two integer values: ";
	int real, imag;
	cin >> real >> imag;
	return Complex(real, imag);
	
}
Complex::Complex(int r, int i)
{
	real = r;
	imag = i;
}
Complex::Complex(Complex const &arg)
{
	real = arg.real;
	imag = arg.imag;
}
int Complex::getReal()const
{
	return real;
}
int Complex::getImag()const
{
	return imag;
}
Complex const add(Complex const &first, Complex const &second)
{
	return Complex(first.getReal() + second.getReal(), first.getImag() + second.getImag());
}

and finally ...my main() ...

int main ( )
{
	Complex const c1(-1, 2), c2(3, -4), c3(c1), c4(c2), c5;
	Complex sum(add(c3, c4));
	//sum.display();
}

And yes, this is homework....

Thanks,

K.

Within the display( ) method for your class, simply do the output of the object's real and imag data members, with whatever formatting you want to see.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.