Hi,
This is what the program does:
-reads data (stock symbols, open price, closing price, high price, low price, previous price, and volume ) from a text file
-do some calculation to produce percent gain/loss for each stock and produce closing assets
-produce a list ordered by percent gain/loss and output the result
I hope I get some help here because I'm stuck and I don't know what else to do
this is what I have so far:
main
/*
* stockMarketMain.cpp
*
* Created on: Oct 29, 2010
*/
#include <iostream>
#include <cstring>
#include "listType.h"
#include "stockType.h"
using namespace std;
int main() {
stockListType stockList;
stockType stockTemp;
stockTemp.setStockInfo("IBD", 68.00, 71.00, 72.00, 67.00, 75.00, 15000);
stockList.insertAt(stockTemp, 0);
stockTemp.setStockInfo("MSET", 120.00, 140.00, 145.00, 140.00, 115.00, 30920);
stockList.insertAt(stockTemp, 1);
stockTemp.setStockInfo("AOLK", 80.00, 75.00, 82.00, 74.00, 83.00, 5000);
stockList.insertAt(stockTemp, 2);
stockTemp.setStockInfo("CSCO", 100.00, 102.00, 105.00, 98.00, 101.00, 25000);
stockList.insertAt(stockTemp, 3);
stockTemp.setStockInfo("ABC", 123.45, 130.95, 132.00, 125.00, 120.50, 10000);
stockList.insertAt(stockTemp, 4);
//cin.get();
return 0;
}
stockType.h
#ifndef H_stockType
#define H_stockType
#include <iostream>
#include <fstream>
#include <cstring>
#include "myString.h"
using namespace std;
class stockType
{
friend ostream& operator<< (ostream&, const stockType&);
friend ifstream& operator>> (ifstream&, stockType&);
public:
void setStockInfo(newString symbol, double openPrice,
double closeProce, double high,
double Low, double prevClose,
int shares);
newString getSymbol();
double getPercentChange();
double getOpenPrice();
double getClosePrice();
double getHighPrice();
double getLowPrice();
double getPrevPrice();
int getnoOfShares();
stockType();
stockType(newString symbol, double openPrice,
double closeProce, double high,
double Low, double prevClose,
int shares);
int operator ==(stockType other);
int operator !=(stockType other);
int operator <=(stockType other);
int operator >=(stockType other);
int operator >(stockType other);
int operator <(stockType other);
private:
newString stockSymbol;
double todayOpenPrice;
double todayClosePrice;
double todayHigh;
double todayLow;
double yesterdayClose;
double percentChange;
int noOfShares;
};
//default constructor
stockType::stockType(){
stockSymbol = "***";
todayOpenPrice = 0.00;
todayClosePrice = 0.00;
todayHigh = 0.00;
todayLow = 0.00;
yesterdayClose = 0.00;
noOfShares = 0;
}
//constructor
stockType::stockType(newString symbol, double openPrice,
double closeProce, double high,
double Low, double prevClose,
int shares){
setStockInfo(symbol, openPrice, closeProce, high, Low, prevClose, shares);
}
void setStockInfo(newString symbol, double openPrice,
double closeProce, double high,
double Low, double prevClose,
int shares){
stockSymbol = symbol;
todayOpenPrice = openPrice;
todayClosePrice = closeProce;
todayHigh = high;
todayLow = low;
yesterdayClose = prevClose;
noOfShares = shares;
}
newString getSymbol(){
return stockSymbol;
}
double getPercentChange(){
percentChange = ((todayClosePrice - yesterdayClose) / yesterdayClose) * 100;
return percentChange;
}
double getOpenPrice(){
return todayOpenPrice;
}
double getClosePrice(){
return todayClosePrice;
}
double getHighPrice(){
return todayHigh;
}
double getLowPrice(){
return todayLow;
}
double getPrevPrice(){
return yesterdayClose;
}
int getnoOfShares(){
return noOfShares;
}
//Overload the relational operators.
bool stockType::operator==(const newString& rightStr) const{
return (strcmp(sortIndicesGainLoss, rightStr.sortIndicesGainLoss) == 0);
}
bool stockType::operator<(const newString& rightStr) const{
return (strcmp(sortIndicesGainLoss, rightStr.sortIndicesGainLoss) < 0);
}
bool stockType::operator<=(const newString& rightStr) const{
return (strcmp(sortIndicesGainLoss, rightStr.sortIndicesGainLoss) <= 0);
}
bool stockType::operator>(const newString& rightStr) const{
return (strcmp(sortIndicesGainLoss, rightStr.sortIndicesGainLoss) > 0);
}
bool stockType::operator>=(const newString& rightStr) const{
return (strcmp(sortIndicesGainLoss, rightStr.sortIndicesGainLoss) >= 0);
}
bool stockType::operator!=(const newString& rightStr) const{
return (strcmp(sortIndicesGainLoss, rightStr.sortIndicesGainLoss) != 0);
}
//Overload the stream insertion operator <<
ostream& operator<< (ostream& osObject, const stockType& stock){
osObject << stock.sortIndicesGainLoss;
return osObject;
}
//Overload the stream extraction operator >>
ifstream& operator>> (ifstream& isObject, stockType& stock){
char temp[81];
isObject >> setw(81) >> temp;
str = temp;
return isObject;
}
#endif
stockListType.h
#ifndef H_StockListType
#define H_StockListType
#include "listType.h"
#include "stockType.h"
class stockListType: public listType<stockType>
{
public:
void printBySymbol();
void printByGain();
void printReports();
void sort();
void sortByGain();
stockListType();
stockListType(int size);
private:
int *sortIndicesGainLoss;
};
#endif
#ifndef H_listType
#define H_listType
#include <iostream>
#include <cassert>
using namespace std;
template <class elemType>
class listType
{
public:
bool isEmpty() const;
//Function to determine whether the list is empty.
//Postcondition: Returns true if the list is empty,
// otherwise it returns false.
bool isFull() const;
//Function to determine whether the list is full.
//Postcondition: Returns true if the list is full,
// otherwise it returns false.
int getLength() const;
//Function to return the number of elements in the list.
//Postcondition: The value of length is returned.
int getMaxSize() const;
//Function to return the maximum number of elements
//that can be stored in the list.
//Postcondition: The value of maxSize is returned.
void sort();
//Function to sort the list.
//Postcondition: The list elements are in ascending order.
void print() const;
//Outputs the elements of the list.
void insertAt(const elemType& item, int position);
//Function to insert item in the list at the location
//specified by position.
//Postcondition: list[position] = item; length++;
// If position is out of range, the program
// is aborted.
listType(int listSize=100);
//Constructor
//Creates an array of the size specified by the
//parameter listSize; the default array size is 50.
//Postcondition: list contains the base address of the
// array; length = 0; maxsize = listSize;
protected:
int maxSize; //variable to store the maximum size
//of the list
int length; //variable to store the number of elements
//in the list
elemType *list; //pointer to the array that holds the
//list elements
};
template <class elemType>
bool listType<elemType>::isEmpty() const
{
return (length == 0);
}
template <class elemType>
bool listType<elemType>::isFull() const
{
return (length == maxSize);
}
template <class elemType>
int listType<elemType>::getLength() const
{
return length;
}
template <class elemType>
int listType<elemType>::getMaxSize() const
{
return maxSize;
}
//Constructor; the default array size is 50
template <class elemType>
listType<elemType>::listType(string, double, double, double, double, double, int)
{
maxSize = listSize;
length = 0;
list = new elemType[maxSize];
}
template <class elemType>
listType<elemType>::~listType() //destructor
{
delete [] list;
}
template <class elemType>
void listType<elemType>::sort() //selection sort
{
int i, j;
int min;
elemType temp;
for (i = 0; i < length; i++)
{
min = i;
for (j = i + 1; j < length; ++j)
if (list[j] < list[min])
min = j;
temp = list[i];
list[i] = list[min];
list[min] = temp;
}//end for
}//end sort
template <class elemType>
void listType<elemType>::print() const
{
int i;
for (i = 0; i < length; ++i)
cout << list[i] << " ";
cout << endl;
}//end print
template <class elemType>
void listType<elemType>::insertAt(const elemType& item,
int position)
{
assert(position >= 0 && position < maxSize);
list[position] = item;
length++;
}
#endif