Question
Hello, I would like some help with fixing my errors in my code, please. The errors I keep getting are these: 1) In file included
Hello, I would like some help with fixing my errors in my code, please.
The errors I keep getting are these:
1) In file included from main.cpp:15:0: stockListType.h:30:4: error: invalid use of template-name 'std::vector' without an argument list vector indexByGain; ^~~~~~
2) In file included from main.cpp:15:0: stockListType.h:31:4: error: invalid use of template-name 'std::vector' without an argument list vector list; ^~~~~~
--------------------------------------------
The text file I use is called 'stockData.txt' and this is the information it contains.
ABC 123.45 130.95 132.00 125.00 120.50 10000 MSET 120.00 140.00 145.00 140.00 115.00 30920 AOLK 80 75 82 74 83 5000 CSCO 100 102 105 98 101 25000 IBD 68 71 72 67 75 15000
----------------------------------------------------
stockType.h
----------------------------------------------------
#ifndef STOCKTYPE_H #define STOCKTYPE_H
#include
using namespace std;
class stockType { friend ostream& operator<<(ostream&, const stockType&); friend ifstream& operator>>(ifstream&, stockType&);
public: void setStockInfo(string symbol, double openPrice, double closeProce, double high, double Low, double prevClose, int shares); string getSymbol(); double getPercentChange(); double getOpenPrice(); double getClosePrice(); double getHighPrice(); double getLowPrice(); double getPrevPrice(); int getnoOfShares();
stockType(); stockType(string symbol, double openPrice, double closeProce, double high, double Low, double prevClose, int shares);
bool operator ==(const stockType& other) const; bool operator !=(const stockType& other) const; bool operator <=(const stockType& other) const; bool operator >=(const stockType& other) const; bool operator >(const stockType& other) const; bool operator <(const stockType& other) const;
private: string stockSymbol; double todayOpenPrice; double todayClosePrice; double todayHigh; double todayLow; double yesterdayClose; double percentChange; int noOfShares; };
#endif /* STOCKTYPE_H */
--------------------------------------------------
stockListType.h
--------------------------------------------------
#ifndef STOCKLISTTYPE_H #define STOCKLISTTYPE_H
#include
using namespace std;
class stockListType { public: void printBySymbol(); void printByGain(); void printReports(); void sortStockList(); void sortByGain(); void insert(const stockType& item); private: vector indexByGain; vector list; };
#endif /* STOCKLISTTYPE_H */
------------------------------------------------------
stockTypeImp.cpp
------------------------------------------------------
#include
using namespace std;
void stockType::setStockInfo(string 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; percentChange = (todayClosePrice - yesterdayClose) / yesterdayClose; noOfShares = shares; }
string stockType::getSymbol() { return stockSymbol; }
double stockType::getPercentChange() { return percentChange; }
double stockType::getOpenPrice() { return todayOpenPrice; }
double stockType::getClosePrice() { return todayClosePrice; }
double stockType::getHighPrice() { return todayHigh; }
double stockType::getLowPrice() { return todayLow; }
double stockType::getPrevPrice() { return yesterdayClose; }
int stockType::getnoOfShares() { return noOfShares; }
stockType::stockType() { stockSymbol = ""; todayOpenPrice = 0; todayClosePrice = 0; todayHigh = 0; todayLow = 0; yesterdayClose = 0; percentChange = 0; noOfShares = 0; } stockType::stockType(string 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; percentChange = (todayClosePrice - yesterdayClose) / yesterdayClose; noOfShares = shares; }
bool stockType::operator ==(const stockType& other) const { return (stockSymbol == other.stockSymbol); }
bool stockType::operator !=(const stockType& other) const { return (stockSymbol != other.stockSymbol); }
bool stockType::operator <=(const stockType& other) const { return (stockSymbol <= other.stockSymbol); }
bool stockType::operator >=(const stockType& other) const { return (stockSymbol >= other.stockSymbol); }
bool stockType::operator >(const stockType& other) const { return (stockSymbol > other.stockSymbol); }
bool stockType::operator <(const stockType& other) const { return (stockSymbol < other.stockSymbol); }
ostream& operator<<(ostream& os, const stockType& stock) { os << setw(6) << stock.stockSymbol << " " << setw(6) << stock.todayOpenPrice << " " << setw(6) << stock.todayClosePrice << " " << setw(6) << stock.todayHigh << " " << setw(6) << stock.todayLow << " " << setw(6) << stock.yesterdayClose << " " << setw(8) << stock.percentChange * 100 << "% " << setw(10) << stock.noOfShares; return os; }
ifstream& operator>>(ifstream& inf, stockType& stock) { inf >> stock.stockSymbol>>stock.todayOpenPrice >> stock.todayClosePrice>>stock.todayHigh >> stock.todayLow>>stock.yesterdayClose >> stock.noOfShares; stock.percentChange = (stock.todayClosePrice - stock.yesterdayClose) / stock.yesterdayClose;
return inf; }
----------------------------------------------------
main.cpp
----------------------------------------------------
#include
using namespace std;
const int noOfStocks = 5;
void getData(stockListType& list);
int main() { stockListType stockList; cout << fixed << showpoint; cout << setprecision(2);
getData(stockList);
stockList.sortStockList(); stockList.printBySymbol(); cout << endl; stockList.printByGain();
return 0; }
void getData(stockListType& list) { ifstream infile; string symbol; double OpenPrice; double ClosePrice; double tHigh; double tLow; double yClose; int shares; stockType temp;
infile.open("stockData.txt");
if (!infile) { cerr << "Input file does not exist. Program terminates." << endl; return; }
infile >> symbol; while (infile) { infile >> OpenPrice >> ClosePrice >> tHigh >> tLow >> yClose >> shares; temp.setStockInfo(symbol,OpenPrice,ClosePrice,tHigh,tLow,yClose,shares); list.insert(temp); infile >> symbol; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started