/////////////////////////////////////////////////////////////// // // // vec.cpp - vector class // // // // version: 1.0 // // Language: Visual C++, ver 5.0 // // Platform: Micron Dual Pentium Pro 200 // // Windows NT 4.0, service pack 3 // // Application: ELE591/791 Example // // Author: Jim Fawcett // // CST 2-187, (315) 443-3948 // // fawcett@neptune.syr.edu // // // /////////////////////////////////////////////////////////////// #ifdef TEST_VEC #include #include #include "vec.h" using namespace std; void main() { cout << "\n Testing vec constr, non-const indexing, bounds checking" << "\n =========================================================\n\n"; vec intVec(8); int i; for(i=-1; i<9; i++) intVec[i] = 3-i; intVec.display(cout,5,5); cout << "\n Testing vec array resizing" << "\n ============================\n"; cout << "\n expanding array: "; intVec.size(10); cout << "new size = " << intVec.size() << '\n'; intVec[8] = 5; intVec[9] = -5; intVec.display(cout,5,5); cout << "\n contracting array: "; intVec.size(5); cout << "new size = " << intVec.size() << '\n'; intVec.display(cout,5,5); // cout << "\n Testing copy and assignment operations" << "\n ========================================\n"; vec newIntVec = intVec; cout << "\n original intVec:\n"; intVec.display(cout,5,5); cout << "\n copy of intVec:\n"; newIntVec.display(cout,5,5); vec assignSrc(8); for(i=0; i<8; i++) assignSrc[i] = i-2; intVec = assignSrc; cout << "\n assignment source:\n"; assignSrc.display(cout,5,5); cout << "\n assignment target:\n"; intVec.display(cout,5,5); cout << "\n Testing insertion and extractions operators" << "\n =============================================\n\n"; cout << " writing vec to file inVec.tst\n"; ofstream out("inVec.tst"); if(!out.good()) { cout << " can't open file inVec.tst for writing\n"; return; } const int MAX = 15; vec test(MAX); for(i=0; i dblVec; in >> dblVec; cout << dblVec << endl; cout << "\n Testing scalar multiplication and vector addition:" << "\n ====================================================\n\n"; vec v1(5), v2(5); for(i=0; i<5; i++) { v1[i] = 3*i+2; v2[i] = 3-i; } cout << " vector v1:\n" << v1; cout << " 1.5*v1:\n" << 1.5*v1; cout << " vector v2:\n" << v2; cout << " v1 + v2:\n" << (v1+v2); cout << " v1 - v2:\n" << (v1-v2) << endl; } #endif