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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
#include <iostream>
#include <fstream>
#include <string>
class FlightNode;
class Date_Time;
class HubNode;
using namespace std;
int main () {
string line,value1,value2,value3,value4, hubName, hubLocation, hline, hvalue1, hvalue2;
int number,i=0;
ifstream flightfile ("flight.csv");
ifstream hubFile ("hub.csv");
class HubNode {
public:
string name;
string location;
HubNode* next;
FlightNode* headFlights;
void print();
string setName(string name) {return name = name;}
string setLocation(string location) {return location = location;}
};
class FlightNode {
public:
string flightNumber;
double price;
string flightCompany;
Date_Time* departure;
int duration;
HubNode* source;
HubNode* destination;
FlightNode *next;
//virtual float getBaggageFees();
//virtual int getDelay();
};
class Date_Time {
public:
int minutes;
int hours;
int day;
int month;
int year;
//Date_Time(); do we need this....
void AddMinutes(int min);
string ToString();
};
FlightNode *head = new FlightNode;
FlightNode *temp = new FlightNode;
FlightNode *nextNode = new FlightNode;
HubNode *hNode = new HubNode;
HubNode *hubHead = new HubNode;
HubNode *hubTemp = new HubNode;
HubNode *hubNextNode = new HubNode;
HubNode *hubPointer = new HubNode;
HubNode *first = new HubNode;
Date_Time *dT = new Date_Time;
temp = head;
cout <<"Flight Data File" << endl;
if (flightfile.is_open())
{
while ( getline (flightfile,line) )// Omit the Caption Line.
{
while(getline(flightfile,value1,','))//Get every value in order.
{
if (temp == head)
{
head->flightNumber = value1;
cout << "FlightNum: " << head->flightNumber << endl;
getline(flightfile, value2,',');
number=atof(value2.c_str());
head->price = atof(value2.c_str());
cout << "Price: " << head->price <<'\n';
getline(flightfile,value3,',');
hNode->name = value3;
head->source = hNode; //hNode is now becoming head->source
number=atoi(value3.c_str());
cout << "Source: " << head->source->name << endl;
getline(flightfile,value4,',');
hNode->name = value4;
head->destination = hNode;
cout << "Destination: " << head->destination->name << endl;
number=atoi(value4.c_str());
getline(flightfile,value1,'/');
number = atoi(value1.c_str());
dT->minutes = number;
cout << "minutes: " << dT->minutes << endl;
getline(flightfile,value1, '/');
number = atoi(value1.c_str());
dT->hours = number;
cout << "hours :" << dT->hours << endl;
getline(flightfile,value1, '/');
number = atoi(value1.c_str());
dT->day = number;
cout << "days :" << dT->day<< endl;
getline(flightfile,value1, '/');
number = atoi(value1.c_str());
dT->month = number;
cout << "months :" << dT->month << endl;
getline(flightfile,value1, ',');
number = atoi(value1.c_str());
dT->year = number;
cout << "years :" << dT->year << endl;
getline(flightfile,value1, ',');
number = atoi(value1.c_str());
head->duration = number;
cout<< "duration :" << head->duration << endl;
getline(flightfile,value1, '\n');
head->flightCompany = value1;
cout<< "Company :" << head->flightCompany<< endl;
cout <<'\n';
head->next = nextNode; //heads next is now nextNode
temp = nextNode; // temp node is now nextNode
}
temp->flightNumber = value1;
cout << "FlightNum: " << temp->flightNumber << endl;
getline(flightfile, value2,',');
number=atof(value2.c_str());
temp->price = atof(value2.c_str());
cout << "Price: " << temp->price <<'\n';
getline(flightfile,value3,',');
hNode->name = value3;
temp->source = hNode; //hNode is now becoming temp->source
number=atoi(value3.c_str());
cout << "Source: " << temp->source->name << endl;
getline(flightfile,value4,',');
hNode->name = value4;
temp->destination = hNode;
cout << "Destination: " << temp->destination->name << endl;
number=atoi(value4.c_str());
getline(flightfile,value1,'/');
number = atoi(value1.c_str());
dT->minutes = number;
cout << "minutes: " << dT->minutes << endl;
getline(flightfile,value1, '/');
number = atoi(value1.c_str());
dT->hours = number;
cout << "hours :" << dT->hours << endl;
getline(flightfile,value1, '/');
number = atoi(value1.c_str());
dT->day = number;
cout << "days :" << dT->day<< endl;
getline(flightfile,value1, '/');
number = atoi(value1.c_str());
dT->month = number;
cout << "months :" << dT->month << endl;
getline(flightfile,value1, ',');
number = atoi(value1.c_str());
dT->year = number;
cout << "years :" << dT->year << endl;
getline(flightfile,value1, ',');
number = atoi(value1.c_str());
temp->duration = number;
cout<< "duration :" << temp->duration << endl;
getline(flightfile,value1, '\n');
temp->flightCompany = value1;
cout<< "Company :" << temp->flightCompany<< endl;
cout <<'\n';
temp->next = nextNode; //current becomes temp next node
temp = nextNode; //temp becomes current node
}
}
flightfile.close();
}
else { cout << "Unable to open file"; }
//hub data file
if (hubFile.is_open())
{
while ( getline(hubFile,line) )// Omit the Caption Line.
{
while(getline(hubFile,value1,','))//Get every value in order.
{
hubHead->name = value1;
cout<<"Airport Name :"<< hubHead->name <<endl;
getline(hubFile, value2, '\n');
hubHead->location = value2;
cout<<"Airport Location :" << hubHead->location << endl;
cout <<"\n" << endl;
}
}
hubFile.close();
}
else { cout << "Unable to open file"; }
getchar();
delete head;
delete temp;
delete hNode;
delete hubHead;
return 0;
}
|