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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <vector>
using namespace std;
class DATE
{
public:
string Date;
int DateValue()
{
int m, d, y; string temp;
//Breakdown the date string into day, month, and year
temp = Date.substr(0,2);
m = atoi(temp.c_str());
temp = Date.substr(3,2);
d = atoi(temp.c_str());
temp = Date.substr(6,4);
y = atoi(temp.c_str());
return ((y*10000) + (m*100) + d);
}
};
int Load_Price_Data(string file_name, string sort_method, string sort_preference, string* Date, double* Price)
{
ifstream File(file_name);
if(!File)
{
cout << "ERROR" << endl;
system("pause");
return -1;
}
string temp;
vector<string> DATA;
while(!File.eof())
{
File >> temp;
DATA.push_back(temp);
}
int size = DATA.size();
//Splitting DATA into Date and Price vectors
string* DD = new string[size]; double* PP = new double[size];
for(int i = 0; i < size; i++)
{
DD[i] = DATA[i].substr(0,10);
temp = DATA[i].substr(11);
PP[i] = atof(temp.c_str());
}
//Sort
if(sort_method == "QuickSort")
{
}
else
{
int swap = 1;
string date; double price; DATE A, B;
if(sort_preference == "ascending")
{
while(swap != 0)
{
swap = 0;
for(int k = 0; k < size; k++)
{
A.Date = DD[k]; B.Date = DD[k+1];
if(A.DateValue() > B.DateValue())
{
date = DD[k]; price = PP[k];
DD[k] = DD[k+1]; PP[k] = PP[k+1];
DD[k+1] = date; PP[k+1] = price;
swap++;
}
}
}
}
else
{
}
}
Date = new string[size]; Price = new double[size];
for(int h = 0; h < size; h++)
{
Date[h] = DD[h]; Price[h] = PP[h];
}
return size;
}
|