0

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.

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by vmanes
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.