// A2_5.cpp #pragma warning(disable : 4786) #include #include #include using namespace std; // return type of T will also work, but may // not return what you want for integers template double getAvg(const vector &v) { T sum = 0; vector::const_iterator it; for(it=v.begin(); it!=v.end(); it++) sum += *it; double avg = sum/v.size(); return sum; } void main() { double da[] = { 3.5, -7.8, 2.6 }; vector v(&da[0],&da[3]); cout << "\n avg = " << getAvg(v) << "\n\n"; }