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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <sstream>
#include <stdlib.h>
#include <list>
using namespace std;
class FileInfo
{
public:
int submissiontime;
float length;
int finishtime;
int remainingtime;
int actualfinishtime;
int delay;
};
// create list
list<FileInfo*>futurelist;
//read from excel file
void FileInput()
{
ifstream file ("DownloadList_test.csv"); // declare file stream
string value1;
string value2;
string value3;
string value4;
string value5;
string value6;
string value7;
string value8;
string value9;
for (int t=0;t<5;t++) //read five items only
{
if (file.good())
{
getline(file,value1, ','); // read a string until next comma
getline(file,value2, ',');
getline(file,value3, ',');
getline(file,value4, ',');
getline(file,value5, ',');
getline(file,value6, ',');
getline(file,value7, ',');
getline(file,value8, ',');
getline(file,value9);
//push values in memory & in future list
FileInfo* fi = new FileInfo();
fi->submissiontime = atoi(value1.c_str());
fi->length= atof(value3.c_str());
fi->finishtime= atoi(value5.c_str());
fi->remainingtime= atoi(value7.c_str());
fi->actualfinishtime= atoi(value8.c_str());
fi->delay= atoi(value9.c_str());
futurelist.push_back(fi);
}
}
file.close();
}
int main()
{
FileInput(); //read csv file
// display contents of future list
cout << "Contents of finished list: ";
list<FileInfo*>::iterator p = futurelist.begin();
while(p != futurelist.end()) {
cout<<endl;
cout << (*p)->submissiontime << " ";
cout << (*p)->length << " ";
cout << (*p)->finishtime << " ";
cout << (*p)->remainingtime << " ";
cout <<(*p)->actualfinishtime<< " ";
cout <<(*p)->delay<< " ";
cout<<endl;
p++;
}
cout << "\n\n";
//--------------------------sorting list--------
int temp, i, j, n;
n=futurelist.size();
for(n-1; (n>=1); n--){
for (int index=0;index<n; index++){
if(futurelist[index]>futurelist[index+1]) {
swap(futurelist[index], futurelist[index+1] );
}
}
}
return 0;
}
|