diff --git a/fight_management/flightTest.cpp b/fight_management/flightTest.cpp new file mode 100644 index 0000000..efa223f --- /dev/null +++ b/fight_management/flightTest.cpp @@ -0,0 +1,77 @@ +/* + * Flighttest.cpp + * + * + * Author: Santosh + */ +#include +#include +#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 diff --git a/fight_management/flightmanagementsystem.cpp b/fight_management/flightmanagementsystem.cpp new file mode 100644 index 0000000..1a31ea8 --- /dev/null +++ b/fight_management/flightmanagementsystem.cpp @@ -0,0 +1,169 @@ +/* + * flightmanagementsystem.cpp + * + * + * Author: Santosh + */ +#include "flightmanagementsystem.h" +#include +#include +#include +#include +#include +#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 +#include +#include +#include +#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::iterator itr = std ::find_if( + // accounts.begin(), accounts.end(), + //[keyId](const Account &ref) { return (ref.getId() == keyId); }); + // return itr; + std ::list::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::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; } + + + */ diff --git a/fight_management/flightmanagementsystem.h b/fight_management/flightmanagementsystem.h new file mode 100644 index 0000000..42d8d88 --- /dev/null +++ b/fight_management/flightmanagementsystem.h @@ -0,0 +1,48 @@ +/* + * flightmanagementsystem.h + * + * + * Author: Santosh + */ + +#ifndef FLIGHTMANAGEMENTSYSTEM_H_ +#define FLIGHTMANAGEMENTSYSTEM_H_ +#include +#include "flighttrip.h" + +class FlightTripDatabase { + std ::list 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_ */ diff --git a/fight_management/flighttrip.cpp b/fight_management/flighttrip.cpp new file mode 100644 index 0000000..936631f --- /dev/null +++ b/fight_management/flighttrip.cpp @@ -0,0 +1,57 @@ +/* + * flighttrip.cpp + * + * + * Author: Santosh + */ +/* + +*/ + +#include "flighttrip.h" +#include +#include +#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"; +} diff --git a/fight_management/flighttrip.h b/fight_management/flighttrip.h new file mode 100644 index 0000000..2b848fe --- /dev/null +++ b/fight_management/flighttrip.h @@ -0,0 +1,40 @@ +/* + * flighttrip.h + * + * + * Author: Santosh + */ + +#ifndef FLIGHTTRIP_H_ +#define FLIGHTTRIP_H_ +#include +#include +#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_ */ diff --git a/fight_management/main.cpp b/fight_management/main.cpp new file mode 100644 index 0000000..01d874b --- /dev/null +++ b/fight_management/main.cpp @@ -0,0 +1,34 @@ +/* + * main.cpp + * + * + * Author: Santosh + */ +#include +#include +#include "flightmanagementsystem.h" +#include "flighttrip.h" +//#include "trip.h" + +int main() { + FlightTrip *ptr; + FlightTrip t1("IN-125", "Pune", "Mumbai", 150.0, "SpiceJet"); + + ptr = &t1; + + // ptr->displayTrip(); + + FlightTripDatabase data; + + data.addTrip(t1); + data.addTrip("IN-456", "Aurangabad", "Mumbai", 250.0, "JetAir"); + + data.display(); + + std :: cout << "\n\n FIND:- "; + + data.findFlightByNumber("IN-125").displayTrip(); + data.findFlightByOriginCity("Aurangabad").displayTrip(); + + return 0; +} diff --git a/fight_management/trip.cpp b/fight_management/trip.cpp new file mode 100644 index 0000000..49f4702 --- /dev/null +++ b/fight_management/trip.cpp @@ -0,0 +1,20 @@ +/* + * trip.cpp + * + * + * Author: Santosh + */ + +#include "trip.h" +#include +#include + +Trip ::Trip() : orgCity("DUMMY"), desCity("DUMMY"), distance(0.00) {} +Trip ::Trip(std ::string t_orgCity, std ::string t_desCity, double t_distance) + : orgCity(t_orgCity), desCity(t_desCity), distance(t_distance) {} +Trip ::Trip(const Trip &ref) + : orgCity(ref.orgCity), desCity(ref.desCity), distance(ref.distance) {} + +std ::string Trip ::getOrgCity() { return orgCity; } +std ::string Trip ::getDesCity() { return desCity; } +double Trip ::getDistance() { return distance; } diff --git a/fight_management/trip.h b/fight_management/trip.h new file mode 100644 index 0000000..dd42cfe --- /dev/null +++ b/fight_management/trip.h @@ -0,0 +1,31 @@ +/* + * trip.h + * + * + * Author: Santosh + */ + +#ifndef TRIP_H_ +#define TRIP_H_ +#include + +class Trip { + std ::string orgCity; // Origin City + std ::string desCity; // Destination City + // double fair; + double distance; // Distance in KMs + + // Fare Per KM + public: + Trip(); + Trip(std ::string t_orgCity, std ::string t_desCity, double t_distance); + Trip(const Trip &ref); + + std ::string getOrgCity(); + std ::string getDesCity(); + double getDistance(); + + virtual double fareCal() = 0; +}; + +#endif /* TRIP_H_ */