/**************************************************************************************************/
/*                                                                                                */
/*  Name:  DarC KonQuesT                                                                          */
/*  Program:  #5                                                                                  */
/*  Date:  2005.5.2                                                                               */
/*  Purpose:                                                                                      */
/*  stockListType class implementation file, which allows for creating binary search trees        */
/*  (using bst.h) of type stockType (from stockType.h/cpp).                                       */
/*  Includes operator overloading and assorted functions.                                         */   
/*                                                                                                */
/*                                                                                                */
/**************************************************************************************************/
#include <iostream>
#include <string>
#include <cassert>
#include "stockType.h"
#include "stockListType.h"
#include "bst.h"

using namespace std;

//operator overloading - populates list with data
istream& operator>>(istream& input, stockListType& stock_list) {
  while(input>>stock_list.stock_in)
	{
	  stock_list.tree.insert(stock_list.stock_in);
	}
  return input;
}

//operator overloading for outputing the BST
ostream& operator<<(ostream& output, stockListType& stock_list) 
{
  stock_list.itr1 = stock_list.tree.begin();
  stock_list.total_assets = 0;
  
  while(stock_list.itr1 != stock_list.tree.end())
  {
    stock_list.total_assets += (*stock_list.itr1).add_assets();
    output << *stock_list.itr1;
    stock_list.itr1++;
  }
  return output;
}

/*  Name: stockListType - constructor                                                                                 */
/*  Purpose: Inherits BinSearchTree                                                                                   */
/*  Parameters:  None                                                                                                 */
/*  Preconditions:  BinSearchTree exists                                                                              */
/*  Postconditions:  Inheritance is setup                                                                             */


stockListType::stockListType(): BinSearchTree<stockType>() {
	
}


/*  Name:  print_head()                                                                                               */
/*  Purpose:  Outputs the header labels of the data to be output                                                      */
/*  Parameters:  None                                                                                                 */
/*  Preconditions:  None                                                                                              */
/*  Postconditions:  Header is output, ready for data                                                                 */

void stockListType::print_head()
{
    cout << endl << "*********    First Investor's Heaven    *********"
         << endl << "*********         Financial Report      *********" << endl
         << "Stock" << setw(22) << "Today" << setw(25) << "Previous" << setw(10) << "Percent"
         << endl << "Symbol" << setw(7) << "Open" << setw(11) << "Close" << setw(8) << "High"
         << setw(8) << "Low" << setw(9) << "Close" << setw(10) << "Gain" << setw(12) << "Volume"
         << endl << "------" << setw(8) << "-----" << setw(10) << "-----"
         << setw(9) << "-----" << setw(9) << "-----" << setw(9) << "-------" << setw(10) << "------"
         << setw(10) << "------" << endl;
}
         
/*  Name:  print_foot()                                                                                               */
/*  Purpose:  Outputs the footer labels of the data to be output as well as the assets                                */
/*  Parameters:  None                                                                                                 */
/*  Preconditions:  Assets calculated                                                                                 */
/*  Postconditions:  Footer finishes data output, and total assets is output                                          */

void stockListType::print_foot()
{  
         cout << "Closing Assets: $" << total_assets << endl;
         cout << "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-" << endl;
                                              
}

