| | |
help with parrallel arrays
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2006
Posts: 49
Reputation:
Solved Threads: 0
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?
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?
C++ Syntax (Toggle Plain Text)
#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; }
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.
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.
•
•
Join Date: Jul 2005
Posts: 1,671
Reputation:
Solved Threads: 261
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?
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?
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.
or if you cannot yet handle that, you can create a structure and make a linked list of those structures
now just learn how to do linkes lists, and again you need not use
any c-style arrays.
C++ Syntax (Toggle Plain Text)
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
C++ Syntax (Toggle Plain Text)
struct judge { long JudgeID; float weight; struct judge* next; }; struct PianoRE { long PlayerID; long Proficiency; float WeightFactor; struct judges* HeadJudge; struct PianoRE* next; };
any c-style arrays.
•
•
Join Date: Mar 2006
Posts: 50
Reputation:
Solved Threads: 2
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.
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
C++ Syntax (Toggle Plain Text)
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; }
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. Best Regards, God Bless,
AstroNox
AstroNox
•
•
Join Date: Mar 2006
Posts: 49
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Mar 2006
Posts: 50
Reputation:
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.
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.
Best Regards, God Bless,
AstroNox
AstroNox
•
•
Join Date: Mar 2006
Posts: 49
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by AstroNox
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.
•
•
Join Date: Mar 2006
Posts: 49
Reputation:
Solved Threads: 0
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?
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.
C++ Syntax (Toggle Plain Text)
#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.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Need help with Array Validation
- Next Thread: Stacks - balanced parentheses
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






