Yup. That's more like what they are asking you to do. Hope that clear up a bit and allows yout to start seeing the possible advantages of using structs and classes as a means to simplify the description of data and its manipulation.
For completeness you should observe the question requirements, which include also calculating the min and max values and store them in the struct.
Meanwhile:
- Your median calculation contains unnecessary code. You don't need to cycle through the vector. Just to sort and calculate. Note your for loop body is not making any use of i, neither it is accumulating the result of the calculation, which clearly indicates you don't need the loop. Just the calculation.
- If you already went through algorithms, you should know you can simplify some calculations by taking advantage of these. For instance,
double sum = accumulate(results.v.begin(), results.v.end(), 0); will return the sum of all values in the vector. Check the
STL Algorithms.
EDIT:
One small side note. It's perhaps best if you replace the ternary operator in your median calculation with the
if statement. Ternary operators are nice, but when they force you to a lengthy line, loose readability.