#include #include #include // include valarray from STL using namespace std; typedef valarray Vector; // define vector type // function to print vector to screen void print (const Vector& v) { cout << "["; for (int i=0; i<(int)v.size(); ++i) cout << " " << v[i]; cout << " ]" << endl; } int main () { Vector v(10); // create vector with 10 entries Vector w; // vector of length 0 so far v = 0; // set all entries to 0 v[0] = 1; // set some of the entries v[3] = -2.6; // ATTENTION: 0-based indices v[5] = -3.3; // entries range from v[0] to v[9] v[7] = 0.2; // v[10] is FORBIDDEN ! cout << "v = "; print (v); // print vector to screen w.resize (10); // make w a vector with 10 entries w = 0; w[0] = 1; w[3] = 9; w[9] = -0.5; cout << "w = "; print (w); // print "w" cout << "adding w to v..." << endl; v += w; // add w to v cout << "v = "; print (v); int n; do { cout << "please enter a natural number: "; cin >> n; } while (! (n > 0)); Vector u(n); // create a vector with the given length for (int i=0; i