Question
C++ function and iostream question?
I am looking at the second function that is necessary to compute the averages from the text file Programming_Score.txt and I cannot figure out how to select the first 14 numbers in a row and use them to find averages, the next appropriate group to find averages for and so forth.? My only solution that I can find is to assign each input (all 270 numbers) to variables and manipulate them manually.? Is there a code that I am missing that lets the user only select the first fourteen columns in a row to use and manipulate?
Also for a more in depth explanation. I am taking in 27 characters from each row of 10 rows for a total of 270 different numbers. We are supposed to take numbers 1-14 of each row and find the average for each line. Each row represents a students grade on homework. next take Colimns 15-17 and find the average for each row. Then take Colimns 18-26 and do the same thing. And then finally number in column 27 is it's own value. How should my code go to select the vales for the first 14 and then average and do this for the next row and so forth. I am completely lost and have read my textbook and emailed the teacher. Please help
Answer
To deal with this problem you need a ifstream to read the file, STL container like vector to organize the line captured, a few loops to get line from files, go through each grade on each line, so..
1. set up a string vector as container
2. open ifstream
3. use a while loop to read all lines to the vector
4. make 3 nested loops for each of the specified column ranges, the outer loop should go through each line while the inner loop go through each character
5. as going through each character/grade, sum them up and get the average on the last loop, print out the result of the average for that line
6. after finishing each of the 3 column ranges, reset the total to zero for the next column range calculation
If you still not sure how, here's a workable code with the text input file, download them to see how the above is done.
http://drop.io/orkd6fd

Ask

