/////////////////////////////////////////////////////////////// // iter1a.cpp -- first STL iterator demo // // // // Jim Fawcett, 4/4/98 // /////////////////////////////////////////////////////////////// #include #include #include #include #ifdef use_std_complex #include #endif using namespace std; #ifndef use_std_complex template class complex { public: complex(T real=0, T imag=0) : _real(real), _imag(imag) { } complex(const complex &c) : _real(c._real), _imag(c._imag) { } ~complex() { } complex& operator=(const complex &c) { _real = c._real; _imag = c._imag; return *this; } T& real() { return _real; } T& imag() { return _imag; } private: T _real; T _imag; }; #endif // void main() { #ifdef use_std_complex cout << " using std::complex\n"; #else cout << " user defined complex\n"; #endif vector< complex > vc; vc.push_back(complex( 1, 0)); vc.push_back(complex( 1, 1)); vc.push_back(complex( 0, 1)); vc.push_back(complex(-1, 1)); vc.push_back(complex(-1, 0)); vc.push_back(complex(-1,-1)); vc.push_back(complex( 0,-1)); vc.push_back(complex( 1,-1)); vc.push_back(complex( 1, 0)); const double pi = 3.1415927; vector< complex >::iterator vci; double angle; for(vci=vc.begin(); vci != vc.end(); vci++) { angle = atan2(vci->imag(),vci->real())*(180.0/pi); cout << " " << "(" << setw(2) << (*vci).real() << "," << setw(2) << (*vci).imag() << ")" << setw(6) << angle << "\n"; } cout << endl; }