Why are you creating your own class for complex numbers while the
C++
standard library already provides one?
In the following code, a sequence of complex numbers is created and then an iteration over the sequence items is performed.
#include <iostream>
#include <complex>
#include <vector>
using namespace std;
using Complex = complex < double >;
void dump( const vector < Complex > & v);
int main()
{
size_t v_size;
cout << "please enter the size of the array: ";
cin >> v_size;
vector< Complex > v;
for (size_t n=0; n<v_size; ++n) {
double re, im;
cout << "complex no. " << (n+1) << ", real part: ";
cin >> re;
cout << "complex no. " << (n+1) << ", imaginary part: ";
cin >> im;
v.emplace_back(Complex(re, im));
}
dump(v);
}
void dump( const vector < Complex > & v)
{
for (const auto & c : v)
cout << c << " ";
cout << "\n";
}