Help Needed Print out top 5 objects!

"Return an array of five strings holding the five most frequently sold stocks (by total volume, not just number of transactions) or top five buyers (by purchased total volume, not just number of transactions. The function assumes that at least five different stocks / buyers are contained within the analyser. The output .array is sorted in order of decreasing volume."

Thats the questions given to me.

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

This is the struct the array of random transactions(objects) are made from. I could print out arrays with top 5 numShares for each object. But the problem is ive to add up each numShares for each tranaction in the array with the same stock symbol, then i have to return an array of strings returning the top 5 stockSymbols with the most numShares. E.g Stock symbol DELL could have 2000 numShares in one tranaction, 1500 in another, etc. Ive to add these up and return the stock symbols with the most numShare. I tried pasting my main class etc in here, but it took up too much room.. Any help appreciated!! Thanks very much in advance!

string* Analyser::topFiveStocks()

return new string[5];

A pointer to the array of tranasactions is sent into my anlayser class that the above method uses.
well, I would use two maps for that, but i don't think you allowed to use it. Am I right?
Last edited on
did you get anywhere with this one?
Yeah, that problem sure is a tricky one.

Get more fabulous scarves?
Topic archived. No new replies allowed.