Hi,
I have this program that I am writing to receive input from a file, process the information, and write the results to another file. Everything is fine logically, as far as I know, but when I try to compile it, a few errors surface concerning the files but I do not know how to solve them. Can you PLEASE help? You don't need to understand the whole code or the point of the program, just identify if there is anything blatantly wrong with my code concerning the input/output files.
int getScores(ifstream a, int G[]) {
int counter = 0;
int score;
while (!a.eof()) {
a >> score;
G[counter] = score;
counter++;
}
return counter;
}
void getCutOffs(int &a, int &b, int &c, int &d) {
int A, B, C, D;
cout << "Enter the lowest grade for an A: ";
cin >> A;
cout << "Enter the lowest grade for an B: ";
cin >> B;
cout << "Enter the lowest grade for an C: ";
cin >> C;
cout << "Enter the lowest grade for an D: ";
cin >> D;
a = A;
b = B;
c = C;
d = D;
}
void countLetterGrades(int G[], int count, int A, int B, int C, int D, int &a, int &b, int &c, int &d, int &f) {
int aX=0, bX=0, cX=0, dX=0, fX=0;
for (int x = 0; x < count; x++) {
if (G[x]>=A) { aX++; }
else if (G[x]>=B) { bX++; }
else if (G[x]>=C) { cX++; }
else if (G[x]>=D) { dX++; }
else if (G[x]>0) { fX++; }
}
a = aX; b = bX; c = cX; d = dX; f = fX;
}
void findMaxAndMin(int G[], int count, int &A, int &B) {
int max = G[0], min = G[0];
for (int x = 1; x < count; x++) {
if(max < G[x]) {
max = G[x];
}
if(min > G[x]) {
min = G[x];
}
}
A = max;
B = min;
}
double findAvg(int G[], int cnt) {
double avg;
int sum=0;
int count=0;
for (int x = 0; x < cnt; x++) {
sum = sum + G[x];
count++;
}
avg = sum / count;
return avg;
}
void drawHistogram(ofstream X, int max, int min, double avg, int num, int a, int b, int c, int d, int f) {
cout << "\tClass Statistics\n\n";
cout << left << setfill(' ') << setw(15);
cout << "Max Score" << "= " << max;
cout << "Min Score" << "= " << min;
cout << "Avg. Score" << "= " << avg;
cout << "Num. of scores" << "= " << num;
string A = drawStars(a);
string B = drawStars(b);
string C = drawStars(c);
string D = drawStars(d);
string F = drawStars(f);
cout << "\n";
cout << "A's:" << A << endl;
cout << "B's:" << B << endl;
cout << "C's:" << C << endl;
cout << "D's:" << D << endl;
cout << "F's:" << F << endl;
cout << left << setfill(' ') << setw(6) << "" << "0" << "5" << "15" << "20" << "25" << "30" << endl;
cout << "\n";
X << "\tClass Statistics\n\n";
X << left << setfill(' ') << setw(15);
X << "Max Score" << "= " << max;
X << "Min Score" << "= " << min;
X << "Avg. Score" << "= " << avg;
X << "Num. of scores" << "= " << num;
X << "\n";
X << "A's:" << A << endl;
X << "B's:" << B << endl;
X << "C's:" << C << endl;
X << "D's:" << D << endl;
X << "F's:" << F << endl;
X << left << setfill(' ') << setw(6) << "" << "0" << "5" << "15" << "20" << "25" << "30" << endl;
X << "\n";
X.close();
}
string drawStars(int a) {
string display = "";
string p = "***** ";
string q = "* ";
string r = " (";
string s = ")";
int one, two;
one = floor (a / 5);
two = a % 5;
for (int x = 0; x < one; x++) {
display += p;
}
for (int y = 0; y < two; y++) {
display +=q;
}
display += r;
std::stringstream ss;
ss << a;
display += ss.str();
display += s;
return display;
}
int getScores(ifstream *a, int G[]) {
int counter = 0;
int score;
while (!a->eof()) {
*a >> score;
G[counter] = score;
counter++;
}
return counter;
}
void getCutOffs(int &a, int &b, int &c, int &d) {
int A, B, C, D;
cout << "Enter the lowest grade for an A: ";
cin >> A;
cout << "Enter the lowest grade for an B: ";
cin >> B;
cout << "Enter the lowest grade for an C: ";
cin >> C;
cout << "Enter the lowest grade for an D: ";
cin >> D;
a = A;
b = B;
c = C;
d = D;
}
void countLetterGrades(int G[], int count, int A, int B, int C, int D, int &a, int &b, int &c, int &d, int &f) {
int aX=0, bX=0, cX=0, dX=0, fX=0;
for (int x = 0; x < count; x++) {
if (G[x]>=A) { aX++; }
else if (G[x]>=B) { bX++; }
else if (G[x]>=C) { cX++; }
else if (G[x]>=D) { dX++; }
else if (G[x]>0) { fX++; }
}
a = aX; b = bX; c = cX; d = dX; f = fX;
}
void findMaxAndMin(int G[], int count, int &A, int &B) {
int max = G[0], min = G[0];
for (int x = 1; x < count; x++) {
if(max < G[x]) {
max = G[x];
}
if(min > G[x]) {
min = G[x];
}
}
A = max;
B = min;
}
double findAvg(int G[], int cnt) {
double avg;
int sum=0;
int count=0;
for (int x = 0; x < cnt; x++) {
sum = sum + G[x];
count++;
}
avg = sum / count;
return avg;
}
void drawHistogram(ofstream *X, int max, int min, double avg, int num, int a, int b, int c, int d, int f) {
cout << "\tClass Statistics\n\n";
cout << left << setfill(' ') << setw(15);
cout << "Max Score" << "= " << max;
cout << "Min Score" << "= " << min;
cout << "Avg. Score" << "= " << avg;
cout << "Num. of scores" << "= " << num;
string A = drawStars(a);
string B = drawStars(b);
string C = drawStars(c);
string D = drawStars(d);
string F = drawStars(f);
cout << "\n";
cout << "A's:" << A << endl;
cout << "B's:" << B << endl;
cout << "C's:" << C << endl;
cout << "D's:" << D << endl;
cout << "F's:" << F << endl;
cout << left << setfill(' ') << setw(6) << "" << "0" << "5" << "15" << "20" << "25" << "30" << endl;
cout << "\n";
*X << "\tClass Statistics\n\n";
*X << left << setfill(' ') << setw(15);
*X << "Max Score" << "= " << max;
*X << "Min Score" << "= " << min;
*X << "Avg. Score" << "= " << avg;
*X << "Num. of scores" << "= " << num;
*X << "\n";
*X << "A's:" << A << endl;
*X << "B's:" << B << endl;
*X << "C's:" << C << endl;
*X << "D's:" << D << endl;
*X << "F's:" << F << endl;
*X << left << setfill(' ') << setw(6) << "" << "0" << "5" << "15" << "20" << "25" << "30" << endl;
*X << "\n";
X->close();
}
string drawStars(int a) {
string display = "";
string p = "***** ";
string q = "* ";
string r = " (";
string s = ")";
int one, two;
one = (int) floor ( (float)(a / 5) );
two = a % 5;
for (int x = 0; x < one; x++) {
display += p;
}
for (int y = 0; y < two; y++) {
display +=q;
}
display += r;
std::stringstream ss;
ss << a;
display += ss.str();
display += s;
return display;
}