Hello MisterTams,
For the most part the program works, but needs a few tweaks.
Starting with the data file I add an extra number after the "#". Could just as easily put that at the end of the line also. More on this later.
In "Stock.h" after the "enum" I added "Sector sctr;" because there was no place to store this number. In "Stock.cpp" you started a setter function for this, but did not finish it. I would guess you did not know where to store it. I added two "Get" functions to retrieve information from the private variables. The use will show up later in main.
"main" is fine although I adjusted this way for testing:
1 2 3 4 5 6 7 8 9
|
std::cout << " " << ReadStkData(StockInfo, MAX_SIZE) << " Items read." << std::endl;
std::cout << std::endl; // Not necessary. Used as a break point for testing
for (size_t lp = 0; lp < MAX_SIZE; lp++)
{
std::cout << std::setw(3) << lp + 1 << " " <<StockInfo[lp].GetCompanyName() << ", "
<< StockInfo[lp].GetSector() << std::endl;
}
|
The for loop could easily be put in a Display function.
I would also suggest changing the array to a "std::vector". It is more useful and you will not have to change "MAX_SIZE" as the data file grows.
In the "ReadStkData" function I added
1 2
|
inFile >> sctr;
stks[x].setSector(sctr);
|
and I changed the for loop to
while (std::getline(inFile, Trade, ' '))
this way when end of file is reached, "inFile" will fail and then the while loop will fail. As coder777 suggested it would be easier to change "elementCounter" to "x". I found this t be the simplest way to fix what you have. Another advantage to this way is that unused elements of the array will be left alone leaving them as they were first initialized.
The program runs as you first posted it, but the for loop in the "ReadStkData" function will fill the array elements 16 - 24 with the same data as element 15. Not what you want.
If anything is unclear let me know.
Hope that helps,
Andy