#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;
class ID
{
private:
string name;
int score;
public:
friend bool operator < (const ID&, const ID&);
ID(string name, int score) :name(name), score(score){}
void display(){
cout.setf(ios::left);
cout << setw(3) << score << name << endl;
}
};
bool operator <(const ID& a, const ID& b){
return a.score < b.score;
}
typedef vector<ID> Vector;
int main(){
Vector v;
Vector::iterator iter;
v.push_back(ID("Smith A.",96));
v.push_back(ID("Amstrong B.",91));
v.push_back(ID("Waston D.",82));
for (iter = v.begin(); iter != v.end(); iter++){
iter->display();
}
sort(v.begin(), v.end());
cout << endl << "Sorted by Score" << endl;
cout << "====================" << endl;
for (iter = v.begin(); iter != v.end(); iter++){
iter->display();
}
cout << endl << "Reverse output" << endl;
cout << "=================" << endl;
Vector::reverse_iterator r = v.rbegin();
while (r != v.rend()){
r->display();
r++;
}
cout << endl;
return 0;
}