### Making an array reading from text files?

Recently I have been given assiginment, the description is this "This program will read grades from two different files (one at a time) and do some simple analytical operations on those grades -- identifying the maximum, minimum, median, and mean. The mean, of course, is the average computed by dividing the sum of all the scores and dividing by the number of scores. The median, on the other hand, is a score chosen so that half of the scores are greater than or equal to the median, and half of the scores are less than or equal to it.

Information about the scores will be stored in an array. But, the array will not hold the scores themselves -- instead it will record the number of occurrences of each particular score.

EXAMPLE DATA
Here is a sample data set of scores ranging from 1 to 10:

1 3 8 4 9 10 3 5 6 10 9 3 8 2 4 5 10 8 9 6 6 5 7 6 3 2 1 9 8 7 9

These grades could be summarized with the following table:
Scores: 1 2 3 4 5 6 7 8 9 10
Occurrences: 2 2 4 2 3 4 2 4 5 3
Note how all the grades are summarized with only 10 values, which requires considerably less memory than storing all of them.

Also, once the data is in this form, it is easy to identify the desired answers:

Minimum = 1 Maximum = 10 Mean = 6 (186/31) Median = 6

NOTE: This maximum of 10 is NOT the largest value in this array. Nor are these other statistics describe the contents of the array. (All of the contents are less than 5, so 6 is neither median nor mean.)

To test your program will not be provided with this assignment. The test files will have the names given ("data1.txt" and "data2.txt") and will both consist of integers in the range 0 to 100. No information will be provided on how many scores there are (your program will have to figure that out).

Since your program will need some data to work with while testing, just create your own suitable data files for that purpose, but to not include your tests in your submission. Your program must accept any valid input file, and not just a particular file you made and designed your program for. "

so far i have done this

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115`` `````` #include #include #include using namespace std; void readData( string fileName, int dataCounts[], int &totalScore); //opens and reads the specified data file, counting the scores that are found inside. // the outputs will be dataCounts (integer array output) the scores found in the file // totalScores (integer output) the total number of scores found void analyzeData(int dataCounts[], int totalScores, int maximum, int minimum, int median, int mean); //analyzes the data described by the array given to it, computing desired statistics int main() { int dataCounts[101]; for (int x = 0; x < 101; x++) dataCounts[x] = 0; int totalScores = 0; readData ( "data1.txt", dataCounts, totalScores); readData ( "data2.txt", dataCounts, totalScores); cout << totalScores; system ("pause"); } void readData( string fileName, int dataCounts[], int &totalScore) //data has to be read first { char line[4]; int value = 0; ifstream infile (fileName); while (!infile.eof()) { infile >> line; value = atoi(line); dataCounts[value]++; totalScore++; } //make new array for analyzeData // make totalScores = totalScores +1 infile.close(); //else cout << "Unable to open files"; void analyzeData(int dataCounts[], int totalScores, int maximum, int minimum, int median, int mean) { int maximum = dataCounts[0]; for (int n=0; n <= 100 ; n++ ) { if(maximum < n && dataCounts[n] > 0) maximum = n; } int minimum = dataCounts[0]; for (int n=0; n < 100 ; n++ ) //this is for min value { if(n > 0) if(minimum > dataCounts[n]) minimum = n; } int total = 0; for (int n=0; n < 100 ; n++ ) //this is for the mean value total = total + dataCounts[n]; return(total / 100); int median = 0; median = dataCounts [100/2]; if(dataCounts %2 == 0) return ((int)dataCounts[100/2]+dataCounts[(100/2)-1])/2 ; else return dataCounts[100/2] ; median = dataCounts[100/2]; //cout everything you get for median exc. cout << maximum << endl; cout << minimum << endl; cout << mean << endl; cout << median << endl; } ``````

my question is how do i make my program to read 2 files without confusing itself. i would appreciate any help thank you.
Topic archived. No new replies allowed.