Simple class exercise - min, max, and average of vector items This program calculates the min and the max value and the average of the items of a vector. It's an exercise from a book so I can't change the header file. 

Is this code proper? 

sales.h

#include &lt;vector&gt;

class Sales
{
    private:
        std::vector&lt;double&gt; sales;
        double average;
        double maximum;
        double minimum;
        double calcAvg();

    public:
        Sales(const std::vector&lt;double&gt; ar);
        void setSales();
        void showSales() const;
};


sales.cpp

#include "sales.h"
#include &lt;iostream&gt;
#include &lt;algorithm&gt;

Sales::Sales(const std::vector&lt;double&gt; ar)
{
     sales = ar;
     minimum = *std::min_element(sales.begin(), sales.end());
     maximum = *std::max_element(sales.begin(), sales.end());
     average = calcAvg();
}

void Sales::setSales()
{
    std::vector&lt;double&gt; temp;
    std::cout &lt;&lt; "Enter values separated by a space: ";
    for (int i = 0; i &lt; 4; i++)
    {
        int item;
        std::cin &gt;&gt; item;
        temp.push_back(item);
    }
    *this = Sales(temp);
}

void Sales::showSales() const
{
    for(std::size_t i = 0; i &lt; sales.size(); i++)
        std::cout &lt;&lt; "Item " &lt;&lt; i &lt;&lt;" = " &lt;&lt; sales.at(i) &lt;&lt; std::endl;
    std::cout &lt;&lt; "Average: " &lt;&lt; average &lt;&lt; std::endl;
    std::cout &lt;&lt; "Min, max: " &lt;&lt; minimum &lt;&lt; " , " &lt;&lt; maximum &lt;&lt; std::endl;
}

double Sales::calcAvg()
{
    double sum;
    for(std::size_t i = 0; i &lt; sales.size(); i++)
       sum += sales.at(i);
    return sum/sales.size();
}


program.cpp

#include "sales.h"
#include &lt;vector&gt;

int main()
{
    std::vector&lt;double&gt; ar;
    ar.push_back(4);
    ar.push_back(5);
    ar.push_back(23);

    Sales s1(ar);
    s1.showSales();

    Sales s2;
    s2.setSales();
    s2.showSales();
    return 0;
}
First, of all, this class has a setSales member much like the setgolf member of the class you posted in your last question.  I think it suffers from all the same issues that I've mentioned; there's not really anything I can add, so I'll leave those comments to represent this, too.

Now to the main issue, which I'd say is the calcAvg member.  It should in any case be const; finding and caching the average of a vector doesn't change external state, and were you to ever print the vector (without first modifying it) you'd come to the same result.

As things are, calcAvg doesn't need access to most of the members of Sales.  It looks to me like you should just write a free average function template that takes an std::vector&lt;T&gt; const&amp; and returns the average (of type T).

Also, about the caching: whether you should do this or not depends on how the class is used.  I wouldn't expect this class to be used as such, but you know better.  I would delay it until the thing is printed; in that case, you'd have to make your minimum, average and maximum all mutable, and probably also of type std::atomic&lt;double&gt;.  This isn't necessarily better: look at the usage and choose.

Finally, as a minor detail, there's no need to use at when you can easily prove that the index is in-bounds anyway, and you can use std::accumulate for calculating the average.