/**************************************************************************************************/
/*                                                                                                */
/*  Name:  DarC KonQuesT                                                                          */
/*  Program:  #2                                                                                  */
/*  Date:  2005.2.8                                                                               */
/*  Purpose:                                                                                      */
/*  Implementation file for the stockType class - includes overloading, intialization             */
/*  and functions for asset and percent gain calculation                                          */  
/*                                                                                                */
/*                                                                                                */
/**************************************************************************************************/

#include <iostream>
#include <string>
#include <cassert>
#include <fstream>
#include "stockType.h"
#include <iomanip>

using namespace std;


/*  Name:  stockType() - constructor                                                                                  */
/*  Purpose: initialize stockType class variables                                                                     */
/*  Parameters: None                                                                                                  */
/*  Preconditions:  create stockType variables                                                                        */
/*  Postconditions:  stockType variables are initialized to default values                                            */

stockType::stockType() {
	symbol = "";
	opening_price = 0;
	closing_price = 0;
	today_high = 0;
	today_low = 0;
	prev_close = 0;
	volume = 0;

}

//relation operator overloading - by stock symbol
bool stockType::operator<(const stockType& stock) const {
          return(symbol < stock.symbol);
}

bool stockType::operator>(const stockType& stock) const {
	        return(symbol > stock.symbol);
}

bool stockType::operator==(const stockType& stock) const {
	        return(symbol == stock.symbol);
}


//stream insertion operator overloading for easy output
ostream& operator<<(ostream& output, const stockType& stock) {
	output << fixed << showpoint << setprecision(2);
	output << setw(6) << stock.symbol;
	output << setw(8) << stock.opening_price;
	output << setw(10) << stock.closing_price;
	output << setw(9) << stock.today_high;
	output << setw(9) << stock.today_low;
	output << setw(9) << stock.prev_close;
	output << setw(9) << (((stock.closing_price - stock.prev_close) / stock.prev_close) * 100) << "%";
	output << setw(10) << stock.volume << endl;
	
	return output;
}

//stream extraction overloading for easy input
istream& operator>>(istream& input, stockType& stock) {
	input >> stock.symbol;
	input >> stock.volume;
	input >> stock.closing_price;
	input >> stock.opening_price;
	input >> stock.today_high;
	input >> stock.today_low;
	input >> stock.prev_close;

	return input;
}


/*  Name: add_assets()                                                                                                */
/*  Purpose:  Calculate for a specific stock, done by multiplying volume times closing price                          */
/*  Parameters:  None                                                                                                 */
/*  Preconditions:  The stock's volume and closing_price variables must be filled with data.                          */
/*  Postconditions:  Returns asset price for current stock to be added to total                                       */

float stockType::add_assets() {
	return(volume * closing_price);

}


/*  Name:  percent_gain()                                                                                              */
/*  Purpose:  Calculate percent gain of current stock                                                                 */
/*  Parameters: None                                                                                                  */
/*  Preconditions:  Stock's closing_price and prev_close variables must be filled                                     */
/*  Postconditions:  returns percent gain of current stock                                                            */

float stockType::percent_gain() {
    return (((closing_price - prev_close) / prev_close) * 100);

}



