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
|
// Kenneth Clark
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
using namespace std;
class stockType
{
public:
void setStock (char, double, double, double, double, double, double);
void getStock (char&, double&, double&, double&, double&, double&, double&)const;
void printStock() const;
void inputStock (char, double, double, double, double, double, double);
void showPriceDiff();
void calcPercentGain();
void showShares();
stockType(char, double, double, double, double, double, double);
stockType();
private:
char ss;
double op, cp, th, tl, pc, sv;
};
void stockType::setStock (char symbol, double openingPrice, double closingPrice,
double todayHigh, double todayLow, double prevClose, double 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 (0 <= volume && volume < 999999)
sv = volume;
else sv = 0;
}
void stockType::getStock(char& symbol, double& openingPrice, double& closingPrice,
double& todayHigh, double& todayLow, double& prevClose, double& volume) const
{
symbol = ss; openingPrice = op; closingPrice = cp; todayHigh = th;
todayLow = tl; prevClose = pc; volume = sv;
}
void stockType::printStock() const
{
if (ss < 'A') cout << " ";
cout << ss;
if (op < 10) cout << "0";
cout << op;
if (cp < 10) cout << "0";
cout << cp;
if (th < 10) cout << "0";
cout << th;
if (tl < 10) cout << "0";
cout << tl;
if (pc < 10) cout << "0";
cout << pc;
if (sv < 10) cout << "0";
cout << sv;
}
void stockType::inputStock (char symbol, double openingPrice, double closingPrice,
double todayHigh, double todayLow, double prevClose, double volume)
{
ifstream inFile;
inFile.open("Stocks.txt");
inFile >> symbol;
inFile >> openingPrice >> closingPrice >> todayHigh >> todayLow >> prevClose >> volume;
inFile.close();
}
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() //*
{ //*
return (cp - pc) / pc * 100; //*
} // Nichole Knowles**********************************************************************
void stockType::showShares()
{
return sv;
}
stockType::stockType(char symbol, double openingPrice, double closingPrice,
double todayHigh, double todayLow, double prevClose, double 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 (0 <= volume && volume < 999999)
sv = volume;
else sv = 0;
}
stockType::stockType()
{
ss = ' ';
op = 0;
cp = 0;
th = 0;
tl = 0;
pc = 0;
sv = 0;
};
int main()
{
system ("pause");
return 0;
}
|