Advertisement
Guest User

main.cpp

a guest
Jul 30th, 2012
640
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. //preprocessor directives - libraries and classes used
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include <iomanip>
  6.  
  7. #define MAX_SYMBOL_SIZE 5
  8.  
  9. #include "stock.cpp"
  10. #include "stocklist.cpp"
  11.  
  12. //prototypes of  >>Stock and <<Stocklist operators
  13. std::ifstream& operator>>(std::ifstream& fin, Stock& stock);
  14. std::ostream& operator<<(std::ostream& out, StockList& sl);
  15.  
  16. int main()
  17. {
  18.     //Create an object of stocklist
  19.     //This will load and store the stocks listed in the file
  20.     StockList sl;
  21.  
  22.     //if data can be loaded
  23.     if (sl.load("StockData.txt\0") == true)
  24.     {
  25.         //sort the list and output it using the overloaded << operator
  26.         sl.sort();
  27.         std::cout << sl;
  28.         return 0;
  29.     }
  30.  
  31.     //if data could not be loaded.
  32.     else
  33.     {
  34.         std::cout << "\nUnable to open file.\n";
  35.         return 1;
  36.     }
  37. }
  38.  
  39. //overload >>Stock to parse a line and store in the correct member data
  40. std::ifstream& operator >>(std::ifstream& is, Stock &stock)
  41. {
  42.     is  >> stock.symbol
  43.         >> stock.openingPrice
  44.         >> stock.closingPrice
  45.         >> stock.todayHigh
  46.         >> stock.todayLow
  47.         >> stock.prevClose
  48.         >> stock.volume;
  49.  
  50.     return is;
  51. }
  52. //overload <<Stocklist to print the list of Stocks
  53. std::ostream& operator <<(std::ostream &os, StockList &sl)
  54. {
  55.     sl.print();
  56.     return os;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement