Cannot figure out the errors withing my program. Can anyone offer any advice.
Here are the errors:
midtermec.cpp:40: error: ‘stock’ has not been declared
midtermec.cpp:46: error: variable or field ‘addstock’ declared void
midtermec.cpp:46: error: ‘stock’ was not declared in this scope
midtermec.cpp: In member function ‘double Xchange::getPrice(std::string)’:
midtermec.cpp:53: error: expected unqualified-id before ‘=’ token
midtermec.cpp:53: error: ‘i’ was not declared in this scope
midtermec.cpp: In function ‘int main()’:
midtermec.cpp:66: error: ‘Xchange nsadaq’ redeclared as different kind of symbol
midtermec.cpp:65: error: previous declaration of ‘Xchange nsadaq()’
midtermec.cpp:67: error: request for member ‘addstock’ in ‘nsadaq’, which is of non-class type ‘Xchange()’
midtermec.cpp:67: error: ‘stock’ was not declared in this scope
midtermec.cpp:68: error: request for member ‘getPrice’ in ‘nsadaq’, which is of non-class type ‘Xchange()’
Here is the code
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
|
/* Program: MidtermEC.cpp */
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Stock
{
public:
Stock(string s, double p);
string getSymbol();
double getPrice();
void changePrice( double newPrice);
private:
string symbol;
double price;
};
Stock::Stock(string s, double p)
{
symbol= s;
price= p;
}
string Stock::getSymbol()
{
return symbol;
}
void Stock::changePrice (double newPrice)
{
price = newPrice;
}
class Xchange: public Stock
{
public:
Xchange();
void addStock (stock newStock);
double getPrice (string symbol);
private:
vector <Stock> stocks;
};
void Xchange::addstock (stock newStock)
{
stocks.push_back(newStock);
}
double Xchange::getPrice (string symbol)
{
for(int=0; i<stocks.size; i++)
{
if (stocks[i].getSymbol== symbol)
{
return stocks[i].getPrice();
}
}
return -1;
}
int main()
{
Xchange nsadaq();
Xchange nsadaq = Xchange();
nsadaq.addstock (stock("GOOG", 1000));
cout << nsadaq.getPrice ("GOOG");
}
|