/*********************************************************************/ /*Program Name: Stockmarket Game */ /*Source Code Name: Pitcherf1.cpp */ /*Description: A simulation of a one trader, checks the values on the*/ /* stock market and makes decisions with the information.*/ /*********************************************************************/ #include #include "..\market\Trader.h" #include "..\traders\Pitcherf1.h" /******************************************************************/ /*Class:Pitcherf1 */ /*Member function:Think () */ /*Description: To Get the Stock Info and Save key attributes,in */ /* in this case (Current Price of Stock and Number of */ /* stock left. Number of stock left is collected on */ /* the hour which trading will occur. */ /******************************************************************/ void Pitcherf1::Think () { mybroker = GetBroker(); mybroker->GetStockMarketInfo(Info); for (int i=0;iGetStockInfo(Ticker[i],sd); CurrentPrice[i]=sd.CurrentPrice; } if (num==15)//Gets Price of hour 15 StockInfo and Number of Stocks { stock=mybroker->GetStockInfo(Ticker[i],sd); NewDayPrice[i]=sd.CurrentPrice; AmountofStock[i]=sd.NumOutstanding; } } num++;//increments num of times think has been called }; /*******************************************************************/ /*Class Name:Pitcherf1 */ /*Member Function Name:Trade() */ /*Program Description: To buy stocks only once, "long term trader".*/ /* The requirements in order for it to buy stock is */ /* to have enough money, balance must be over 5,000 */ /* and to make sure the stock has that many stocks. */ /*******************************************************************/ int Pitcherf1::Trade () { balance=mybroker->GetBalance();//Gets Pitcherf1's balance if (balance>5000 && days==15) { //Loops through all the stocks comparing them to see if stock //has increased, if it does, buy 15 shares of it. for (int i=0;i5000) { if ( AmountofStock[i]>15)//error checking, check to see if there is enough stock { mybroker->Buy (Ticker[i], 15);//if there is buy it } } balance=mybroker->GetBalance ();//Update balance } } days ++;//increment the number of hours that has passed return 0; }; Pitcherf1::~Pitcherf1() { //delete mybroker; //deletes my Broker };