Monday, May 24, 2010

Those familiar with STL in C++ Please Help?

If you guys have been following my last questions you will see that I have learned alot but still need some help. I have finally gotten my program to work with the vector of structs. Now I need to be able to show the name(s) of the highest scorer(s) and the name(s) of the lowest scorer(s). The names and the scores are stored inside the vector%26lt;Grades%26gt; Grade; vector of structs so Grade[0].names = "Mike" and Grade[0].scores = 90








Here is my program thus far it is error free as of now.





// In a header file


#ifndef GRADES_H


#define GRADES_H





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using namespace std;





struct Grades


{


string names;


int scores;


};





#endif

Those familiar with STL in C++ Please Help?
Do the for loop, but do the swap inside for the highest score.


Say


int hightest=0


int lowest = 1000


int position=-1;//used to hold position of highest





for (int count = 0; count %26lt;= 4; count++)


{


if(VGrade[count].scores %26gt; highest)//first one will be


{


position = count;


highest=VGrade[count].scores


}





}


Now you know the position of who has the highest and using position for name of highest (or lowest)
Reply:What's the question? By the way, the "Standard" Template Library is one of the main reasons why I don't think C++ is as beautiful as C. It seems there are as many different library implementations, and usages as there are companies willing to write compilers. Will your program work on every compiler, or just most of them?


No comments:

Post a Comment