#include #include #include using namespace std; //Since vectors are NOT automatically passed by reference //the & is necessary (& v) void read (istream & in, vector & v, int & n) { n=0; int number; while (in>>number) { v.resize(++n); //Vectors allow dynamic sizing of the list! v[n-1]=number; } } //The advantages of pass by reference, //namely, the economic use of memory, //together with the safety of pass by value //can be achieved by the joint use of const and & int average (const vector & v, const int & n) { int sum=0; for (int k=0; k & v, const int & n) { for (int k=0; k v; ifstream fin ("list.txt"); ofstream fout ("list_out.txt"); int n; read (fin, v, n); write (fout, v, n); fout << "The average of the " << n << " items in the list is: " << average (v, n) << endl; return 0; }