I have a project for school. Need to read file and sort it by destinatiion, departure (24 hour format) , flightNo and gateNo. I tried to sort but it didn't work.. I am new in programming,and if anyone can help me, I'll appreciate.
// Name : Flight.h
#pragma once
#include <iostream>
#include <string>
#include <vector>
using std::string;
class Flight
{
private:
string flightNo;
string destination;
string departure;
string gateNo;
public:
Flight(void);
~Flight(void);
void readingFile();
void writingFile();
};
// Flight.cpp
#include "Flight.h"
#include <fstream>
#include <cstring>
using namespace std;
Flight::Flight(void)
{
}
Flight :: ~Flight(void)
{
}
void Flight :: readingFile()
{
string FileName;
string line;
cout << "Enter a file name: " << endl;
cin >> FileName;
ifstream inFile(FileName.c_str());
if (inFile.is_open())
{
while (getline( inFile, line))
{
cout << line <<endl;
}
inFile.close();
}else
cout << "File is not open!" <<endl;
}
//Sort.h
#pragma once
#include "Flight.h"
#include <vector>
// Sort class
class Sort
{
protected:
// number of comparisons performed in sort function
unsigned long num_cmps;
public:
// main entry point
//virtual void sort(vector<Flight>& data) = 0;
void sortflights();
// returns number of comparisons
unsigned long getNumCmps();
// resets the number of comparisons
void resetNumCmps();
};
// SelectionSort class
class SelectionSort : public Sort
{
public:
// main entry point
void sort(std::vector<Flight>& data);
};
class MergeSort : public Sort
{
// main entry point
void sort(std::vector<Flight>& data);
};
//Sort.cpp
#include "Sort.h"
#include <iostream>
using namespace std;
unsigned long Sort::getNumCmps()
{
return num_cmps;
}
void Sort::resetNumCmps()
{
num_cmps = 0;
}
void Sort :: sortflights()
{
int choose;
cout<<"Choose an option!"<<endl;
cout<<"PRESS 1 FOR SORT BY DESTINATION"<<endl;
cout<<"PRESS 2 FOR SORT BY DEPARTURE"<<endl;
cout<<"PRESS 3 FOR SORT BY FLIGHT NUMBER"<<endl;
cout<<"PRESS 3 FOR SORT BY GATE NUMBER"<<endl;
cin>>choose;
if(choose==1)
{
vector<string> destination;
for(int i=0; i<destination.size(); i++)
{
string elem1=destination[i];
string elem2=destination[i+1];
if (strcmp(elem1.c_str(),elem2.c_str())>0)
{
cout << elem1<<endl ;
}
else
cout << elem2<<endl ;
cout << "Number of iteration = " << i << endl;
}
}
else if(choose==2)
{
vector<string> departure;
for(int i=0; i<departure.size(); i++)
{}