I have to make a program that read this :
(name) (test1..2..3...etc)
Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
Cooper 78 91 11 90 73
Gupta 92 83 30 69 87
Blair 23 45 96 38 59
Clark 60 85 45 39 67
Kennedy 77 31 52 74 83
Bronson 93 94 89 77 97
Sunny 79 85 28 93 82
Smith 85 72 49 75 63

from a file and then make an output file that has 8 column that include the name, each test, average of the tests and then the letter grade.

The problem requires a void function used for calculating the average and a value function for the letter grade.

I know how to do this without the functions, but im in a knot when I have to use functions.

I was thinking if in the calculating average function to assign the average of each line to a separate variable and use a while loop to do that. I am not sure if that is an effiecent way to do that. Ill post up the code once try it out. But for now, can anoyone tell how they would a approach this problem?

If a function is void, the only way you can display the result is to write to console immediately right after the calculation. In this case, while you are displaying each row, at the last column, which is the letter grade, call the function (may pass in total score depending on how you implement your variable). In the function, compute the grade from total and display it.

If a function is void, the only way you can display the result is to write to console immediately right after the calculation. In this case, while you are displaying each row, at the last column, which is the letter grade, call the function (may pass in total score depending on how you implement your variable). In the function, compute the grade from total and display it.

Actually not true:

``void calcAverage( double* gradeArray, int arrayLength, double& average );``

You can use a void function to modify local variables if you pass the variables by reference. This is most useful if you need to have a function return more than one value:

``void calcMeanAndStdv( double* gradeArray, int arrayLength, double& mean, double& stdv );``

This way, you can have the function calculate the value of the mean and standard deviation in one function.

I was thinking if in the calculating average function to assign the average of each line to a separate variable and use a while loop to do that. I am not sure if that is an effiecent way to do that. Ill post up the code once try it out. But for now, can anoyone tell how they would a approach this problem?

That isn't necessary. I would proceed by processing one line at a time:

``````1.  Read in the next Line
2.  Parse the line.
3.  Store the Name as a string and the scores in an array
4.  Use the average function to calculate the mean of the scores in the array
5.  Use the grading function to calculate the grade given the average
6.  Print out the results
7.  If there are more lines to process, start again at 1.``````

Oh yes, you are right. I forgot that this is C++. :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.