kievar
2010-04-21 19:38:20 UTC
below is my code, any help would be great.
------------
#include
#include
#include
#include
using namespace std;
typedef string* StrPtr;
typedef double* DoublePtr;
int readData(StrPtr &dates, DoublePtr &prices);
void selectionSort(StrPtr dates, DoublePtr prices, vector
int main()
{
vector
StrPtr dates;
DoublePtr prices;
readData (dates, prices);
selectionSort(dates, prices, numPrices);
}
int readData(StrPtr &dates, DoublePtr &prices)
{
int numRecords = 0;
ofstream inFile;
inFile.open("PriceHistory.txt");
if (inFile.fail())
{
cout << "Error: Failed to open input file." << endl;
exit(1);
}
inFile << numRecords;
dates = new string[numRecords];
prices = new double[numRecords];
inFile << dates;
inFile << prices;
return numRecords;
}
void selectionSort(StrPtr dates, DoublePtr prices, int numPrices)
{
double minValue = 0;
int minIndex = 0;
double tmp = 0;
for (int i = 0; i < numPrices - 1; i++) {
minValue = prices[i];
minIndex = i;
for (int j = i + 1; j < numPrices; j++)
if (prices[j] < minValue) {
minValue = prices[j];
minIndex = j;
} // end if
tmp = prices[i];
prices[i] = prices[minIndex];
prices[minIndex] = tmp;
}
}