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.

Recommended Answers

All 3 Replies

You should have posted this under the same thread buddy.Because we need to start from the scratch in understanding if you start a new thread.Topic under same thread will let us know that its a part of it only.

You still have a mistake left :

rss.open("studentScoreData.txt",ios::in,ios::binary);

Its not "," that you should use in between the flags.you should use "|" operator as below:

rss.open("studentScoreData.txt",ios::in|ios::binary);

Other things are running fine i suppose :).Enjoy.

Are you posting because you have more questions or just to show the final product? It still has major problems. Reread my comments in your prior thread(s). You still have arrays in printGrade. You should have none. You still have a loop in printGrade. There should not be a loop. You have variables in readStudentData that aren't used. You still use MAX_SIZE in computeAverage. You overwrite the count value passed to computeAverage. You display in computeAverage...

I was posting just to show final product. Code may still have several issues but it works. That is what matters to me. I'm not all knowing when it comes to programming. I prefer to stick to excel and vb. I'm not a fan of c++. I'm only doing it because it is required for my degree plan. I'm just a beginner programmer and everything I program has beginner errors in it. I am learning a little at a time in large chunks. This was the largest program I have ever had to write and the only reason I did it was because it was required for class. Otherwise I wouldn't have messed with it.

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.