I'm trying to finish an assignment. which is a program that reads sales data from a text file, sorts the data and outputs the sorted data to a second file. The input file is a comma-seperated value file (CSV), with the first item being the number of sales data items to be processed, followed by the list of sales data on one line (items are seperated by commas). Each sales data item is decimal number. but I have to do this in 4 functions including the main() and that's where I'm having the most issues
Sample Input:
5,453.67,8769.57,221.87,600.28,8123.00
I'm confused on how reading in a file works and out put the data sorted.
int main() {
string filename, newFilename;
ifstream infile("salesData.csv");
//cout << "What file do you want to open? " << endl;
//cin >> filename;
int size = 0;
getSalesData(size, filename);
selectionSortArray(filename, size);
ofstream outputFile;
writeTofile(outputFile, filename);
system("pause");
return 0;
}
double * getSalesData(int &size, string &filename)
{
ifstream inputfile;
inputfile.open(filename);
double * salesData = new double[size];
inputfile.close();
return salesData;
}
//******************************************************************
// selectionSortArray
// task: to sort values of an array in ascending order // data in: the array, the array size // data out: the sorted array
//******************************************************************
void selectionSortArray(string &filename, int length){}
// copy data to output file
void writeTofile(ofstream &outputFile, string x)
{
outputFile.open(x.c_str());
outputFile.close();
}
I expect to see the sample input 5,453.67,8769.57,221.87,600.28,8123.00 to be sorted