STLIteratorDemo

STLIteratorDemo - } double...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> #include <fstream> #include <cmath> #include <list> using namespace std ; double average(list<int>& l); double variance(list<int>& l, double avg); int main () { list<int> l; cout << "Enter some numbers: "; while(true) { int val; cin >> val; if(!cin) break; l.push_back(val); } double avg = average(l); cout << endl << "Input has average " << avg << " and variance " << variance(l, avg) << endl;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } double average(list&lt;int&gt;&amp; l) { double sum = 0; int count = 0; for(list&lt;int&gt;::iterator i = l.begin(); i != l.end(); i++) { sum += *i; count++; } return sum / count; } double variance(list&lt;int&gt;&amp; l, double avg) { double sum = 0; int count = 0; for(list&lt;int&gt;::iterator i = l.begin(); i != l.end(); i++) { sum += pow((*i - avg), 2); count++; } return sum / count; }...
View Full Document

Page1 / 2

STLIteratorDemo - } double...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online