Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions fight_management/flightTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Flighttest.cpp
*
*
* Author: Santosh
*/
#include <gtest/gtest.h>
#include <iostream>
#include "flightmanagementsystem.h"
#include "flighttrip.h"

namespace {
class FlightTripTest : public ::testing ::Test {
protected:
void SetUp() override {
FlightTrip t1("IN-125", "Pune", "Mumbai", 150.0, "SpiceJet");
}
void TearDown() override { delete ptr; }
FlightTrip *ptr;
};

class FlightDatabaseTest : public ::testing ::Test {
protected:
void SetUp() override {
FlightTripDatabase t;
t.addTrip("IN-125", "Pune", "Mumbai", 150.0, "SpiceJet");
}
void TearDown() override { delete ptr; }
FlightTrip *ptr;
};

TEST_F(FlightTripTest, DefaultConstructor) {
FlightTrip a;
EXPECT_EQ("XX-XXX", a.getId());
EXPECT_EQ("DUMMY", a.getOrgCity());
EXPECT_EQ(0.0, a.getDistance());
}

TEST_F(FlightTripTest, ParaConstructor) {
FlightTrip a("IN-124", "Pune", "Mumbai", 150.0, "AirLines");
EXPECT_EQ("IN-124", a.getId());
EXPECT_EQ("Pune", a.getOrgCity());
EXPECT_EQ("Mumbai", a.getDesCity());
EXPECT_EQ(150.0, a.getDistance());
EXPECT_EQ("AirLines", a.getFlightOperator());
}

TEST_F(FlightDatabaseTest, AddTrip) {
FlightTripDatabase t1;
t1.addTrip("IN-125", "Pune", "Mumbai", 150.0, "SpiceJet");
EXPECT_EQ("IN-125", t1.findFlightByOriginCity("Pune").getId());
}
TEST_F(FlightDatabaseTest, FindByName) {
FlightTripDatabase t1;
t1.addTrip("IN-125", "Pune", "Mumbai", 150.0, "SpiceJet");
EXPECT_EQ("IN-125", t1.findFlightByNumber("IN-125").getId());
}

TEST_F(FlightDatabaseTest, FindByOperator) {
FlightTripDatabase t1;
t1.addTrip("IN-125", "Pune", "Mumbai", 150.0, "SpiceJet");
EXPECT_EQ("IN-125", t1.findFlightByOperator("SpiceJet").getId());
}

TEST_F(FlightDatabaseTest, FindByOrgCity) {
FlightTripDatabase t1;
t1.addTrip("IN-125", "Pune", "Mumbai", 150.0, "SpiceJet");
EXPECT_EQ("IN-125", t1.findFlightByOriginCity("Pune").getId());
}

TEST_F(FlightDatabaseTest, FindByDesCity) {
FlightTripDatabase t1;
t1.addTrip("IN-125", "Pune", "Mumbai", 150.0, "SpiceJet");
EXPECT_EQ("IN-125", t1.findFlightByDestinationCity("Mumbai").getId());
}

} // namespace
169 changes: 169 additions & 0 deletions fight_management/flightmanagementsystem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
* flightmanagementsystem.cpp
*
*
* Author: Santosh
*/
#include "flightmanagementsystem.h"
#include <algorithm>
#include <iostream>
#include <iterator>
#include <list>
#include <string>
#include "flighttrip.h"

void FlightTripDatabase::addTrip(const FlightTrip& ref) {
trips.push_back(ref);
}

void FlightTripDatabase::addTrip(std ::string t_id, std ::string t_orgCity,
std ::string t_desCity, double t_distance) {
trips.emplace_back(t_id, t_orgCity, t_desCity, t_distance);
}

void FlightTripDatabase::addTrip(std ::string t_id, std ::string t_orgCity,
std ::string t_desCity, double t_distance,
std ::string t_flightOperator) {
trips.emplace_back(t_id, t_orgCity, t_desCity, t_distance, t_flightOperator);
}
void FlightTripDatabase::addTrip(std ::string t_id, std ::string t_orgCity,
std ::string t_desCity, double t_distance,
std ::string t_flightOperator,
double t_taxPercentage) {
trips.emplace_back(t_id, t_orgCity, t_desCity, t_distance, t_flightOperator,
t_taxPercentage);
}

void FlightTripDatabase ::display() {
for (auto itr = trips.begin(); itr != trips.end(); ++itr) {
itr->displayTrip();
}
}
FlightTrip& FlightTripDatabase::findFlightByNumber(std ::string keyId) {
auto itr = std ::find_if(trips.begin(), trips.end(), [keyId](FlightTrip ref) {
return (ref.getId() == keyId);
});
return *itr;
} /*
bool FlightTripDatabase::removeTrip(std ::string keyId) {
auto itr = std ::find_if(trips.begin(), trips.end(), [keyId](FlightTrip ref)
{ return (ref.getId() == keyId);
});
if (itr == trips.end())
return 0;
else {
trips.remove(*itr);
return 0;
}
}*/

FlightTrip& FlightTripDatabase::findFlightByOriginCity(
std ::string keyOrgCity) {
auto itr =
std ::find_if(trips.begin(), trips.end(), [keyOrgCity](FlightTrip ref) {
return (ref.getOrgCity() == keyOrgCity);
});
return *itr;
}
FlightTrip& FlightTripDatabase::findFlightByDestinationCity(
std ::string keyDesCity) {
auto itr =
std ::find_if(trips.begin(), trips.end(), [keyDesCity](FlightTrip ref) {
return (ref.getDesCity() == keyDesCity);
});
return *itr;
}
FlightTrip& FlightTripDatabase::findFlightByOperator(std ::string keyOperator) {
auto itr =
std ::find_if(trips.begin(), trips.end(), [keyOperator](FlightTrip ref) {
return (ref.getFlightOperator() == keyOperator);
});
return *itr;
}
/*
double FlightTripDatabase::findMaxFareByOperator(std ::string Operator) {
auto itr = findFlightByOperator(Operator);
auto fair = max_element( itr.begin(), itr.end(),cmp);

}
*/
/*
FlightTrip& FlightTripDatabase::removeTrip(std :: stri) {
auto itr}

double FlightTripDatabase::findAverageCostOfAllTrips() {}
double FlightTripDatabase::findMinFareBetweenCities() {}
double FlightTripDatabase::findMaxFareByOperator() {}
*/

/*












#include <algorithm>
#include <iostream>
#include <iterator>
#include <list>
#include "bank.h"

void Bank ::addAccount(const Account &ref) { accounts.push_back(ref); }

void Bank ::addAccount(int id, std ::string name, int balance) {
//accounts.push_back(Account(id,name,balance));
accounts.emplace_back(id, name, balance);
}

void Bank ::displayAll() const {
for (auto itr = accounts.begin(); itr != accounts.end(); ++itr) {
itr->display();
}
}
Account &Bank ::findById(int keyId) {
// std ::list<Account>::iterator itr = std ::find_if(
// accounts.begin(), accounts.end(),
//[keyId](const Account &ref) { return (ref.getId() == keyId); });
// return itr;
std ::list<Account>::iterator itr = std ::find_if(
accounts.begin(), accounts.end(),
[keyId](const Account &ref) { return (ref.getId() == keyId); });
//if(itr == accounts.end())
// return ;
return *itr;
}
Account &Bank ::findByName(std ::string keyName) {
std ::list<Account>::iterator itr = std ::find_if(
accounts.begin(), accounts.end(),
[keyName](const Account &ref) { return (ref.getName() == keyName); });
return *itr;
}

bool cmp(const Account &a, const Account &b) { return a.getId() < b.getId(); }

bool cmps(const Account &a, const Account &b) {
return a.getName() < b.getName();
}
void Bank ::sortById() {
// std ::sort(accounts.begin(), accounts.end(), cmp);
accounts.sort(cmp);
}
void Bank ::sortByName() { accounts.sort(cmps); }
bool compareById(const Account &ref1, const Account &ref2) {
return ref1.getId() > ref2.getId();
}


int Bank ::getLowestBalance() { return 0; }

bool Bank ::removeAccount(int keyId) { return false; }


*/
48 changes: 48 additions & 0 deletions fight_management/flightmanagementsystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* flightmanagementsystem.h
*
*
* Author: Santosh
*/

#ifndef FLIGHTMANAGEMENTSYSTEM_H_
#define FLIGHTMANAGEMENTSYSTEM_H_
#include <list>
#include "flighttrip.h"

class FlightTripDatabase {
std ::list<FlightTrip> trips;

public:
void addTrip(const FlightTrip& ref);

void addTrip(std ::string t_id, std ::string t_orgCity,
std ::string t_desCity, double t_distance);

void addTrip(std ::string t_id, std ::string t_orgCity,
std ::string t_desCity, double t_distance,
std ::string t_flightOperator);
void addTrip(std ::string t_id, std ::string t_orgCity,
std ::string t_desCity, double t_distance,
std ::string t_flightOperator, double t_taxPercentage);

void display();
FlightTrip& findFlightByNumber(std ::string keyId);

FlightTrip& findFlightByOriginCity(std ::string keyOrgCity);
FlightTrip& findFlightByDestinationCity(std ::string keyDesCity);
FlightTrip& findFlightByOperator(std ::string keyOperator);
double findMaxFareByOperator(std ::string Operator);
// bool FlightTripDatabase::removeTrip(std ::string keyId);

/*FlightTrip& removeTrip();
FlightTrip& findFlightByNumber();
FlightTrip& findFlightByOriginCity();
FlightTrip& findFlightByDestinationCity();
FlightTrip& findFlightByOperator();
double findAverageCostOfAllTrips();
double findMinFareBetweenCities();
double findMaxFareByOperator();*/
};

#endif /* FLIGHTMANAGEMENTSYSTEM_H_ */
57 changes: 57 additions & 0 deletions fight_management/flighttrip.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* flighttrip.cpp
*
*
* Author: Santosh
*/
/*

*/

#include "flighttrip.h"
#include <iostream>
#include <string>
#include "trip.h"

FlightTrip ::FlightTrip()
: Trip("DUMMY", "DUMMY", 0.00), id("XX-XXX"), flightOperator("DUMMY") {}

FlightTrip ::FlightTrip(std ::string t_id, std ::string t_orgCity,
std ::string t_desCity, double t_distance)
: Trip(t_orgCity, t_desCity, t_distance), id(t_id) {}

FlightTrip ::FlightTrip(std ::string t_id, std ::string t_orgCity,
std ::string t_desCity, double t_distance,
std ::string t_flightOperator)
: Trip(t_orgCity, t_desCity, t_distance),
id(t_id),
flightOperator(t_flightOperator) {}
FlightTrip ::FlightTrip(std ::string t_id, std ::string t_orgCity,
std ::string t_desCity, double t_distance,
std ::string t_flightOperator, double t_taxPercentage)
: Trip(t_orgCity, t_desCity, t_distance),
id(t_id),
flightOperator(t_flightOperator),
taxPercentage(t_taxPercentage) {}

/*FlightTrip ::FlightTrip(const FlightTrip& ref)
: Trip(ref.getOrgCity(), ref.getDesCity(), ref.getDistance()),
id(ref.id),
flightOperator(ref.flightOperator),
taxPercentage(ref.taxPercentage) {}*/
std ::string FlightTrip ::getId() { return id; }

std ::string FlightTrip ::getFlightOperator() { return flightOperator; }
double FlightTrip ::getTax() { return taxPercentage; }
double FlightTrip ::fareCal() {
return ((getDistance() * farePerKm) +
((getDistance() * farePerKm * taxPercentage / 100)));
}

void FlightTrip ::displayTrip() {
std ::cout << "Flight Number : \t" << id << "\nOrigin City : \t"
<< getOrgCity() << "\nDestination City : \t" << getDesCity()
<< "\nDistance : \t" << getDistance() << "\nOperator : \t"
<< getFlightOperator() << "\nTax : \t" << getTax() << " %"
<< "\nFare : \t" << fareCal() << "\n";
}
40 changes: 40 additions & 0 deletions fight_management/flighttrip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* flighttrip.h
*
*
* Author: Santosh
*/

#ifndef FLIGHTTRIP_H_
#define FLIGHTTRIP_H_
#include <iostream>
#include <string>
#include "trip.h"

class FlightTrip : public Trip {
std ::string id;
std ::string flightOperator;
double taxPercentage = 8;
const double farePerKm = 150;

public:
FlightTrip();
FlightTrip(std ::string t_id, std ::string t_orgCity, std ::string t_desCity,
double t_distance);
FlightTrip(std ::string t_id, std ::string t_orgCity, std ::string t_desCity,
double t_distance, std ::string t_flightOperator);
FlightTrip(std ::string t_id, std ::string t_orgCity, std ::string t_desCity,
double t_distance, std ::string t_flightOperator,
double t_taxPercentage);
// FlightTrip(const FlightTrip& ref);

std ::string getId();

std ::string getFlightOperator();
double getTax();
double fareCal();

void displayTrip();
};

#endif /* FLIGHTTRIP_H_ */
Loading