Help with Class Example

This was an example my teacher went over to help with upcoming assignment and i have a few errors i'm not sure about, First time encountering them. [Error ISO C++ forbids comparison between pointer and integer[-fpremissive] starts Line 14. Then after i adjusted a few things Line 92 gave me [Error] Invalid Conversion from int to int*. Would greatly Appreciate help seeing as i could look back at this as reference material.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#define SIZE 28
using namespace std;


int ArrayFromFile (int A[], int Q[])
{
	int C = 0;
	ifstream inFile;
	inFile.open("grades.txt");
	while(C<Q &&!inFile.eof()) 
	{
		inFile >> A[C];
		C+=1;
	}
	inFile.close();
	if (C!=Q) cout << "Quanity of data file doesn't match array size";
	return C;
}


void sortArray (int A[], int Q)
{
	int P, PASS, T;
	for (PASS=1; PASS<Q; PASS++)
	 for (P=0;P<=-1-PASS;P++)
	  if (A[P]>A[P+1])  { T=A[P]; A[P]=A[P+1]; A[P+1]=T;}
}

void stats ( int A[], int Q[], int &MIN, int &MAX, float &AVG)
{
	int TOTAL=0;
	int I;
	int COUNT=0;
	int T;
	
	MIN = 100;
	MAX = 0;
	for (I=0; I<Q; I++)
	{
		if (A[T]>=Q && A[T]<=100)
		{
			COUNT+=1;
			TOTAL+=A[I];
			if (A[I]<MIN) MIN=A[I];
			if (A[I]<MAX) MAX=A[I];			
		}
	}
	AVG=static_cast<float>(TOTAL/COUNT);
}

void displayCatergory (int A[], int Q[], int &MIN, int &MAX, float &AVG)
{
	int I;
	int QI=0, QU=0, QS=0, QO=0;
	cout << "Student\n\n";
	cout << "Score  |  Category\n";
	cout << "-------+----------\n";
	for (I=0; I<Q[SIZE]; I++)
	{
		cout << setw(8) << A[I] << "  |  ";
		if (A[I]<0 || A[I]>100)  {QI++; cout << "Invalid";}
		else if (A[I]<60) { QU++; cout << "Unstatisfactory";}
		else if (A[I]<90) { QU++; cout << "statisfactory";}
		else {QO++; cout << "Outstanding";}
		cout << endl;
    }
	cout << "\nStatistics:\n\n";
	cout << setw(8) << Q << "  |  Scores Read From File" << endl;
	cout << setw(8) << QO << "  |  Outstanding Scores (90-100)" << endl;
	cout << setw(8) << QS << "  |  Statisfactory Scores (60-89)" << endl;
	cout << setw(8) << QU << "  |  Unstatisfactory Scores (0-59)" << endl;
	cout << setw(8) << QI << "  |  Invalid Scores (Under 0 or Over 100)" << endl;
	cout << setw(8) << setprecision(2) << fixed << AVG << "  |  Average Score" << endl;
	cout << setw(8) << MAX << "  |  Highest Score" << endl;
	cout << setw(8) << MIN << "  |  Lowest Score"  << endl;
}
int main (void)
{
	cout << "Student\n";
	cout << "4/14/15\ class example\n";
	cout << "Test Score Summary\n";
	
	int SCORES;
	int QTY[SIZE];
	int MIN, MAX;
	float AVG;
	
QTY = ArrayFromFile(SCORES, QTY);
sortArray(SCORES, QTY);
stats(SCORES, QTY, MIN, MAX, AVG);
displayCatergory(SCORES, QTY, MIN, MAX, AVG);
return 0;
}
http://ideone.com/EBJ3Ds

The code is horrible. I don't know what language your professor is trying to teach, but it isn't C++.

The code tries to treat array names as the size of arrays. This will never work - you have to track the size of arrays separately.

All the variable names are in all caps - although technically a matter of personal preference, the general (and most widely accepted standard) is that only constants are in all caps.

Line 92 - I think SCORES was meant to be an array, however, this line tries to assign the return value of the function to QTY - the function returns a single value but QTY is an array. Not to mention that you can't assign arrays to other arrays, or that functions cannot return arrays. This line has so many things wrong with it.

I don't have a high opinion of your teacher right now. Are you sure this is the exact code they provided? Could it be that you transcribed the code incorrectly?
as far as majority of the code it is exactly like he showed i think, i just messed up on the code with the errors that i get so the first function in ArrayFromFile and the Main function.
I'm assuming from the beginning hes trying to relate Q to 28 because if C!=28 then my error "Quantity of data file does not match size of the array" should pop up.
So before i came here i took every "Q" and replaced it with "SIZE" and that's when the second error popped up.
Last edited on
Even with that, line 92 doesn't make sense. You should email your professor for the actual code they wrote.
Topic archived. No new replies allowed.