Airport data base program

------------------------------------------------------------------------------

#ifndef AIRPORT_H
#define AIRPORT_H

#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<fstream>

using namespace std;

class Airport {
private:
int id;
string icaoCode;
string type;
string name;
double latitude;
double longitude;
string isoCountry;
string municipality;

public:
//default constructor
Airport(){
int id=0;
string icaoCode="";
string type="";
string name="";
double latitude=0;
double longitude=0;
string isoCountry="";
string municipality="";
//parametrized constructor
Airport(int x,
string icc,
string typ,
string nm,
double alt,
double lon,
string isc,
string mnc)
{id=x;
icaocode=icc;
type=typ;
name=nm;
altitude=alt;
longitude=lon;
isoCountry=isc;
municipality=mnc;}
//setters & getters

voidsetId(int i)
{id=i;}

void setIcaoCode(string icc)
{icaoCode=icc;}

void setType(string typ)
{type=typ;}

void setName(string nm)
{name=nm;}

void setAltitude(double alt)
{altitude=alt;}

void setLongitude(double lon)
{longitude=lon;}

void setIsoCountry(string isc)
{isoCountry=isc;}

void setMunicipality(string mnc)
{municipality=mnc;}

int getId()
{return id;}

string getIcaoCode()
{return icaoCode;}

string getName()
{return name;}

string getType()
{return type;}

double getAltitude()
{return altitude;}

double getLongitude()
{return longitude;}

string getIsoCountry()
{return isoCountry;}

string getMunicipality()
{return municipality;}

//functions
void read(ifstream&infile)
{
infile>>id;
infile.ignore();
getline(infile,icaoCode,',');
getline(infile,type,',');
getline(infile,name,',');
infile>>altitude;
infile.ignore();
infile>>longitude;
infile.ignore();
getline(infile,isoCountry,',');
getline(infile,municipality);
}

void print()
{
cout<<right<<setw(8)<<id<<" ";
cout<<left<<setw(8)<<icaoCode<<" ";
cout<<left<<setw(45)<<name<<" ";
cout<<right<<setw(10)<<latitude<<" ";
cout<<right<<setw(10)<<longitude<<" ";
cout<<left<<setw(10)<<isoCountry<<" ";
cout<<left<<municipality<<"\n";
}

double distanceTo(Airport theOther)
{

const double pi = 3.14159265
double dlon=(longitude-theOther.getLongitude())*(pi/180);
double dlat =(altitude-theOther.getAltitude())*(pi/180);

double a = pow( sin(dlat/2) ,2) + cos(theOther.latitude) * cos(latitude) * pow( sin(dlon/2) , 2) ;

double c = 2 * atan2(sqrt(a), sqrt(1 - a));
double d = 6373.0 * c;
return d;

}



};
class Country {
private:
int id;
string code;
string name;
string continent;
vector<Airport> airports;
public:
Country(){
id=0;
code="";
name="";
continent="";
};
// idOc = id of country, codc= code of country, nmc = name of country
//, cnt= continent
Country(intidOc, string codc,stringnmc,stringcnt){
id=idOc;
code=codc;
name=nmc;
continent=cnt;
};

//setters & getters
int getId();
string getCode();
string getName();
string getContinent();
vector<Airport>getAirports();

void setId(int id2)
{id=id2};
void setCode(string c2)
{code=c2};
void setName(string n2)
{name=n2};
void setContinent(string con2)
{continent=con2};




};

#endif


Main.cpp:


#include <sstream>
#include "Airport.h"

void printMenu();
//int getSelection();
vector<string> line2strings(string line);
void readCountry(string fileName, vector<Country> & countries);
void readAirport(string fileName, vector<Country> & countries, vector<Airport> & airports);
int main()

{

int selection;
bool header;
bool notFound;
int counter=0;
int input;
vector<Country> countries;
vector<Airport> airports;

cout<<"Data loading, please wait for a while ......\n";

readCountry("countries.csv", countries);
readAirport("airports.csv",countries,airports);


cin>>selection;



switch (selection)
{

case 1:
{

cout<<"Enters the icaoCode : ";
cin>>input;
for (int i=0;i<airports.size();i++)
{
if(airports[i].getIcaoCode()==input)
cout<<"longitude is "<<airports[i].getLongitude()<<endl<<"Laltitude is "<<airports[i].getAltitude()<<endl;
}
}
break;

case 2:
{

int num=0;
cout<<"Enters the isoCode for the country : ";
cin>>input;
for(int i=0;i<airportSize;i++){
if(airports[i].getIsoCountry()==input)
num++;
}
cout<<"there are :"<<num<<" Airports in this ISOCODE" <<endl;

}
break;

case 3:
{

cout<<"Enters the isoCode for the country : ";
cin>>input;
for (int i=0;i<airportSize;i++)
{
if(airports[i].getIsoCountry()==input)
cout<<airports[i].getName()<<endl;
}
}
break;
case 4:
{

cout<<"Enter the name of a continent"<<endl;
cin>>input;
cout<<"The airports are :"<<endl;
for(int i=0;i<countrySize;i++)
{
if(countries[i].getContinent()==input)
cout<<countries[i].getName()<<endl;
}
}

break;
case 5:
cout<<"Enters the isoCode for the country : ";
cin>>input;
notFound = true;
counter = 0;
for ( int i = 0; i < countries.size(); i++) {
if(airports[i].getIsoCountry()==input && airport[i].getType()=="large_airport")
cout<<airports[i].getName()<<endl;

if (counter < 1) {
cout<<"There is no large airport in this country\n";
}


break;
}

case 6:
{


cout<<" enter the icaoCode"<<endl;
cin>>input;
for(int i=0;i<airports.size();i++){
if(airports[i].getIcaoCode()==input)
cout<<"Distance from doha international airport is = "<<doha.distanceTo(airports[i])<<endl;
}
}
break;

case 7:
{

cout<<"enter the isoCode"<<endl;
cin>>input;
for(int i=0;i<airportSize;i++)
{
if(airports[i].getIsoCountry()==iso)
cout<<"Distance between Doha Airport and "<<airports[i].getName()<<endl<<"is "<<airports[31525].distanceTo(airports[i])<<endl;
}
}
break;
case 8:
{
cout<<"Enters the name of the municipality : ";

cin.getline(municipality,60,'\n');

cin.getline(municipality,60,'\n');


for (int i = 0; i < airports.size(); i++) {

if(airports[i].getMunicipality()==0)
cout<<airports[i].getName()<<endl;
}

}
break;

case 9:
{
cout<<"Exiting."<<endl;
exit(0);
}
}
return 0;
}

void printMenu()
{
cout<<"1. Display the latitude and longitude of a given airport.\n"
"2. Display the number of airports in a given country.\n"
"3. Display all the airports in in a given country\n"
"4. Display all the airports in a given continent.\n"
"5. Display all the large_airports in a given country\n"
"6. Display the distance between Doha International Airport and an airport whose icaoCode is entered by the user.\n"
"7. Display the distances between Doha International Airport and all airports of a given country.\n"
"8. Display all the airports in a given municipality\n"
"9. Exit the application\n";
}



//This still need to be worked on
void readAirport (string fileName, vector<Country> & countries, vector<Airport> & airports) {
ifstream in ;
in.open(fileName.c_str(),ios::in);
string line;
vector<string> strings;
if (in.is_open()) {
getline(in,line);
while (getline(in,line) ) {

strings = line2strings(line);
if (strings.size() == 8) {
Airport airport(
atoi(strings.at(0).c_str()),
strings.at(1).c_str(),
strings.at(2).c_str(),
strings.at(3).c_str(),
atof(strings.at(4).c_str()),
atof(strings.at(5).c_str()),
strings.at(6).c_str(),
strings.at(7).c_str()
);
airports.push_back(airport);
for (unsigned int i = 0; i < countries.size(); i++) {
if (string s.at(6) == countries.at(i).getCode()) {
countries.at(i).addAirport(airport);
break;
}
}
}
}

}
}

void readCountry(string fileName, vector<Country> & countries){
ifstream in ;
in.open("countries.csv");
string line;
vector<string> strings;
if (in.is_open()) {
getline(in,line);
while (getline(in,line) ) {

strings = line2strings(line);
// if (strings.size() == 4) {
// Country country( atoi(strings.at(0).c_str()), strings.at(1).c_str(),strings.at(2).c_str(),strings.at(3).c_str() );
// countries.push_back(country);
}
}

}
}


I am a new comer in C++
my code is long , i know, but please help as i got my head pinned down on this for too long and i cant think anymore.
So....What do you need help with? You just posted your code and never asked a question.

Also, if you could please edit your first post and put code tags around it. You can edit and press the <> button after selecting your code or type [code] before and [ /code] (without space) after.
And please don't forget indentation.
Topic archived. No new replies allowed.