Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stock.h"
- //Accessors for private data
- std::string Stock::get_symbol() const { return symbol;}
- float Stock::get_openingPrice() const { return openingPrice; }
- float Stock::get_closingPrice() const { return closingPrice; }
- float Stock::get_todayHigh() const { return todayHigh; }
- float Stock::get_todayLow() const { return todayLow; }
- float Stock::get_prevClose() const { return prevClose; }
- unsigned int Stock::get_volume() const { return volume; }
- //calculate todays gain in %
- float Stock::today_gain() const
- {
- return (closingPrice-prevClose)/prevClose*100;
- }
- //overload >Stock operator so it checks if the stock symbol
- //is alpabetically larger than another.
- //symbol[] here is the > left operand, r_symbol the right
- bool Stock::operator >(Stock& right) const
- {
- std::string r_symbol = right.get_symbol();
- //prepare to loop aal characters if needed
- for (int i=0; i < (MAX_SYMBOL_SIZE-1); i++)
- {
- //if first letter is smaller, exit function and return true
- if (symbol[i] > r_symbol[i])
- {
- return true;
- }
- //otherwise
- else if (symbol[i] == r_symbol[i])
- {
- //check the length of both symbols
- //if we're on last characters and
- //one is shorter than the other, exit function
- if ( symbol.length() < (i+2))
- {
- return false;
- }
- else if (r_symbol.length() < (i+2))
- {
- return true;
- }
- else
- {
- //still characters left, so continue the for loop
- continue;
- }
- }
- //if the first symbol was already smaller
- else
- {
- return false;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement