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 222 223 224
|
// Kenneth Clark
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <string>
using namespace std;
class stockType
{
public:
void setStock (string, double, double, double, double, double, double, char, int);
void getStock (string&, double&, double&, double&, double&, double&, double&, char&, int&)const;
void printStock() const;//works
void showPriceDiff();//works
void calcPercentGain();//working
void showShares(); //working
friend istream& operator >> (istream &in, stockType &cStock);// Dawn Brownell-Adie ****
friend ostream& operator << (ostream &out, stockType &cStock);// Dawn Brownell-Adie ****
void getTotalAssets();// working ****// Dawn Brownell-Adie ****
stockType(string, double, double, double, double, double, double, char, int);
stockType();//works
string ss;
double op, cp, th, tl, pc, pg;
char pp;
int sv;
double total_assets;// Dawn Brownell-Adie ****
};
void stockType::setStock (string symbol, double openingPrice, double closingPrice,
double todayHigh, double todayLow, double prevClose, double percentGain, char percent, int volume)
{//*Daniel De Gasperis***************************************************************
//*
if ("A" <= symbol && symbol < "z")
ss = symbol;
else ss = ' ';
if (0 <= openingPrice && openingPrice < 9999)
op = openingPrice;
else op = 0;
if (0 <= closingPrice && closingPrice < 9999)
cp = closingPrice;
else cp = 0;
if (0 <= todayHigh && todayHigh < 9999)
th = todayHigh;
else th = 0;
if (0 <= todayLow && todayLow < 9999)
tl = todayLow;
else tl = 0;
if (0 <= prevClose && prevClose < 9999)
pc = prevClose;
else pc = 0;
if (-999999 <= percentGain && percentGain < 9999)
pg = percentGain;
else pg = 0;
if (pp == '%')
pp = percent;
else pp = 0;
if (0 <= volume && volume < 999999)
sv = volume;
else sv = 0; //*
//*
}//*Daniel De Gasperis***************************************************************
void stockType::getStock(string& symbol, double& openingPrice, double& closingPrice,
double& todayHigh, double& todayLow, double& prevClose, double& percentGain, char& percent, int& volume) const
{
symbol = ss; openingPrice = op; closingPrice = cp; todayHigh = th;
todayLow = tl; prevClose = pc; percentGain = pg; percent = pp; volume = sv;
}
void stockType::printStock() const
{
cout << ss << " " << op << " " << cp << " " << th << " " << tl << " " << pc << " "
<< pg << pp << " " << sv << " ";
}
void stockType::showPriceDiff()// Nichole Knowles*****************************************
{ //*
cout << "Today's opening price was " << op << ", and the closing was " << cp << endl; //*
cout << "Today's high price was " << th << ", and the low price was " << tl << endl; //*
cout << "While the previous closing price was " << pc << endl; //*
} //*
void stockType::calcPercentGain() //*
{ //*
cout << (cp-pc)/pc*100; //*
} // Nichole Knowles**********************************************************************
void stockType::showShares()
{
cout << sv;
}
istream& operator >> (istream& in, stockType& cStock)// Dawn Brownell-Adie ******
{
// Since operator>> is a friend of the stockType class, we can access StockType members directly.
in >> cStock.ss;
in >> cStock.op;
in >> cStock.cp;
in >> cStock.th;
in >> cStock.tl;
in >> cStock.pc;
in >> cStock.pg;
in >> cStock.pp;
in >> cStock.sv;
// cout << cStock.total_assets << endl;
cStock.total_assets += cStock.sv*cStock.pc;
return in;// Dawn Brownell-Adie ******************************************
}
ostream& operator<< (ostream& out, stockType& cStock)// Dawn Brownell-Adie ******
{
cStock.calcPercentGain();
// operator<< is a friend of the StockType class, we can access StockTypes members directly.
out << setw(8) << left << cStock.ss << right << fixed << setprecision(2) << setw(8) <<
cStock.op << fixed << setprecision(2) << setw(8) <<
cStock.cp << fixed << setprecision(2) << setw(8) <<
cStock.th << fixed << setprecision(2) << setw(8) <<
cStock.tl << fixed << setprecision(2) << setw(8) <<
cStock.pc << fixed << setprecision(2) << setw(8) <<
cStock.pg << fixed << setprecision(2) << setw(2) <<
cStock.pp << fixed << setprecision(2) << setw(12) <<
cStock.sv << fixed << setprecision(2) <<endl;
return out;// Dawn Brownell-Adie ****
}
void stockType::getTotalAssets()// Dawn Brownell-Adie ****
{
cout << cp * sv;// Dawn Brownell-Adie ****
}
stockType::stockType(string symbol, double openingPrice, double closingPrice,
double todayHigh, double todayLow, double prevClose, double percentGain, char percent, int volume)
{
if ("A" <= symbol && symbol < "z")
ss = symbol;
else ss = ' ';
if (0 <= openingPrice && openingPrice < 9999)
op = openingPrice;
else op = 0;
if (0 <= closingPrice && closingPrice < 9999)
cp = closingPrice;
else cp = 0;
if (0 <= todayHigh && todayHigh < 9999)
th = todayHigh;
else th = 0;
if (0 <= todayLow && todayLow < 9999)
tl = todayLow;
else tl = 0;
if (0 <= prevClose && prevClose < 9999)
pc = prevClose;
else pc = 0;
if (-999999 <= percentGain && percentGain < 9999)
pg = percentGain;
else pg = 0;
if (pp == '%')
pp = percent;
else pp = 0;
if (0 <= volume && volume < 999999)
sv = volume;
else sv = 0;
}
stockType::stockType()
{
ss = 'A';
op = 0;
cp = 0;
th = 0;
tl = 0;
pc = 0;
pg = 0;
pp = 0;
sv = 0;
};
int main()
{
string ss;
double op, cp, th, tl, pc, pg;
char pp;
int sv;
stockType stock;
ifstream in("Stocks.txt");
while (in >> stock)
cout << stock << "\n";
stock.printStock();
cout << endl << "\n";
system ("pause");
return 0;
}
|