Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <fstream>
- #include <iomanip>
- using namespace std;
- int isFirstLine = 0;
- string tempSymbol;
- double tempOpen;
- double tempClose;
- double tempHigh;
- double tempLow;
- double tempPrev;
- double tempPerc = 1;
- double tempNum;
- template <class T>
- class stockListType {
- public:
- vector <T> stockList;
- stockListType(T tempStock) {
- stockList.push_back(tempStock);
- }
- stockListType() {}
- void add(T tempStock) {
- this->stockList.push_back(tempStock);
- }
- void printAllStocks() {
- for (T temp : this->stockList) {
- temp.printStock();
- }
- }
- void calForAll() {
- for (int i = 0; i < stockList.size(); i++) {
- stockList[i].calGAL();
- }
- }
- };
- class stockType {
- public:
- string symbol;
- double openPrice;
- double closePrice;
- double highPrice;
- double lowPrice;
- double prevPrice;
- double percentGainOrLoss;
- double numOfShares;
- void setStock(string sym, double open, double close, double high, double low, double prev, double per, double num) {
- this->symbol = sym;
- this->openPrice = open;
- this->closePrice = close;
- this->highPrice = high;
- this->lowPrice = low;
- this->prevPrice = prev;
- this->percentGainOrLoss = 0;
- this->numOfShares = num;
- }
- void printStock() {
- int widthInt = 10;
- cout << setw(widthInt) << left << this->symbol;
- cout << setw(widthInt) << left << this->openPrice;
- cout << setw(widthInt) << left << this->closePrice;
- cout << setw(widthInt) << left << this->highPrice;
- cout << setw(widthInt + 15) << left << this->lowPrice;
- cout << setw(widthInt) << left << this->prevPrice;
- cout << setw(widthInt) << left << this->numOfShares;
- cout << setw(widthInt) << left << this->percentGainOrLoss;
- cout << endl;
- }
- void showDifferentPrices() {
- cout << this->openPrice << " " << this->closePrice << " " << this->highPrice << " " << this->lowPrice << " " << this->prevPrice << endl;
- }
- void calGAL() {
- double percent = (this->closePrice - this->prevPrice) / this->prevPrice * 100;
- this->percentGainOrLoss = percent;
- }
- bool operator=(const stockType& tempStock) {
- bool returnVariable = false;
- if (this->symbol == tempStock.symbol) {
- returnVariable = true;
- }
- else {
- returnVariable = false;
- }
- return returnVariable;
- }
- void operator << (const stockType& tempStock) {
- stockType *stockTypePointer = this;
- *stockTypePointer = tempStock;
- }
- void operator >> (stockType& tempStock) {
- stockType *stockTypePointer = this;
- tempStock = *stockTypePointer;
- }
- };
- void main() {
- ifstream fileInput; //here we are going to define the file that we are trying to stream
- fileInput.open("C:\\temp\\New Text Document.txt");
- stockListType <stockType> newStockList;
- while (!fileInput.eof()) {
- if (isFirstLine < 1) {
- string bufferString;
- fileInput >> tempSymbol >> bufferString >> bufferString >> bufferString >> bufferString >> bufferString >> bufferString;
- isFirstLine++;
- }
- else {
- fileInput >> tempSymbol >> tempOpen >> tempClose >> tempHigh >> tempLow >> tempPrev >> tempNum;
- stockType newStockType;
- newStockType.setStock(tempSymbol, tempOpen, tempClose, tempHigh, tempLow, tempPrev, tempPerc, tempNum);
- newStockList.add(newStockType);
- }
- }
- newStockList.calForAll();
- cout << setw(50) << "Financial Report" << endl;
- vector<string> BufferString;
- BufferString.push_back("SYMBOL");
- BufferString.push_back("OPEN");
- BufferString.push_back("CLOSE");
- BufferString.push_back("HIGH");
- BufferString.push_back("LOW");
- BufferString.push_back("PRE CLOSE");
- BufferString.push_back("SHARES");
- BufferString.push_back("G/L");
- int i = 0;
- for (string c : BufferString) {
- if (i != 4) {
- i++;
- cout << setw(10) << left << c;
- }
- else {
- i++;
- cout << setw(25) << left << c;
- }
- }
- cout << endl;
- newStockList.printAllStocks();
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment