1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
#ifndef STOCKTYPE_H
#define STOCKTYPE_H
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
class stockType
{
public:
stockType(string symbol="", double openPrice=0.0, double closePrice=0.0, double highPrice=0.0,
double lowPrevPrice=0.0, double closePrevPrice=0.0, int shares=0);
friend istream& operator>>(istream& ins, stockType& stock);
friend ostream& operator<<(ostream& outs, const stockType& stock);
//sets the variables
void setStockInfo(string syms, double open, double close, double high,
double lowPrev, double closePrev, int no_of_shares);
//calculates the gain
void calculateGain(double closeP, double prevP);
bool operator==(const stockType& stock1) const;
bool operator!=(const stockType& stock1) const;
bool operator<=(const stockType& stock1) const;
bool operator<(const stockType& stock1) const;
bool operator>=(const stockType& stock1) const;
bool operator>(const stockType& stock1) const;
//member functions
string getSymbols()const {return symbols;}
double getOpenPrice()const {return open_price;}
double getClosePrice()const {return close_price;}
double getHighPrice()const {return high_price;}
double getLowPrevPrice()const {return low_prev_price;}
double getClosePrevPrice()const {return close_prev_price;}
double getShares()const {return no_shares;}
double getGain()const {return gain;}
private:
string symbols;
double open_price, close_price, high_price, low_prev_price, close_prev_price, gain;
int no_shares;
};
#include "stockType.h"
stockType::stockType(string symbol, double openPrice, double closePrice, double highPrice,
double lowPrevPrice, double closePrevPrice, int shares)
{
setStockInfo(symbol, openPrice, closePrice, highPrice, lowPrevPrice, closePrevPrice, shares);
}
void stockType::setStockInfo(string syms, double open, double close, double high,
double lowPrev, double closePrev, int no_of_shares)
{
symbols = syms;
open_price = open;
close_price = close;
high_price = high;
low_prev_price = lowPrev;
close_prev_price = closePrev;
no_shares = no_of_shares;
}
istream& operator>>(istream& ins, stockType& stock)
{
ins>>stock.symbols;
ins>>stock.open_price;
ins>>stock.close_price;
ins>>stock.high_price;
ins>>stock.low_prev_price;
ins>>stock.close_prev_price;
ins>>stock.no_shares;
stock.calculateGain(stock.close_price, stock.close_prev_price);
return ins;
}
ostream& operator<<(ostream& outs, const stockType& stock)
{
outs<<stock.getSymbols()
<<fixed<<showpoint<<setprecision(2)
<<setw(10)<<stock.getOpenPrice()<<setw(10)
<<stock.getClosePrice()<<setw(10)
<<stock.getHighPrice()<<setw(10)
<<stock.getLowPrevPrice()<<setw(11)
<<stock.getClosePrevPrice()
<<setw(10)<<stock.getGain()<<"%"<<setw(13)
<<stock.getShares()<<endl<<endl;
return outs;
}
void stockType::calculateGain(double closeP, double prevP)
{
gain = ((closeP - prevP)/(prevP)*100);
}
bool stockType::operator==(const stockType& stock1) const
{
return (symbols==stock1.symbols);
}
bool stockType::operator!=(const stockType& stock1) const
{
return (symbols!=stock1.symbols);
}
bool stockType::operator>=(const stockType& stock1) const
{
return (symbols>=stock1.symbols);
}
bool stockType::operator>(const stockType& stock1) const
{
return (symbols>stock1.symbols);
}
bool stockType::operator<=(const stockType& stock1) const
{
return (symbols<=stock1.symbols);
}
bool stockType::operator<(const stockType& stock1) const
{
return (symbols<stock1.symbols);
}
#ifndef stockListType_H
#define stockListType_H
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include "stockType.h"
using namespace std;
class stockListType
{
public:
stockListType()
{
}
void insert(const stockType& item);
void sortStockSymbols();
void sortStockGain();
void printStockSymbols();
void printStockGain();
private:
vector<int> indexByGain;
vector<stockType> list;
};
#endif
#include <algorithm>
#include "stockListType.h"
void stockListType::insert(const stockType& item)
{
list.push_back(item);
}
void stockListType::printStockSymbols()
{
int k = 0;
double closing_assets = 0;
cout<<"***************** First Investor's Heaven ******************************"<<endl<<endl;
cout<<" Financial Report "<<endl;
cout<<"********************************************************************************"<<endl<<endl;
cout<<"Stock Today Previous Percent"<<endl<<endl;
cout<<"Symbol Open Close High Low Close Gain Volume"<<endl;
cout<<"------ ------ ------ ------ ------- ------- ------- -------"<<endl;
for (k=0; k<list.size(); k++)
{
cout<<list[k]<<endl;
closing_assets =+(list[k].getClosePrice()*list[k].getShares());
}
cout<<endl<<"****************************************";
cout<<endl<<"* Closing Assests: "<<closing_assets<<endl;
cout<<"****************************************"<<endl;
}
void stockListType::printStockGain()
{
int k = 0;
double closing_assets =0;
cout<<"***************** First Investor's Heaven ******************************"<<endl<<endl;
cout<<" Financial Report "<<endl;
cout<<"********************************************************************************"<<endl<<endl;
cout<<"Stock Today Previous Percent"<<endl<<endl;
cout<<"Symbol Open Close High Low Close Gain Volume"<<endl;
cout<<"------ ------ ------ ------ ------- ------- ------- -------"<<endl;
for (k=0; k<list.size(); k++)
{
cout<<list[k]<<endl;
closing_assets = closing_assets + (list[k].getClosePrice()*list[k].getShares());
}
cout<<endl<<"****************************************";
cout<<endl<<"* Closing Assests: "<<closing_assets<<endl;
cout<<"****************************************"<<endl;
}
void stockListType::sortStockSymbols()
{
sort(list.begin(), list.end());
}
void stockListType::sortStockGain()
{
//need help implementing the code
}
|