#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

//Since vectors are NOT automatically passed by reference
//the & is necessary (& v)
void read (istream & in, vector<int> & v, int & n)
{
	int number;
	n=0;
	while (in>>number)
	{
		v.resize(++n);	//Vectors allow dynamic sizing of the list!
		v[n-1]=number;
	}
}

int average (vector <int> v, int n)
{
	int sum=0;
	for (int k=0; k<n; k++)
	{
		sum+=v[k];
	}
	return sum/n;
}

void write (ostream & out, vector<int> v, int n)
{
	for (int k=0; k<n; k++)
	{
		out << v[k] << endl;
	}
}

int main()
{
	vector<int> 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;
}

