Here is my final product:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
void printGrade(int oneScore, float average);
void printTable(int scores[], int id[], int count);
float computeAverage(int scores[], int count);
const int MAX_SIZE = 21;
void readStudentData(ifstream &rss, int scores[], int id[], int &count, bool &tooMany)
{
rss.open("studentScoreData.txt",ios::in,ios::binary);
count = 0;
int oneScore = 0;
float average = 0;
string grade;
if(rss.fail())
{
cout << "Cannot Open File. If test file has been \n"
<< "created rename it studentScoreData." << endl << endl;
exit(1);
}
else
{
while((rss >> id[count] && count < MAX_SIZE) && (rss >> scores[count] && count < MAX_SIZE))
{
count++;
}
}
}
float computeAverage(int scores[], int count)
{
int id[MAX_SIZE];
int oneScore = 0;
float average = 0;
int sum = 0;
for(count = 0; count < MAX_SIZE; count++)
sum += scores[count];
average = sum / MAX_SIZE;
printGrade(oneScore,average);
return average;
}
void printTable(int scores[], int id[], int count)
{
int oneScore = 0;
float average = 0;
string grade;
cout << left << setw(9) << "ID#s" << setw(9) << "Scores" << setw(9) << "Grades" << endl << endl;
computeAverage(scores,count);
}
void printGrade(int oneScore, float average)
{
ifstream rss;
bool tooMany;
int count;
int id[MAX_SIZE];
int scores[MAX_SIZE];
string grade;
readStudentData(rss, scores, id, count, tooMany);
for(oneScore = 0; oneScore < MAX_SIZE; oneScore++)
{
if(scores[oneScore] > average + 10)
{
grade = "outstanding";
}
else if(scores[oneScore] < average - 10)
{
grade = "unsatisfactory";
}
else
{
grade = "satisfactory";
}
cout << left << setw(9) << id[oneScore] << setw(9) << scores[oneScore] << setw(9) << grade << endl;
}
}
int main()
{
ifstream rss;
string line;
int scores[MAX_SIZE];
int id[MAX_SIZE];
int count;
bool tooMany;
readStudentData(rss, scores, id, count, tooMany);
if (tooMany=true)
{
printTable(scores,id,count);
exit(1);
}
else
{
printTable(scores,id,count);
}
return 0;
}
Thanks to all who helped me. One of the major issues with my code that I finally realized was that my computeAverage(....) function was passing a parameter incorrectly.
I had it being set as:
computeAverage(int score[], int count[])
When it should have been:
computeAverage(int score[], int count) //notice my count parameter
Again, thanks to all who helped.
I have supplied the .cpp file and the .txt file that it calls for. Give it a try if you wish.