Hi i've an array and im looking to get the top 5 most frequently occuring from this array.
static std::string pickRandomStockSymbol()
{
static std::string stockSymbols[] = {"SIRI", "INTC", "ZNGA", "BBRY", "MSFT",
"QQQ", "CSCO", "FB", "MU", "DELL", "AMAT", "NWSA", "AAPL", "AFFY", "ORCL",
"YHOO", "GRPN", "MDLZ", "VOD", "CMCSA" };
return stockSymbols[rand() % 20];
^^ this is the array i will be using.
the transactions are randomly created using this struct:
struct Transaction
{
string stockSymbol; // String containing the stock symbol, e.g. "AAPL"
string buyerName; // String containing the buyer's name e.g. "Mr Brown"
int buyerAccount; // Integer containing an eight digit account code
int numShares; // Integer containing the number of sold shares
int pricePerShare; // Integer containing the buy price per share
};
it is within this function i plan to do this in, i just dont really know what way i approach this:
string* Analyser::topFiveStocks()
{
return new string[5];
}
is there anyone out there willing to show me how i could run through the transactions to get these top 5 occuring elements?
if there would be any more information needed i'll be more than happy to provide.
Thanks in advance, Andrew