// Oldham, Jeffrey D. // 2000 Feb 21 // CS1321 // // Modified by: // Massingill, Berna L. // 2001 Feb and 2001 Oct // // Example of code using MVector class // #include #include // has EXIT_SUCCESS #include "mvector.h" using namespace std; int main(void) { // Declaring vectors and assigning values to elements. MVector m; cout << "An empty vector's original dimensionality is " << m.dim() << endl; m.redimension(4); cout << "The vector should now have four elements: " << m.dim() << endl; m.set(0, 1.1); m.set(1, 2.1); m.set(2, 3.1); m.set(3, 4.1); cout << "The vector's contents: " << m << endl; MVector n(m); cout << "The copied vector's contents should be the same: " << n << endl; MVector p(4); cout << "A vector declared with dimensionality 4 has dimensionality " << p.dim() << endl; p.set(0, 5.1); p.set(1, 6.1); p.set(2, 7.1); p.set(3, 8.1); cout << "The second vector's contents: " << p << endl; // Arithmetic operations on vectors. cout << "addition: " << m + p << endl; cout << "subtraction: " << m - p << endl; cout << "dot product: " << m * p << endl; cout << "scale by 2: " << 2 * m << endl; cout << "again: " << m * 2 << endl; cout << "add second vector to first, changing first vector: "; m += p; cout << m << endl; cout << "scale first vector, changing it: "; m *= 2; cout << m << endl; cout << "length of m = " << m.length() << endl; // Relational operations on vectors. if ((m == m) && !(m != m)) cout << "A vector equals itself\n"; if ((m != p) && !(m == p)) cout << "Two different vectors are not equal\n"; // Input operation on vector. MVector q(4); cout << "Enter four numbers for vector:\n"; cin >> q; cout << "The vector is " << q << endl; return EXIT_SUCCESS; }