in addition to my questions above...our professor gave an example where he said that he created a program for a school and he created an array for 3000 (for the # of students), but actually there were 3002 students and he said that the school lost the data...or something to that effect....is that how sensetive the arrays allocation of memory/size is and why?

>our professor gave an example where he said that he created a program for a school and he
>created an array for 3000 (for the # of students), but actually there were 3002 students and
>he said that the school lost the data...
If this was supposed to be a serious program and not an example or prototype, I'd say your professor is an incompetent boob when it comes to practical programming. I mean, really. The number of students is variable, so why would you think a statically sized array could possibly be sufficient? The only time you use arrays is when you have control over the size, or the array is used as a temporary in building a larger container.

>is that how sensetive the arrays allocation of memory/size is and why?
If you have 3000 slots and 3002 items, where do the other 2 go? That's the problem of fixed size containers, and it's a very simple problem, but with serious implications.

Ok kool, thanks for pointing that out, never thought about that. Im going to make a bit of modifications to my source code for this assignment and re-post so you can see what's going on. Thx again.

Any assistance is appreciated.

Loop 1:
Used to fill container by reading contents of file and, depending on type of container used, keep track of actual number of grades read in

Loop 2:
Used to:
calculate sumTotalOfAllGrades
Determine minimum grade
Determine maximum grade

Outside any loop:
print out total grades read in, min and max grade
Calculate averageOfAllGrades

Loop 3:
Used to determine if any given grade above or below averageOfAllGrades and do whatever is desired once that information is available.

Ok guys, i did a bit of modification, much to simpler(to me that is)

#include <iomanip>
#include <cmath>
#include <fstream>
#include<string>
#include<iostream>

using namespace std;

int main()
{
ifstream infile;
ofstream outfile;

infile.open ("gradesA.txt");
outfile.open ("gradeOutput");

int grades;//each individual grades
int testScoreAverage;//average of all grades
int testscores=0;//number of test scores
int totalgrade=0;
int max = -32767;//highest grade
int min = 32767;//lowest grade
int count = 0;
int i;

while(infile>>grades)
{	
	testscores=testscores++;
	totalgrade=totalgrade + grades;
	testScoreAverage =(totalgrade /testscores);

  if 
	  (grades< testScoreAverage) 
  {
     cout << grades << " Below" << endl;
  }
  if (grades > testScoreAverage) 
  {
     cout << grades << " Above" << endl;
  }
	  for (i=0;i<count;i++)
	  {
		  if (grades[count]>max)
			 max=grades[count];
		  if (grades[count]<min)
			  min=grades[count];
	  }//end for i
}
      cout << "AND THE MAX IS:  " << max << endl;
      cout << "AND THE MIN IS:  " << min << endl;
	  cout<<"The # of test scores in the file: "<<testscores<<endl;

	  infile.close();
      outfile.close();
	return 0;
}

The error message that i get is:

error C2109: subscript requires array or pointer type

Based on what i have above, i should have been able to tell how much grades there are, there average, the highest, the lowest and eventually, whether each grade is below or above the average. Thx much for the input.

Ok....i changed to this:

#include <iomanip>
#include <cmath>
#include <fstream>
#include<string>
#include<iostream>

using namespace std;

int main()
{
ifstream infile;
ofstream outfile;

infile.open ("gradesA.txt");
outfile.open ("gradeOutput");

int grades;//each individual grades
int testScoreAverage;//average of all grades
int testscores=0;//number of test scores
int totalgrade=0;
int max = -32767;//highest grade
int min = 32767;//lowest grade
int count = 0;
int i;

cout<<"Grades" <<"     Status"<<endl;
while(infile>>grades)
{	
	testscores=++testscores;
	totalgrade=totalgrade + grades;
	testScoreAverage =(totalgrade /testscores);
	cout<<grades<<endl;
	
  if 
	  (grades < testScoreAverage) 
  {
     
     cout <<setw(15)<<"Below"<<endl;
  }
  if (grades > testScoreAverage) 
  {
     cout  <<setw(15)<<"Above"<<endl;
  }
} 
      cout <<"AND THE MAX IS:  " << max << endl;
      cout <<"AND THE MIN IS:  " << min << endl;
	  cout<<"The # of test scores in the file: "<<testscores<<endl;
	  cout<<"The average grade was: "<<testScoreAverage<<endl;

	  infile.close();
      outfile.close();
	return 0;
}

My infile:

66
56
88
98
43

it does calculate the # of grades correctly...So pretty much, apart from the min and max everything else works. Except that the programs shows that i have 5 numbers in the infile(which is correct), however, on the screen it only prints out 4 lines of numbers...any idea why? Thx for your input.

I did a bit of messing around, but then it affects the average.
The output:

Grades     Status
66
56
          Below
88
          Above
98
          Above
43
          Below
AND THE MAX IS:  -32767
AND THE MIN IS:  32767
The # of test scores in the file: 5
The average grade was: 70

so the 1st # is missing a status.

Thx to all for their input, program works perfectly.

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.