| | |
help with parrallel arrays
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2006
Posts: 50
Reputation:
Solved Threads: 2
Hey lsu420luv,
Sorry for the reply like 8 hours later. You see, I live in Singapore and the reply you gave was at 4am SGT. Was asleep by then.
From what I saw in your previous post, I think you still do not comprehend quite a number of the C++ concepts... Here's what I did together with an explanation:
Ok, I've separated the globals, constants and methods. You should do that too. It makes reading them a lot easier.
Notice that I have also reduced your
Look at how I've reduced your file I/O code. You can simply open an
After that, you can check if the open succeeded simply by:
Basically, putting a stream as the condition of an
Is (sort of) the same as:
It's just much shorter. Why "sort of"? I will explain this later.
These are also present in the
If the input (
First of all, the stream you work with now is
You use the output operator (
And with the output operator, you tell
What I mean when that these operators are like methods and the return the stream you call them with, means that I call a method something like this happens when I use
Don't get it? Basically, this:
Is exactly the same as:
What does all these mean to you? Basically (look carefully at where the exclamation mark goes):
Is exactly the same as:
Which is also (sort of) the same as:
Why "sort of the same"? Because (look, no exclamation mark):
Is actually doing this:
(And of course,
It's sort of the same, because
Now, what is
I've used
You were asking why your
You used
Putting everything together, here is the full source code:
Ok, I admit, all the help I gave you thus far are all done without the use of a compiler. I wasn't able to get my C++ compiler up but I can give you the guarantee that the code works. It should. Unless I make some careless mistake, which I believe I didn't.
I would recommend two books if you intend to go into C++:
The second is also a must-have for every C++ programmer. The Standard Library is the equivalent of the Java API for C++ (though not as extensive), and no other book gives a tutorial and reference on it as worth as Mr. Josuttis'.
It's sometimes hard to find a good reference on the Internet (which is surprising), so I had to rely on these books for C++ help. In fact, these two books propelled me into programming C++.
You can also check out How Not to Program in C++ by Steve Oualline. It's a rather light-hearted good read on the common mistakes people make with C++.
I believe all's done and you can submit your work. It's been nice working with ya on this, and if there's anything else that needs to be done, don't hesitate to post it. I've sent the PM. Thanks again!
Sorry for the reply like 8 hours later. You see, I live in Singapore and the reply you gave was at 4am SGT. Was asleep by then.
From what I saw in your previous post, I think you still do not comprehend quite a number of the C++ concepts... Here's what I did together with an explanation:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <cstdlib> using namespace std; // Const Fields const int MAXMEMBERS = 20; const int MAXJUDGES = 5; // Globals int pianoPlayer[MAXMEMBERS]; double score[MAXMEMBERS][MAXJUDGES]; double weightFactor[MAXMEMBERS]; int profLevel[MAXMEMBERS]; int judgeNumber[MAXMEMBERS][MAXJUDGES]; double average[MAXMEMBERS]; int weightedScore[MAXMEMBERS]; int category; //category of music the students are playing int judgeCount[MAXMEMBERS]; int numPlayers; // Methods int ReadScores(ifstream& fin); void PrintReport(ofstream& fout); void ProcessScores();
Notice that I have also reduced your
PrintReport method that it only takes in an ofstream as its parameter. Remember what I told you about global variables? Since all the variables required by PrintReport are global (i.e. declared outside of any method), you can access them without passing them as parameters into the method. C++ Syntax (Toggle Plain Text)
int main() { ifstream fin("PianoREV.data"); ofstream fout("Report.out"); if (!fin) { cout << "Error: Input File"; return 1; } if (!fout) { cout << "Error: Output File"; return 1; } numPlayers = ReadScores(fin); ProcessScores(); PrintReport(fout); fin.close(); fout.close(); }
ifstream or ofstream by calling their constructors; in other words, just by doing this: C++ Syntax (Toggle Plain Text)
ifstream fin("PianoREV.data"); ofstream fout("Report.out");
C++ Syntax (Toggle Plain Text)
if (!fin) { cout << "Error: Input File"; return 1; } if (!fout) { cout << "Error: Output File"; return 1; }
if statement tells you if it is still valid. Doing this: C++ Syntax (Toggle Plain Text)
if (!fin)
C++ Syntax (Toggle Plain Text)
if (fin.fail())
These are also present in the
ReadScores method, the one that you've been using (underlined):int ReadScores (ifstream& fin)
{
int i= 0;
int j= 0;
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 we have too many judges
{
// 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)
{
judgeCount[i] = MAXJUDGES; // Set judgeCount to limit
break;
}
else
continue;
}
if (!(fin >> judgeNumber[i][j]) || judgeNumber[i][j] == -1)
{
judgeCount[i] = j;
break;
}
if (!(fin >> score[i][j]))
{
judgeCount[i] = j;
break;
}
}
}
return i;
}>>) and output (<<) operators makes it look confusing, think of them as methods, and that these methods return the stream you call them with. What does this mean? Whenever you do something like: C++ Syntax (Toggle Plain Text)
cout << "Bob" << 123 << "Tom" << endl;
cout.You use the output operator (
<<) on cout.And with the output operator, you tell
cout to print "Bob", 123, "Tom" and endl (I'll explain endl later) Understood so far?What I mean when that these operators are like methods and the return the stream you call them with, means that I call a method something like this happens when I use
<< (C++ pros, don't flame me with this, it's just an abstraction for explanation):ostream& << (ostream& s)
{
// Some logic ...
return s;
} C++ Syntax (Toggle Plain Text)
cout << "Bob" << 123 << "Tom" << endl;
C++ Syntax (Toggle Plain Text)
cout << "Bob"; cout << 123; cout << "Tom"; cout << endl;
if (!(fin >> pianoPlayer[i]))
break;fin >> pianoPlayer[i]; if (!fin) break;
fin >> pianoPlayer[i]; if (fin.fail()) break;
if (fin) if (fin.good())if (!fin) the same as if (!fin.good()), the NOT operator (!) just changes true to false and vice versa).It's sort of the same, because
fin.good() is not just the opposite of fin.fail()! It's also the opposite of fin.eof() and fin.bad(). What are these?fin.eof()returnstrueif the End-Of-File (EOF) has been reached.fin.fail()returnstrueif some I/O error occurred.fin.bad()returnstrueif some fatal I/O error occurred.
if (!fin.good()), or simply if (!fin) checks for all these possible errors.Now, what is
endl? endl is the C++ representation of a newline. You should not use "\n" because this is quite restricted as different OSes use different line terminators. *nix will use "\n" but Windows "\r\n". In order to make your code compile without being OS specific, you should use endl.I've used
endl in your PrintReport method too (underlined):void PrintReport (ofstream& fout)
{
for (int i = 0; i < numPlayers; ++i)
{
fout << "Piano Player: " << pianoPlayer[i] << endl;
for (int j = 0; j < judgeCount[i]; ++j)
{
fout << "Judge Number: " << judgeNumber[i][j] << " "
<< "Score: " << score[i][j] << endl;
}
fout << "Average Score: " << average[i] << endl
<< "Weighted Score: " << weightedScore[i] << endl << endl;
}
}PrintReport method print every player and judge? Look at the changes (underlined):void PrintReport (ofstream& fout)
{
for (int i = 0; i < numPlayers; ++i)
{
fout << "Piano Player: " << pianoPlayer[i] << endl;
for (int j = 0; j < judgeCount[i]; ++j)
{
fout << "Judge Number: " << judgeNumber[i][j] << " "
<< "Score: " << score[i][j] << endl;
}
fout << "Average Score: " << average[i] << endl
<< "Weighted Score: " << weightedScore[i] << endl << endl;
}
}MAXMEMBERS and MAXJUDGES earlier, and that's why you print to MAXMEMBERS and MAXJUDGES! It's that simple a logic error. Since you said you wanted a judgeCount array, I've included it in too. Notice that this is also reflected in the ReadScores method; ReadScores will determine how many judges are there per student (underlined):int ReadScores (ifstream& fin)
{
int i= 0;
int j= 0;
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 we have too many judges
{
// 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)
{
judgeCount[i] = MAXJUDGES; // Set judgeCount to limit
break;
}
else
continue;
}
if (!(fin >> judgeNumber[i][j]) || judgeNumber[i][j] == -1)
{
judgeCount[i] = j;
break;
}
if (!(fin >> score[i][j]))
{
judgeCount[i] = j;
break;
}
}
}
return i;
}
In case that you do not know what break and continue is, break terminates the innermost loop and continues immediately on the code outside the loop. continue forces the loop to reiterate and evaluate the condition immediately, not executing the remaining code before a normal iteration.
As for ProcessScores, I've also changed it to use judgeCount. Other than that, nothing else is changed. I was unable to find any fault with the logic.
void ProcessScores ()
{
int j;
double totalScore;
for (int i = 0; i < numPlayers; ++i)
{
for (j = 0, totalScore = 0; j < judgeCount[i]; ++j)
{
totalScore += score[i][j];
}
if (j != 0)
average[i] = totalScore / j;
weightedScore[i] = average[i] * weightFactor[i];
}
}Putting everything together, here is the full source code:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <cstdlib> using namespace std; // Const Fields const int MAXMEMBERS = 20; const int MAXJUDGES = 5; // Globals int pianoPlayer[MAXMEMBERS]; double score[MAXMEMBERS][MAXJUDGES]; double weightFactor[MAXMEMBERS]; int profLevel[MAXMEMBERS]; int judgeNumber[MAXMEMBERS][MAXJUDGES]; double average[MAXMEMBERS]; int weightedScore[MAXMEMBERS]; int category; //category of music the students are playing int judgeCount[MAXMEMBERS]; int numPlayers; // Methods int ReadScores(ifstream& fin); void PrintReport(ofstream& fout); void ProcessScores(); int main() { ifstream fin("PianoREV.data"); ofstream fout("Report.out"); if (!fin) { cout << "Error: Input File"; return 1; } if (!fout) { cout << "Error: Output File"; return 1; } numPlayers = ReadScores(fin); ProcessScores(); PrintReport(fout); fin.close(); fout.close(); } int ReadScores (ifstream& fin) { int i= 0; int j= 0; 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 we have too many judges { // 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) { judgeCount[i] = MAXJUDGES; // Set judgeCount to limit break; } else continue; } if (!(fin >> judgeNumber[i][j]) || judgeNumber[i][j] == -1) { judgeCount[i] = j; break; } if (!(fin >> score[i][j])) { judgeCount[i] = j; break; } } } return i; } void ProcessScores () { int j; double totalScore; for (int i = 0; i < numPlayers; ++i) { for (j = 0, totalScore = 0; j < judgeCount[i]; ++j) { totalScore += score[i][j]; } if (j != 0) average[i] = totalScore / j; weightedScore[i] = average[i] * weightFactor[i]; } } void PrintReport (ofstream& fout) { for (int i = 0; i < numPlayers; ++i) { fout << "Piano Player: " << pianoPlayer[i] << endl; for (int j = 0; j < judgeCount[i]; ++j) { fout << "Judge Number: " << judgeNumber[i][j] << " " << "Score: " << score[i][j] << endl; } fout << "Average Score: " << average[i] << endl << "Weighted Score: " << weightedScore[i] << endl << endl; } }
Ok, I admit, all the help I gave you thus far are all done without the use of a compiler. I wasn't able to get my C++ compiler up but I can give you the guarantee that the code works. It should. Unless I make some careless mistake, which I believe I didn't.
I would recommend two books if you intend to go into C++:
- C++: The Complete Reference, 4th Edition by Herbert Schildt
- The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis
The second is also a must-have for every C++ programmer. The Standard Library is the equivalent of the Java API for C++ (though not as extensive), and no other book gives a tutorial and reference on it as worth as Mr. Josuttis'.
It's sometimes hard to find a good reference on the Internet (which is surprising), so I had to rely on these books for C++ help. In fact, these two books propelled me into programming C++.
You can also check out How Not to Program in C++ by Steve Oualline. It's a rather light-hearted good read on the common mistakes people make with C++.
I believe all's done and you can submit your work. It's been nice working with ya on this, and if there's anything else that needs to be done, don't hesitate to post it. I've sent the PM. Thanks again!
Best Regards, God Bless,
AstroNox
AstroNox
•
•
Join Date: Mar 2006
Posts: 50
Reputation:
Solved Threads: 2
Finally got my C++ compiler working. I've compiled the code and fixed some small compilation warnings:
Enjoy.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <cstdlib> using namespace std; // Const Fields const int MAXMEMBERS = 20; const int MAXJUDGES = 5; // Globals int pianoPlayer[MAXMEMBERS]; double score[MAXMEMBERS][MAXJUDGES]; double weightFactor[MAXMEMBERS]; int profLevel[MAXMEMBERS]; int judgeNumber[MAXMEMBERS][MAXJUDGES]; double average[MAXMEMBERS]; double weightedScore[MAXMEMBERS]; int category; //category of music the students are playing int judgeCount[MAXMEMBERS]; int numPlayers; // Methods int ReadScores(ifstream& fin); void PrintReport(ofstream& fout); void ProcessScores(); int main() { ifstream fin("PianoREV.data"); ofstream fout("Report.out"); if (!fin) { cout << "Error: Input File"; return 1; } if (!fout) { cout << "Error: Output File"; return 1; } numPlayers = ReadScores(fin); ProcessScores(); PrintReport(fout); fin.close(); fout.close(); } int ReadScores (ifstream& fin) { int i= 0; 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 we have too many judges { // 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) { judgeCount[i] = MAXJUDGES; // Set judgeCount to limit break; } else continue; } if (!(fin >> judgeNumber[i][j]) || judgeNumber[i][j] == -1) { judgeCount[i] = j; break; } if (!(fin >> score[i][j])) { judgeCount[i] = j; break; } } } return i; } void ProcessScores () { int j; double totalScore; for (int i = 0; i < numPlayers; ++i) { for (j = 0, totalScore = 0; j < judgeCount[i]; ++j) { totalScore += score[i][j]; } if (j != 0) average[i] = totalScore / j; weightedScore[i] = average[i] * weightFactor[i]; } } void PrintReport (ofstream& fout) { for (int i = 0; i < numPlayers; ++i) { fout << "Piano Player: " << pianoPlayer[i] << endl; for (int j = 0; j < judgeCount[i]; ++j) { fout << "Judge Number: " << judgeNumber[i][j] << " " << "Score: " << score[i][j] << endl; } fout << "Average Score: " << average[i] << endl << "Weighted Score: " << weightedScore[i] << endl << endl; } }
Best Regards, God Bless,
AstroNox
AstroNox
•
•
Join Date: Mar 2006
Posts: 49
Reputation:
Solved Threads: 0
I know that I am not that good. The reason I do not understand that if (!(fin stuff is because we have not learned it yet. I am not supposed to use things we have not learned yet. Thanks for making it work though. I will check my pm's. An ideas on how to add a selection sort. I hope you check this before 12 noon tommorow because that is when it is due
•
•
Join Date: Mar 2006
Posts: 49
Reputation:
Solved Threads: 0
I want to sort by weighted player average descending. Also can you change the
I know it seems like I dont know what I am doing, but it is only partially that. I have to do it how she wants it. Here is what I have so far. I had to change some things to setup 2d arrays for weighted scores. she wants each score for each judge weigted. Everything is fine except those lines above and the selection sort. I need a sort of average[i] descending. Here is the code exactly how i need it except for those two things.
the problem is that she is a bad teacher. I usually learn things on my own and this summer will become a c++ guru. I have learned a hell of a lot of stuff on my own, but never on time restraints doing shit the way someone else wants it. For instance why would she make me use an inferior method to the one you used? No one knows, but that is neither here nor there. All your help is greatly appreciated. The program runs great.
C++ Syntax (Toggle Plain Text)
if (!(fin >> judgeNumber[i][j]) || judgeNumber[i][j] == -1) { judgeCount[i] = j; break; } if (!(fin >> score[i][j])) { judgeCount[i] = j; break; }
I know it seems like I dont know what I am doing, but it is only partially that. I have to do it how she wants it. Here is what I have so far. I had to change some things to setup 2d arrays for weighted scores. she wants each score for each judge weigted. Everything is fine except those lines above and the selection sort. I need a sort of average[i] descending. Here is the code exactly how i need it except for those two things.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <cstdlib> using namespace std; // Const Fields const int MAXMEMBERS = 20; const int MAXJUDGES = 7; //set text values to numbers for switch statement for CatType typedef int CATEGORY; const int BALLAD = 1; const int CONCERTO = 2; const int MODERN = 3; const int SONATA = 4; const int WALTZ = 5; //set text values to numbers for switch statement for ProfLevel typedef int PROFICIENCY; const int PRIMARY = 1; const int INTERMEDIATE = 2; const int ADVANCEDINTERMEDIATE = 3; const int SENIOR = 4; // Globals int pianoPlayer[MAXMEMBERS]; double score[MAXMEMBERS][MAXJUDGES]; double weightFactor[MAXMEMBERS]; int profLevel[MAXMEMBERS]; int judgeNumber[MAXMEMBERS][MAXJUDGES]; double average[MAXMEMBERS]; double weightedScore[MAXMEMBERS][MAXJUDGES]; int categoryName; //category of music the students are playing int judgeCount[MAXMEMBERS]; int numPlayers; // Methods int ReadScores(ifstream& fin); void PrintReport(ofstream& fout); void ProcessScores(); void SwitchCatType(ofstream& fout,CATEGORY categoryName); void SwitchProfLevel(ofstream& fout, PROFICIENCY profLevel[MAXMEMBERS]); void Header(ofstream& fout); void SetFormat(ofstream& fout); int main() { ifstream fin("PianoREV.data"); ofstream fout("Report.out"); if (!fin) { cout << "Error: Input File"; return 1; } if (!fout) { cout << "Error: Output File"; return 1; } numPlayers = ReadScores(fin); ProcessScores(); PrintReport(fout); fin.close(); fout.close(); } /************************************************************************************************/ /* Function Name: SetFormat */ /* Function Purpose: Setup formatting of fout */ /* Input Parameters: none */ /* Return value: none */ /************************************************************************************************/ void SetFormat (ofstream& fout) { fout.setf(ios::fixed); fout.setf(ios::showpoint); fout.precision(1); return; } //end Set Format /************************************************************************************************/ /* Function Name: Header */ /* Function Purpose: Output the header of file */ /* Input Parameters: none */ /* Return value: none */ /************************************************************************************************/ void Header (ofstream& fout) { // output header to file fout << " \n\n Federation of Music Teachers\n"; fout << " Mardi Gras Piano Invitational Competition\n"; fout << " Baton Rouge, Louisiana\n\n"; return; } //end Header int ReadScores (ifstream& fin) { int i= 0; fin >> categoryName; while (fin >> pianoPlayer) // input profLEvel, weightFactor, judgeNumbers, and scores fin >> profLevel[i]; fin >> weightFactor[i]; // Process the judges for (int j = 0; fin; ++j) { if (!(fin >> judgeNumber[i][j]) || judgeNumber[i][j] == -1) { judgeCount[i] = j; break; } if (!(fin >> score[i][j])) { judgeCount[i] = j; break; } } } return i; } void ProcessScores () { int j; double totalScore; for (int i = 0; i < numPlayers; i++) { for (j = 0; j < judgeCount[i]; j++) { weightedScore[i][j] = score[i][j] * weightFactor[i]; totalScore += weightedScore[i][j]; } average[i] = totalScore / j; totalScore = 0; } } /************************************************************************/ /* Function Name: SwitchProfLevel */ /* Function Purpose: determine what level player is and output the level*/ /* ftom numerical to actually name ex: 1 is primary */ /* Input Parameters: level */ /* Return value: none */ /************************************************************************/ void SwitchProfLevel(ofstream& fout, PROFICIENCY profLevel[MAXMEMBERS]) { int i = 0; switch (profLevel[i]) { case PRIMARY: fout << " Primary\n"; break; case INTERMEDIATE: fout << " Intermediate\n"; break; case ADVANCEDINTERMEDIATE: fout << " Advanced Intermediate\n"; break; case SENIOR: fout << " Senior\n"; break; default: cout << " Invalid Proficiency Level\n"; break; } } //end SwitchProfLevel /************************************************************************/ /* Function Name: SwitchCatType */ /* Function Purpose: determine what category player is and output */ /* from numerical to actually name ex: 1 is Ballad */ /* Input Parameters: categoryName */ /* Return value: none */ /************************************************************************/ void SwitchCatType(ofstream& fout,CATEGORY categoryName) { switch (categoryName) { case BALLAD: fout << " Ballad\n"; break; case CONCERTO: fout << " Concerto\n"; break; case MODERN: fout << " Modern\n"; break; case SONATA: fout << " Sonata\n"; break; case WALTZ: fout << " Waltz\n"; break; default: cout << " Invalid Category\n"; break; } } //end SwitchCatType /************************************************************************/ /* Function Name: PrintReport */ /* Function Purpose: Recieve arrays and print to output file */ /* Input Parameters: pianoPlayer, score, judgeNumber, judgeCount */ /* Return value: none */ /************************************************************************/ void PrintReport(ofstream& fout) { int i=0, j=0; Header(fout); SetFormat(fout); for (i = 0; i < numPlayers; i++) { //output piano player and category fout << "Piano Player: "; fout << pianoPlayer[i] << "\n"; fout << "Category:"; // call switch function for category and Proficiency SwitchCatType(fout, categoryName); fout << "Proficiency Level:"; SwitchProfLevel(fout, profLevel); fout << " "; //outpur judges' to file use switch to get correct amount for (j =0; j < judgeCount[i]; j++) { fout << "Judge"; fout.width(10); } fout << "\n "; // output judges' numbers for (j =0; j < judgeCount[i]; j++) { fout.width(7); fout << judgeNumber[i][j] << " "; } fout << "\n -----------------------------------------------------------------------\n"; fout << " "; //output scores for (j =0; j < judgeCount[i]; j++) { fout.width(7); fout << score[i][j] << " "; } fout << "\n "; //output weighted scores for (j =0; j < judgeCount[i]; j++) { fout.width(7); fout << weightedScore[i][j] << " "; } fout << "\nWeight: " << weightFactor[i]; fout << "\nAverage Score: " << average[i] << "\n\n\n"; } return; } //end PrintReport
the problem is that she is a bad teacher. I usually learn things on my own and this summer will become a c++ guru. I have learned a hell of a lot of stuff on my own, but never on time restraints doing shit the way someone else wants it. For instance why would she make me use an inferior method to the one you used? No one knows, but that is neither here nor there. All your help is greatly appreciated. The program runs great.
•
•
Join Date: Mar 2006
Posts: 50
Reputation:
Solved Threads: 2
Before I start working on those, let me confirm these:
Also, I'm sorry if I demeaned or offended you in anyway indirectly or directly (regarding the "you seemed not to know what you're doing" part). Yes, I understand now, that your lecturer is making things difficult for you. Just wanted to clear that up too.
- You want the sort to be descending, according to
average. This means if I have:
4, 6, 3, 8, 1, 5, 7
You want it to be sorted as:
8, 7, 6, 5, 4, 3, 1 - A thing to note is that, if you were to sort the
average, means that every single array is implicated—they all need to be sorted in relation to theaveragearray. A lazy version of this is to have an index, i.e., another array to store the sorted indices of the arrays. I think the second method is a far more efficient and less error prone method, but I do not know if you are allowed to do such a thing.
Also, I'm sorry if I demeaned or offended you in anyway indirectly or directly (regarding the "you seemed not to know what you're doing" part). Yes, I understand now, that your lecturer is making things difficult for you. Just wanted to clear that up too.
Best Regards, God Bless,
AstroNox
AstroNox
•
•
Join Date: Mar 2006
Posts: 49
Reputation:
Solved Threads: 0
no you didnt offend me. I am just used to being the one that solves all the problems. She has led us into the darka with no flashlight. How she does the selection if this helps is by seting a low index and a target. i believe it checks to see if each one is the low value and if it is resets that as the low one. she just gave us
selection = 0
low integer = -0
j = i+1
j = 1
low index j==2, low index j =2 or something. the lowindex i value change the values. I hope this helkps. I would think it would be the sloppier. she likes to do this shit. Any thoughts on how to replace the if(!( statements. I did it for profLevel and weight factor but cannot seem to get the others.
selection = 0
low integer = -0
j = i+1
j = 1
low index j==2, low index j =2 or something. the lowindex i value change the values. I hope this helkps. I would think it would be the sloppier. she likes to do this shit. Any thoughts on how to replace the if(!( statements. I did it for profLevel and weight factor but cannot seem to get the others.
•
•
Join Date: Mar 2006
Posts: 50
Reputation:
Solved Threads: 2
I know how to do a selection sort algorithm, no worry on that. But I need answers to those two questions...
I'm working on the simplification of those statements, don't worry about that.
- Are you sure you want it descending?
- Do you want the sort to reshuffle ALL the arrays, or you want an additional array that stores the sorted indices of all the arrays?
I'm working on the simplification of those statements, don't worry about that.
Best Regards, God Bless,
AstroNox
AstroNox
![]() |
Other Threads in the C++ Forum
- Previous Thread: Need help with Array Validation
- Next Thread: Stacks - balanced parentheses
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg simple sorting string strings temperature template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





