Solution Review: Find Mean and Median
In this review, we give a detailed analysis of the solution to the problem of finding mean and median.
We'll cover the following...
Solution: Input and Output from .txt File
Explanation
This solution is a bit tricky, but don’t worry we will break it down for you.
Let’s begin from the driver code (line number 29).
Steps Performed:
-
Line number 30 - 32: Open the file and fetch all the lines in a variable.
-
Line number 34 - 38: Populate a vector to store inputs from the file.
-
Line number 40: Create a
resultvector. -
Line number 41 - 45: Find
meanandmedianusing their functions and store the output in theresultvector. -
Line number 47: Write the
resultvector onoutput/outData.txtfile.
mean() and median() functions are simple. They just take a vector, iterate over all the elements, and output the specific answer.
In the next lesson, we have another challenge for you to solve.