Lessons 21–25 · About 60 min per lesson
Sorting and basic statistics
Order a batch and explain it with totals, maximums and means.
Lesson breakdown
- Lesson 21
Sort a vector in ascending order with std::sort.
- Lesson 22
Locate minimum, maximum and middle positions in sorted results.
- Lesson 23
Add large integer totals with long long.
- Lesson 24
Convert to double and print the mean at the required precision.
- Lesson 25
Check duplicate values, even-sized batches and empty input.
Worked example
Sort scores 5, 2, 2 and 4 and compute the mean.
How to solve it
The sorted order is 2, 2, 4, 5. A total of 13 divided by 4 gives 3.25 with floating-point division.
Assignment
Print sorted scores and the mean to two decimal places, or Empty for an empty batch.
Check your result
[5,2,2,4] → 2 2 4 5 and 3.25; [8] → 8 and 8.00.