So for my assignment I have to do this.
Write a complete C++ program to read in, sort, and perform other statistical actions on a set of data. The program will read from an input file and write all results to an output file.
From an input file, the program will read a set of student's 3-digit id numbers and their SAT scores.
The program will sort the id numbers into descending numerical order, being sure to carry along the corresponding SAT scores. The program will then print the sorted lists, giving both id numbers and SAT scores.
The program will then sort the SAT scores into ascending numerical order, carrying along the corresponding id numbers. The program will print the sorted lists, giving both id numbers and scores.
Then the program will call functions to find the max and min of the SAT scores, the mean of the SAT scores, and the median of the SAT scores.
NOTE: In order to properly test the median function, you will run the same program TWICE, using different input and output files (in the program, you should change only the names of the files). You must send me two different input files, one with an even number of sets of data (even value for n) and once with an odd number of sets of data (an odd value for n), and two different output files. Make sure the names match to show which is even and which is odd.
Finally, the program will read in two scores and call a function search, once for each value, to see if the score is found in the array scores.
I'm only having trouble with modifying the readdata function which I have here.
How do I modify it so that it doesn't need the n parameter, but instead uses a counter to get n?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
//readdata() reads in the values of both arrays from a file.
void readdata(int &n,int nums1[],int nums2[])
{
infile>>n;
if(n>0&&n<=LIM)
outfile<<"There are "<<n<<" values"<<endl;
else
{
outfile<<"Invalid number of values"<<endl;
exit(1);
}
for(int count=0;count<n;count++)
{
infile>>nums1[count];
infile>>nums2[count];
}
return;
}
|