// ps1.cpp : A simple portfolio application.
//

#include "stdafx.h"
#include<iostream>
#include "Checking.h"
#include "Savings.h"
#include "Bond.h"
#include "Stock.h"
#include "Portfolio.h"

using namespace std;

//The output from this program should be:
//
//Checking:       CashAccount: balance=100
//Savings: interest=0.06  CashAccount: balance=200
//Savings: interest=0.06  CashAccount: balance=200
//Savings: interest=0.06  CashAccount: balance=200
//Bond: cost=133  yield=0.05
//Stock: numShares=10     pricepershare=14.5
//myNetWorth=$578
//myNetWorth=$653
//Portfolio Value = 1113.1
//Portfolio Value = 457.1
//Press any key to continue

int main(int argc, char* argv[])
{
	Checking myCheckAccount(100); //checking account with 100 dollars
	cout << myCheckAccount << endl;

	Savings mySavingsAccount(200, .06); //savings with 200 dollars and 6% interest
	cout << mySavingsAccount << endl;
	Savings * savingsCopy = new Savings(mySavingsAccount); //a copy constructor
	cout << (*savingsCopy) << endl;
	delete savingsCopy;
	cout << mySavingsAccount << endl; //just making sure you did copy it.

	Bond myBond(133, .05); //I buy a bond worth $133, with a 5% yield
	cout << myBond << endl;

	Stock myStock(10, 14.5); //I buy 10 shares of a stock at $14.50/share
	cout << myStock << endl;

	Security * pfolio[4];

	pfolio[0] = & myCheckAccount; //place them in array
	pfolio[1] = & mySavingsAccount;
	pfolio[2] = & myBond;
	pfolio[3] = & myStock;
	double myNetWorth = 0;
	for (int i =0; i <4 ; i++)
		//C++ determines what is the REAL type and call the appropiate function
		myNetWorth += pfolio[i]->presentValue();
	cout << "myNetWorth=$" << myNetWorth << endl; //how much am I worth?

	myStock.setSharePrice(22); //stock goes up in price

	myNetWorth = 0;
	for (i =0; i <4 ; i++)
		myNetWorth += pfolio[i]->presentValue();
	cout << "myNetWorth=$" << myNetWorth << endl; //how much am I worth?


	//You must implement the class Portfolio, which uses a template.
	// It stores a number of assets of the given type (here we use 
	//  Security, but you can imagine a Portfolio of RealEstate, or
	//  BeaniBabies, or anything that has a currentValue() function).
	// and automatically calculates the total currentValue
	//
	//TIP: Place all the Portfolio code on Portfolio.h, otherwise it
	// will not compile (see Stroustroup 13.7 for the reason, basically
	// VC++ has no export keyword, yet.)
	//
	//TIP: Portfolio should keep an array (you can hardwire the size to 4)
	// of pointers to Security.
	Portfolio<Security> allInv;
	Stock s1(15, 12.5);
	Stock s2(14, 9.4);
	Checking c1(138);
	Bond b1(656, .08);
	allInv.add(&s1);
	allInv.add(&s2);
	allInv.add(&c1);
	allInv.add(&b1);

	cout << "Portfolio Value = " << allInv.presentValue() << endl;

	allInv.removeLast();

	cout << "Portfolio Value = " << allInv.presentValue() << endl;

	return 0;
}
