954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help with parrallel arrays

I am completly lost with arrays. I have scoured my book and the exaamples it gives are way to simple. I can wrerite them like those in the books, but I cannot seem to get the real problem to work. Also I am doing ifstream and ofstream so I cannot really see what is happening. I printed to screen once and it was just a bunch of garbage. Here is the problem: I have to take input from the file PianoREV.data and output it to Report.out. I need to setup parallel partially filled arrays for the contestant id's, student level, composision difficulty rating, num judges and overall averages. I need two dimensional arrays for the judge ids judges scores and weighted scores. Then a print report fucntion comes and prints it all. I have not attempted to write this as i cannot get the arrays to work to begin with. Here is an example of the PianoREV.

6010 1 1.3
23 7.0
25 8.5
34 7.0
12 7.5
-1
6012 1 1.2
23 7.5
34 7.0
45 7.0
50 7.5
-1

The first number is the player id. the second the proficiency level, the third is the weight factor, followed by judge and then score. I had a lot of help with psuedo code on the first assignment based on this task and would depply appreciate some more. MY teacher is really not helping any of us. Half the class has dropped and the other half is failing. Anyways here is what i have so far. Am I even going in the right direction?

#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;
const int MAXMEMBERS = 25;
int ReadScores (ifstream& fin, int pianoPlayer[MAXMEMBERS], double score[MAXMEMBERS]);

int pianoPlayer[MAXMEMBERS];
double score[MAXMEMBERS];
double weightFactor[MAXMEMBERS];
int profLevel[MAXMEMBERS];

const int MAXJUDGES = 7;
int main()
{
	ifstream fin;
	ofstream fout;

	fin.open("PianoREV.data");
	if (fin.fail())
	{
		cout << "Error: Input File";
		exit (1);
	}
	fout.open("Report.out");
	if (fout.fail())
	{
		cout << "Error: Output File";
		exit (1);
	}
ReadScores (fin, pianoPlayer, score);
fin.close();
fout.close();
}

int ReadScores (ifstream& fin, int pianoPlayer[MAXMEMBERS], double score[MAXMEMBERS])
{
	int countPlayers = 0;
	while (countPlayers < MAXMEMBERS && (fin >> pianoPlayer[MAXMEMBERS]))
	{
		int i = 0;
		int judgeNumber[i];
		fin >> profLevel[countPlayers];
		fin >> weightFactor[countPlayers];
		while (judgeNumber[i] != -1)
		{
			for(i = 0; i<MAXJUDGES;i++)
			{
				fin >> judgeNumber[i];
				fin >> score[i];
				fin >> judgeNumber[i];
			}
		}
	}
	return countPlayers;
}
lsu420luv
Light Poster
49 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

So, according to your description
Player ID = 6010
Proficiency Level = 1
Weight Factor = 1.3
Judge = 23
Score = 7.0

Then the next set is
Player ID = 25
Proficiency Level = 8.5
Weight Factor = 34
Judge = 7.0
Score = 12


That doesn't look right to me because the numbers in the first set are not the same type as those in the second set. You need to clarify what that data rally means before you can write a program to read them.

Ancient Dragon
Retired & Loving It
Team Colleague
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

The portion of the input file posted contains the data for two piano players, one with number 6010 and one with number 6012. The data is delimited by player with a -1. In this example each player has proficiency of 1 but one has weight factor 1.2 and the other weight factor 1.3. Each player received scores from 4 judges with the each judges number and score from that judge listed on a separate line. I assume that in other parts of the file a player may have scores from a different number of judges, hence the need to delineate player data by the -1 flag, but maybe it's just a learning exercise in how to identify and deal with delimeters when reading a file.

What I don't understand is how many arrays are needed:

>>I need to setup parallel partially filled arrays for the contestant id's, student level, composision difficulty rating, num judges and overall averages.

Does this imply 5 arrays are needed, one for each of the above sets of data?

And what do you mean by partially filled? Are you supposed to use tables of a given size but only certain elements within the table are going to be used---how will you know which elements are to be used and which aren't---by player number, judge number, develop a hash function?


Then what does this mean:

>>I need two dimensional arrays for the judge ids judges scores and weighted scores.

Are you supposed to read through the data for all scores from a given judges and place them in a single two dimensional array of type double?

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

if you know how to write a c++ class, you can do the project with no c-style arrays at all. Two classes and a vector should do the job.

class judge
{
public:
	long	JudgeID;
	float	weight;
};

class PianoRE
{
public:
	PianoRE() {PlayerID = Proficiency = 0; WeightFactor = 0.0f;}
	void SetPlayerID(long id) {PlayerID = id;}
	long GetPlayerID() {return PlayerID;}
	void SetProficiendy(long prof) {Proficiency = prof;}
	long GetProficiency() {return Proficiency;}
	void SetWeight(float w) {WeightFactor = w;}
	float GetWeight() {return WeightFactor;}
	void SetJudge(const judge& j) {judges.push_back(j);}
	const vector<judge>& GetJudges() {return judges;}

protected:
	long	PlayerID;
	long	Proficiency;
	float	WeightFactor;
	vector<judge> judges;

};


or if you cannot yet handle that, you can create a structure and make a linked list of those structures

struct judge
{
	long	JudgeID;
	float	weight;
        struct judge* next;
};

struct PianoRE
{
	long	PlayerID;
	long	Proficiency;
	float	WeightFactor;
	struct judges*  HeadJudge;
        struct PianoRE* next;
};

now just learn how to do linkes lists, and again you need not use
any c-style arrays.

Ancient Dragon
Retired & Loving It
Team Colleague
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Hey lsu420luv, I would suggest the following way of implementing this part of your project. You would have to implement the output file logic yourself.

typedef std::map<int, float> Ratings; // Use this type to store judge ratings
typedef std::vector<PianoStudent> Players; // Use this type to store PianoStudents

struct PianoStudent
{
	int player_id;
	int player_proficiency;
	float weight_factor;
	Ratings judge_ratings;
};

int main ()
{
	std::ifstream fin("PianoREV.data");

	if (!fin) // Check if file open failed
	{
		cout << "Error: Input File";
		return 1;
	}

	Players students; // PianoStudent vector
	PianoStudent ps;

	while (fin)
	{
		if (!(fin >> ps.player_id))
			break;
		if (!(fin >> ps.player_proficiency))
			break;
		if (!(fin >> weight_factor))
			break;

		// Process the judges
		while (fin)
		{
			int judge_id;
			float rating;
			if (!(fin >> judge_id) || judge_id == -1)
				break;
			if (!(fin >> rating))
				break;
			ps.judge_ratings.insert(std::make_pair(judge_id, rating)); // Add the judge rating
		}
		students.push_back(ps); // Add the student to the vector
	}

	// Print out all the students
	cout << "Total students: " << students.size() << endl;
	for (Players::iterator iter = students.begin(); iter != students.end(); ++iter)
	{
		cout << "Player ID: " << iter->player_id << endl
			<< "Player Proficiency: " << iter->player_proficiency << endl
			<< "Weight Factor: " << iter->weight_factor << endl;
		for (Ratings::iterator jter = iter->judge_ratings.begin(); jter != iter->judge_ratings.end(); ++jter)
		{
			cout << "Judge ID: " << jter->first
				<< " Rating: " << jter->second << endl;
		}
	}

	return 0;
}

I felt that you tried your best and I know there are many lecturers out there who don't do their job. I hope this would be of good help to you. I wrote the code to print out the information contained within the PianoStudent as a reference on how to retrieve the values from the vector and map . If you encounter any further problems, or if anyone has better suggestions to this solution, feel free to point them out.

AstroNox
Junior Poster in Training
50 posts since Mar 2006
Reputation Points: 10
Solved Threads: 2
 

I am not supposed to know how to do vectors or structures yet. Lerner was right in his assumptions. They are supposed to be loaded into 5 partially filled arrays. Some of them hitting the max number of judges being 7 and some not. The judges is's the judges scores and the weighted scores are scored in seperate 2-d arrays that store the multiple scores for that player id. I hope this answers the questions.


Are you supposed to read through the data for all scores from a given judges and place them in a single two dimensional array of type double?

I am supposed to read through the scores for all judges for one player and score that in a 2-d array. Also the weighted scores and the jude ids.

lsu420luv
Light Poster
49 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

That's possible, but it could become very messy. It might be better to have three arrays, one for the judge ID, another for the score, and the last for the student ID. This student ID will allow you to match up the judge/score to the student's statistics, like proficiency and weight factor. If you could use pointers, dynamic means to allocating the memory is preferred because you do not know how large your future data files might be.

I thought lecturers wouldn't bother on structs, vectors and so on as long as the whole thing works properly. In fact I believe that most lecturers wouldn't bother to look at code if it is possible, say, unless you are supposed to submit an implementation of an algorithm or something somewhere along that line.

AstroNox
Junior Poster in Training
50 posts since Mar 2006
Reputation Points: 10
Solved Threads: 2
 

That's possible, but it could become very messy. It might be better to have three arrays, one for the judge ID, another for the score, and the last for the student ID. This student ID will allow you to match up the judge/score to the student's statistics, like proficiency and weight factor. If you could use pointers, dynamic means to allocating the memory is preferred because you do not know how large your future data files might be.

I thought lecturers wouldn't bother on structs, vectors and so on as long as the whole thing works properly. In fact I believe that most lecturers wouldn't bother to look at code if it is possible, say, unless you are supposed to submit an implementation of an algorithm or something somewhere along that line.

In the assignment sheet it requires the 5 arrays. She does do shit messy. She is an awful teacher I think. This whole class is code.

lsu420luv
Light Poster
49 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

Five arrays... well you could try your original method I guess. What more can I say since the situation is like that...

AstroNox
Junior Poster in Training
50 posts since Mar 2006
Reputation Points: 10
Solved Threads: 2
 

Here is what I have been working on. It will not print to the report.out. It does not have all the arrays built, but it should fill the ones necessary at least to output some text to file. What am I doing wrong here?

#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;
const int MAXMEMBERS = 25;
const int MAXJUDGES = 7;
int ReadScores (ifstream& fin, int pianoPlayer[MAXMEMBERS], double score[MAXMEMBERS][MAXJUDGES],
			       int judgeNumber[MAXMEMBERS][MAXJUDGES]);

int pianoPlayer[MAXMEMBERS];
double score[MAXMEMBERS][MAXJUDGES];
double weightFactor[MAXMEMBERS];
int profLevel[MAXMEMBERS];
int judgeNumber[MAXMEMBERS][MAXJUDGES];
int category;  //category of music the students are playing
//index of student id's
 //index of something
int judgeCount[MAXMEMBERS];
int numPlayers = 0;
int main()
{
	ifstream fin;
	ofstream fout;

	fin.open("PianoREV.data");
	if (fin.fail())
	{
		cout << "Error: Input File";
		exit (1);
	}
	fout.open("Report.out");
	if (fout.fail())
	{
		cout << "Error: Output File";
		exit (1);
	}
ReadScores (fin, pianoPlayer, score, judgeNumber);
numPlayers = ReadScores (fin, pianoPlayer, score, judgeNumber);
fin.close();
fout.close();
}

int ReadScores (ifstream& fin, int pianoPlayer[MAXMEMBERS], double score[MAXMEMBERS][MAXJUDGES], 
			       int judgeNumber[MAXMEMBERS][MAXJUDGES])
{
	int i= 0;
	int j= 0;
	fin >> category;
	while (i < MAXMEMBERS && (fin >> pianoPlayer[i]))
	{
		fin >> profLevel[i];
		fin >> weightFactor[i];
		fin >> judgeNumber[i][j];
		while (judgeNumber[i][j] != -1)
		{
			j++;
			i++;
			fin >> score[i][j];
			fin >> judgeNumber[i][j];
		}
	}
	return i;
}
void PrintReport(ofstream& fout, int pianoPlayer[MAXMEMBERS], int score[MAXMEMBERS][MAXJUDGES],
				int numPlayers)
{
	int i;
	int j;
	for (i = 0; i < numPlayers; i++)
	{
		fout << pianoPlayer[i];
		fout << score[i][j];
		j++;
	}	
	return;
}


I just couted to screen and it is not exiting the while loop when it hits the negative 1. Another things are the arrays filling right and how can i check this.

lsu420luv
Light Poster
49 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

I have setup the arrays sucessfully I think. At least the score and the player ids. For some reason it is pulling in the negative one before exiting though. Is there a way to avoid this? Here it is

int ReadScores (ifstream& fin, int pianoPlayer[MAXMEMBERS], double score[MAXMEMBERS][MAXJUDGES], 
				int judgeNumber[MAXMEMBERS][MAXJUDGES])
{
	int i= 0;
	int j= 0; 
	int k= 0; //index judge count
	fin >> category;
	while (fin >> pianoPlayer[i])
	{
		fin >> profLevel[i];
		fin >> weightFactor[i];
		fin >> judgeNumber[i][j];
		while (judgeNumber[i][j] != -1)
		{
			fin >> score[i][j];
			fin >> judgeNumber[i][j];
			j++;			
		}
	judgeCount[i] = j;	
	i++;
	j = 0;
	}
	return i;
}
void PrintReport(ofstream& fout, int pianoPlayer[MAXMEMBERS], double score[MAXMEMBERS][MAXJUDGES],
				 int numPlayers)
{
	for (i = 0; i < MAXMEMBERS; i++)
	{
		fout << "Piano Player: ";
		fout << pianoPlayer[i];
		for (j =0; j < MAXJUDGES; j++)
		{
			fout << "Judge Number: " << judgeNumber[i][j] << "   ";
			fout << "Score: " << score[i][j] << "\n";
		}
	}	
	return;
}


Basically after the completion of one cycle the player id becomes the negative one and the all the data becomes off by one each repition. There is something wrong with my loops it is not stopping after the players are read I do not think, but it is not trapped in an infinite loop. I do not know what to do. I think I finnally am getting some grasp on this

lsu420luv
Light Poster
49 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

It's not printing anything because you did not call the PrintReport method?

Your reading method seems to be flawed. Try this method (it's a modified version what I wrote earlier):

int ReadScores (ifstream& fin)
{
	int i;
	for (i = 0; fin && i < MAXMEMBERS; ++i)
	{
		if (!(fin >> pianoPlayer[i]))
			break;
		if (!(fin >> profLevel[i]))
			break;
		if (!(fin >> weightFactor[i]))
			break;

		// Process the judges
		for (int j = 0; fin; ++j)
		{
			if (j >= MAXJUDGES)
			{
				// If the number of judges overflow the array size,
				// we have to clear off the remaining judge entries
				// so that we can continue reading from the next
				// player entry
				int k;
				if (!(fin >> k) || k == -1)
					break;
				else
					continue;
			}
			if (!(fin >> judgeNumber[i][j]) || judgeNumber[i][j] == -1)
				break;
			if (!(fin >> score[i][j]))
				break;
		}
	}
	return i;
}

Hope this helps.

Oh yes, it would be good to place your ReadScores and PrintReport methods above the main method so that you do not need to pre-declare them.

AstroNox
Junior Poster in Training
50 posts since Mar 2006
Reputation Points: 10
Solved Threads: 2
 

that rocks. Thank you. I am still running into the problem of it reading 8 judges for every player. It is not exiting at the -1. I see that it is reading until MAXJUDGES has been read. I do not know how to put the while loop in there for sentinal control. Also it is reading 25 players rather than just reading until the last player is processed. How can i get around this. Is there a way to just disply the filled parts or do i have to use the while loop.
Also I am supposed to be calling by reference only. What does this mean?
How do I add up the scores to avereage them? I have been fiddling and I keep on using the wrong values?

lsu420luv
Light Poster
49 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

Sorry, but I do not fully understand what you have posted (no, I'm not pointing out the spelling mistakes):
I do not know how to put the while loop in there for sentinal control.
What do you mean by "sentinal control"?Is there a way to just disply the filled parts or do i have to use the while loop.
What do you mean by "disply the filled parts"? What filled parts do you want to display?Also I am supposed to be calling by reference only. What does this mean?
Honestly I would not know unless you give me the context in which your lecturer placed that statement.How do I add up the scores to avereage them? I have been fiddling and I keep on using the wrong values?
This is pretty simple. Assume that sid is the array index of the student you want to average the score for.

int numJudges = 0;
double totalScore = 0;
double average = 0;
for (; numJudges < MAXJUDGES && judgeNumber[sid][numJudges] != -1; ++numJudges)
	totalScore += score[sid][numJudges];
if (numJudges != 0)
	average = totalScore / numJudges;


If you would like to get past the MAXMEMBERS and MAXJUDGES limits, it'd be recommended to use a vector . But since you can't, you have to use malloc , realloc or new , delete ; and pointers to manage and increase your memory use for these data.

AstroNox
Junior Poster in Training
50 posts since Mar 2006
Reputation Points: 10
Solved Threads: 2
 

basically I need the loop to stop when it hits -1. Rather than read the judges till the MAXJUDGES has been reached. she says call by reference not by value. you add a + to a variable in the function or something. See I need to setup an array that stores how many jdeges per student an I assume that controls how many it prints to screen. A judge counter array if you will. so the student with 5 judges and scores print 5 and ones with 4 print 4 rather than 8 every time.

lsu420luv
Light Poster
49 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 
basically I need the loop to stop when it hits -1. Rather than read the judges till the MAXJUDGES has been reached.


That has already been done in my previous post (look at the underlined portion):

int ReadScores (ifstream& fin)
{
	int i;
	for (i = 0; fin && i < MAXMEMBERS; ++i)
	{
		if (!(fin >> pianoPlayer[i]))
			break;
		if (!(fin >> profLevel[i]))
			break;
		if (!(fin >> weightFactor[i]))
			break;

		// Process the judges
		for (int j = 0; fin; ++j)
		{
			if (j >= MAXJUDGES)
			{
				// If the number of judges overflow the array size,
				// we have to clear off the remaining judge entries
				// so that we can continue reading from the next
				// player entry
				int k;
				if (!(fin >> k) || k == -1)
					break;
				else
					continue;
			}
			if (!(fin >> judgeNumber[i][j]) || judgeNumber[i][j] == -1)
				break;
			if (!(fin >> score[i][j]))
				break;
		}
	}
	return i;
}
she says call by reference not by value. you add a + to a variable in the function or something.


Callwhich method with parameters by reference or value? The ReadScores method above uses ifstream& fin as its parameter; the & tells the compiler that the parameter is passed in by reference and not by value.See I need to setup an array that stores how many jdeges per student an I assume that controls how many it prints to screen. A judge counter array if you will. so the student with 5 judges and scores print 5 and ones with 4 print 4 rather than 8 every time.
That's already been done in my previous post too. You do not need another array to store the number of judges; all you need is to read the array until you either hit a -1 in the judgeNumber[sid][<em>n</em>] , or hit MAXJUDGES , whichever comes first. The underlined portion in this excerpt of my previous post checks if we reached -1 yet:

int numJudges = 0;
double totalScore = 0;
double average = 0;
for (; numJudges < MAXJUDGES && judgeNumber[sid][numJudges] != -1; ++numJudges)
	totalScore += score[sid][numJudges];
if (numJudges != 0)
	average = totalScore / numJudges;
AstroNox
Junior Poster in Training
50 posts since Mar 2006
Reputation Points: 10
Solved Threads: 2
 

It is still posting all eight judges regardless of the -1. Here is the code I am using.

#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;
const int MAXMEMBERS = 20;
const int MAXJUDGES = 8;
int ReadScores(ifstream& fin);
void PrintReport(ofstream& fout, int pianoPlayer[MAXMEMBERS], double score[MAXMEMBERS][MAXJUDGES],
				int numPlayers);
int ProcessScores(ifstream& fin);
int pianoPlayer[MAXMEMBERS];
double score[MAXMEMBERS][MAXJUDGES];
double weightFactor[MAXMEMBERS];
int profLevel[MAXMEMBERS];
int judgeNumber[MAXMEMBERS][MAXJUDGES];
int category;  //category of music the students are playing
int judgeCount[MAXMEMBERS];
int numPlayers;
int i= 0;
int j= 0;
int main()
{
	ifstream fin;
	ofstream fout;

	fin.open("PianoREV.data");
	if (fin.fail())
	{
		cout << "Error: Input File";
		exit (1);
	}
	fout.open("Report.out");
	if (fout.fail())
	{
		cout << "Error: Output File";
		exit (1);
	}
ReadScores (fin);
ProcessScores (fin);
numPlayers = ReadScores (fin);
PrintReport(fout, pianoPlayer, score, numPlayers);
fin.close();
fout.close();
}

int ReadScores (ifstream& fin)
{
	int i;
	fin >> category;
	for (i = 0; fin && i < MAXMEMBERS; ++i)
	{
		if (!(fin >> pianoPlayer[i]))
			break;
		if (!(fin >> profLevel[i]))
			break;
		if (!(fin >> weightFactor[i]))
			break;

		// Process the judges
		for (int j = 0; fin; ++j)
		{
			if (j >= MAXJUDGES)
			{
				// If the number of judges overflow the array size,
				// we have to clear off the remaining judge entries
				// so that we can continue reading from the next
				// player entry
				int k;
				if (!(fin >> k) || k == -1)
					break;
				else
					continue;
			}
			if (!(fin >> judgeNumber[i][j]) || judgeNumber[i][j] == -1)
				break;
			if (!(fin >> score[i][j]))
				break;
		}
	}
	return i;
}
int ProcessScores(ifstream& fin)
{
	for (i = 0; i < MAXMEMBERS; i++)
	{
		
		averageRaw[i][j]= score[i][j] + sum;
void PrintReport(ofstream& fout, int pianoPlayer[MAXMEMBERS], double score[MAXMEMBERS][MAXJUDGES],
				 int numPlayers)
{
	for (i = 0; i < MAXMEMBERS; i++)
	{
		fout << "Piano Player: ";
		fout << pianoPlayer[i] << "\n";
		for (j =0; j < MAXJUDGES; j++)
		{
			fout << "Judge Number: " << judgeNumber[i][j] << "   ";
			fout << "Score: " << score[i][j] << "\n";
		}
	}	
	return;
}


Here is the Report.out

Piano Player: 6010
Judge Number: 23 Score: 7
Judge Number: 25 Score: 8.5
Judge Number: 34 Score: 7
Judge Number: 12 Score: 7.5
Judge Number: -1 Score: 0
Judge Number: 0 Score: 0
Judge Number: 0 Score: 0
Judge Number: 0 Score: 0
Piano Player: 6012
Judge Number: 23 Score: 7.5
Judge Number: 34 Score: 7
Judge Number: 45 Score: 7
Judge Number: 50 Score: 7.5
Judge Number: -1 Score: 0
Judge Number: 0 Score: 0
Judge Number: 0 Score: 0
Judge Number: 0 Score: 0

Is the problem in how i am outputting the results?

lsu420luv
Light Poster
49 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

You need to have the underlined portion in your condition, as mentioned in my previous post:

void PrintReport(ofstream& fout)
{
	for (i = 0; i < MAXMEMBERS; i++)
	{
		fout << "Piano Player: ";
		fout << pianoPlayer[i] << "\n";
		for (j =0; j < MAXJUDGES && judgeNumber[i][j] != -1; j++)
		{
			fout << "Judge Number: " << judgeNumber[i][j] << "   ";
			fout << "Score: " << score[i][j] << "\n";
		}
	}	
	return;
}

You might also consider adding numPlayers to the condition of the outer loop, as underlined:

void PrintReport(ofstream& fout)
{
	for (i = 0; i < MAXMEMBERS && i <numPlayers; i++)
	{
		fout << "Piano Player: ";
		fout << pianoPlayer[i] << "\n";
		for (j =0; j < MAXJUDGES && judgeNumber[i][j] != -1; j++)
		{
			fout << "Judge Number: " << judgeNumber[i][j] << "   ";
			fout << "Score: " << score[i][j] << "\n";
		}
	}	
	return;
}

In fact, the numPlayers condition alone should suffice, being that numPlayers will not exceed MAXMEMBERS (underlined):

void PrintReport(ofstream& fout)
{
	for (i = 0; i <numPlayers; i++)
	{
		fout << "Piano Player: ";
		fout << pianoPlayer[i] << "\n";
		for (j =0; j < MAXJUDGES && judgeNumber[i][j] != -1; j++)
		{
			fout << "Judge Number: " << judgeNumber[i][j] << "   ";
			fout << "Score: " << score[i][j] << "\n";
		}
	}	
	return;
}

I noticed that you are placing redundant variables (underlined) in your method declarations, which I cleared off in ReadScores, and now here in PrintReport:

void PrintReport(ofstream& fout, int pianoPlayer[MAXMEMBERS], double score[MAXMEMBERS][MAXJUDGES], int numPlayers)

There is no need to do that because your arrays and numPlayers variables are all outside of any method declaration. This makes it globally available, which means any method in that .cpp file can access these variables (underlined):

#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;
const int MAXMEMBERS = 20;
const int MAXJUDGES = 8;
int ReadScores(ifstream& fin);
void PrintReport(ofstream& fout, int pianoPlayer[MAXMEMBERS], double score[MAXMEMBERS][MAXJUDGES],
				int numPlayers);
int ProcessScores(ifstream& fin);
int pianoPlayer[MAXMEMBERS];
double score[MAXMEMBERS][MAXJUDGES];
double weightFactor[MAXMEMBERS];
int profLevel[MAXMEMBERS];
int judgeNumber[MAXMEMBERS][MAXJUDGES];
int category;  //category of music the students are playing
int judgeCount[MAXMEMBERS];
int numPlayers;
int i= 0;
int j= 0;
int main()
{
	ifstream fin;
	ofstream fout;

	fin.open("PianoREV.data");
	if (fin.fail())
	{
		cout << "Error: Input File";
		exit (1);
	}
...

By the way, looking at the source code you gave, that shouldn't compile at all. Your ProcessScores method is deformed. What's with that?

AstroNox
Junior Poster in Training
50 posts since Mar 2006
Reputation Points: 10
Solved Threads: 2
 

I copied it while in the middle of doing something. Kick ass I have prevented it from printing judges that dont exist. I am having problems with the average score thing. I need to average the score and then multiply it by the weight factor. From your post it doesnt seem like an aarray takes care of this. a 2-d array is supposed to handle the judges scores and weighted scores. How do i set that up. I did it like you pointed out and it kept on just shooting up 0. Also I am still reading beyong the number of players, instead i am reading until the max number I think. You are saving my ass by the way. Know I appreciate all this help. Here is what i did for the average score:

int ProcessScores(ifstream& fin)
{
	int numJudges;
	double weightedScore[i][j];
	double average[i];
	for (numJudges = 0; numJudges < MAXJUDGES && judgeNumber[i][j] != -1; ++numJudges)
	{
		totalScore[i][j] += score[i][j];
	}
	if (numJudges != 0)
	{
		average[i] = totalScore[i][j] / numJudges;
		i++;
	}
	return i;
}
lsu420luv
Light Poster
49 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

You might want to add two more global array variables first, assuming you need the unweighted and weighted:

int average[MAXMEMBERS];
int weightedScore[MAXMEMBERS];

Then you can calculate for each value with three loops. I don't know but you seemed to have thrown things together without much thought or understanding.

Assuming you want to calculated the averages for each student:

void ProcessScores ()
{
	int numJudges;
	double totalScore;
	for (int i = 0; i < numPlayers; ++i)
	{
		for (numJudges = 0, totalScore = 0; numJudges < MAXJUDGES && judgeNumber[i][j] != -1; ++numJudges)
		{
			totalScore += score[i][numJudges];
		}
		if (numJudges != 0)
			average[i] = totalScore / numJudges;
		weightedScore[i] = average[i] * weightFactor[i];
	}
}

I've changed your return type to void since it doesn't make sense to return anything. Also, I removed the ifstream& parameter because it is not necessary either.

Oh yes, you should not declare int i and int j globally, because usually those are used specifically in methods for loop counts, and it would be bad if you forget to reset them to zero for a certain loop.

Hope this helps, and I'm glad that I was able to provide you with assistance. If you truly like what I've done for you, I'd appreciate a small donation of any amount (via PayPal); PM me if you are willing and I'll give you my e-mail. Thanks!

AstroNox
Junior Poster in Training
50 posts since Mar 2006
Reputation Points: 10
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You