Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //preprocessor directives - libraries and classes used
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <iomanip>
- #define MAX_SYMBOL_SIZE 5
- #include "stock.cpp"
- #include "stocklist.cpp"
- //prototypes of >>Stock and <<Stocklist operators
- std::ifstream& operator>>(std::ifstream& fin, Stock& stock);
- std::ostream& operator<<(std::ostream& out, StockList& sl);
- int main()
- {
- //Create an object of stocklist
- //This will load and store the stocks listed in the file
- StockList sl;
- //if data can be loaded
- if (sl.load("StockData.txt\0") == true)
- {
- //sort the list and output it using the overloaded << operator
- sl.sort();
- std::cout << sl;
- return 0;
- }
- //if data could not be loaded.
- else
- {
- std::cout << "\nUnable to open file.\n";
- return 1;
- }
- }
- //overload >>Stock to parse a line and store in the correct member data
- std::ifstream& operator >>(std::ifstream& is, Stock &stock)
- {
- is >> stock.symbol
- >> stock.openingPrice
- >> stock.closingPrice
- >> stock.todayHigh
- >> stock.todayLow
- >> stock.prevClose
- >> stock.volume;
- return is;
- }
- //overload <<Stocklist to print the list of Stocks
- std::ostream& operator <<(std::ostream &os, StockList &sl)
- {
- sl.print();
- return os;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement