#include #include #include using namespace std; class CSortData { public: char m_szSymbol[5]; long m_lVolume; double m_dLast; }; struct Arg2Sort { bool operator() (const CSortData & x, const CSortData & y ) { return x.m_lVolume > y.m_lVolume; } }; struct Arg3Sort { bool operator() (const CSortData & x, const CSortData & y ) { return x.m_dLast > y.m_dLast; } }; void main() { CSortData m_SortData; vector m_vecSortData; vector::iterator it; strcpy(m_SortData.m_szSymbol, "MSFT"); m_SortData.m_lVolume = 28785500; m_SortData.m_dLast = 55.88; m_vecSortData.push_back( m_SortData ); strcpy( m_SortData.m_szSymbol, "INTL" ); m_SortData.m_lVolume = 50503100; m_SortData.m_dLast = 31.44; m_vecSortData.push_back( m_SortData ); strcpy( m_SortData.m_szSymbol, "CSCO" ); m_SortData.m_lVolume = 100864300; m_SortData.m_dLast = 26.06; m_vecSortData.push_back( m_SortData ); cout << "\n" << endl; cout << " 02/21/01 NASDAQ Data " << endl; cout << "\n" << endl; cout << "/******************************" << endl; cout << "Symbol Volume Close " << endl; cout << "******************************/" << endl; cout << "\n" << endl; for ( it = m_vecSortData.begin(); it != m_vecSortData.end(); it++ ) cout << it->m_szSymbol << "\t" << it->m_lVolume << "\t" << it->m_dLast << endl; cout << "\n" << endl; cout << "/******************************" << endl; cout << " Sorted By Volume " << endl; cout << "******************************/" << endl; cout << "\n" << endl; std::sort( m_vecSortData.begin(), m_vecSortData.end(), Arg2Sort()); for ( it = m_vecSortData.begin(); it != m_vecSortData.end(); it++ ) cout << it->m_szSymbol << "\t" << it->m_lVolume << "\t" << it->m_dLast << endl; cout << "\n" << endl; cout << "/******************************" << endl; cout << " Sorted By Close " << endl; cout << "******************************/" << endl; cout << "\n" << endl; std::sort( m_vecSortData.begin(), m_vecSortData.end(), Arg3Sort() ); for ( it = m_vecSortData.begin(); it != m_vecSortData.end(); it++ ) cout << it->m_szSymbol << "\t" << it->m_lVolume << "\t" << it->m_dLast << endl; cout << "\n " << endl; }