Website Summary Files Commits Branches @commit @diff @stats
path: root / Big4_and_composition
diff options
context:
space:
mode:
Commit0218c678e13e1cb94a352c91733cea68467dc566 (patch)
Author
 Angeld55 <angel_dimitriev@abv.bg>
2021-02-14 23:06:35 +0200
Committer
 Angeld55 <angel_dimitriev@abv.bg>
2021-02-14 23:06:35 +0200
Files16fb3114cb560242458d10411765e50f5d6183db /Big4_and_composition
Object-oriented_programming_FMI-0218c678e13e1cb94a352c91733cea68467dc566.tar
Object-oriented_programming_FMI-0218c678e13e1cb94a352c91733cea68467dc566.tar.gz
Object-oriented_programming_FMI-0218c678e13e1cb94a352c91733cea68467dc566.zip
Parentd4ae0ef9ec1b54420176c4a88e09f2fd44ae31b0 (diff)
start from scratch
diff --git a/Big4_and_composition/Airlines_booking_system/Airline.cpp b/Big4_and_composition/Airlines_booking_system/Airline.cpp
deleted file mode 100644
index f5dd3e3..0000000
--- a/Big4_and_composition/Airlines_booking_system/Airline.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-#include "Airline.h"
-
-int Airline::firstFreeIndex()
-{
- for (int i = 0; i < MAXFLIGHTS; i++)
- {
- if (fl[i] == nullptr)
- return i;
- }
- return -1;
-}
-void Airline::CopyFrom(const Airline& other)
-{
- name = new char[strlen(other.name) + 1]; //Копираме именето
- strcpy(name, other.name);
-
- for (int i = 0; i < MAXFLIGHTS; i++)
- {
- if (other.fl[i] == nullptr)
- fl[i] = nullptr;
- else
- {
- fl[i] = new Flight(*other.fl[i]); //извикваме копи контруктора на обектите.
- } // Понеже в other.fl[i] e указател, то трябва да го 'дерефрираме'.
- }
-}
-void Airline::Free() //трябва да изтрием името и всички обекти, към които сочат указателите
-{
- delete[] name;
- for (int i = 0; i < MAXFLIGHTS; i++)
- delete fl[i]; //някои указатели може да имат стойност nullptr, но това няма да доведе до грешка.
-}
-
-
-Airline::Airline(const char* name)
-{
- this->name = new char[strlen(name) + 1];
- strcpy(this->name, name);
-
- for (int i = 0; i < MAXFLIGHTS; i++)
- fl[i] = nullptr;
-}
-
-bool Airline::addFlight(const char* originAirportName, const char* originAirportId,
- const char* destAirportName, const char* destAirportId, int durration)
-{
- int ind = firstFreeIndex();
-
- if (ind == -1) //няма свободни места.
- return false;
-
- fl[ind] = new Flight(originAirportName, originAirportId, destAirportName, destAirportId, durration);
- return true;
-
-}
-bool Airline::addFlight(const Flight& other)
-{
- int ind = firstFreeIndex();
-
- if (ind == -1)//няма свободни места.
- return false;
- fl[ind] = new Flight(other);
- return true;
-}
-Airline::Airline(const Airline& other)
-{
- CopyFrom(other);
-}
-Airline& Airline::operator=(const Airline& other)
-{
- if (this != &other)
- {
- Free();
- CopyFrom(other);
- }
- return *this;
-}
-Airline::~Airline()
-{
- Free();
-}
-bool Airline::containsJourney(const char* originID, const char* destID)
-{
- //TODO -> fix cycles
- if (strcmp(originID, destID))
- return true;
-
- bool solution = false;
-
- for (int i = 0; i < MAXFLIGHTS && !solution; i++)
- {
- if (fl[i] != nullptr)
- {
- if (strcmp(fl[i]->getOrigin().getId(), originID) == 0)
- solution = solution || containsJourney(fl[i]->getDestination().getId(), destID);
- }
- }
- return false;
-}
-void Airline::print()
-{
- for (int i = 0; i < MAXFLIGHTS; i++)
- {
- if (fl[i])
- {
- std::cout << "Flight: ";
- fl[i]->print();
- }
- }
-}
diff --git a/Big4_and_composition/Airlines_booking_system/Airline.h b/Big4_and_composition/Airlines_booking_system/Airline.h
deleted file mode 100644
index 0a8f34c..0000000
--- a/Big4_and_composition/Airlines_booking_system/Airline.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "Flight.h"
-
-const int MAXFLIGHTS = 10;
-
-class Airline
-{
- char* name;
- Flight* fl[MAXFLIGHTS]; //масив от указатели към обекти от тип Flight.
-
- int firstFreeIndex();
-
- void CopyFrom(const Airline& other);
- void Free();
-
-public:
- Airline(const char* name);
- Airline(const Airline& other);
- Airline& operator=(const Airline& other);
- ~Airline();
-
- bool addFlight(const char* originAirportName, const char* originAirportId,
- const char* destAirportName, const char* destAirportId, int durration);
- bool addFlight(const Flight& other);
-
- bool containsJourney(const char* origin, const char* dest);
-
- void print();
-};
diff --git a/Big4_and_composition/Airlines_booking_system/Airport.cpp b/Big4_and_composition/Airlines_booking_system/Airport.cpp
deleted file mode 100644
index d9f0c25..0000000
--- a/Big4_and_composition/Airlines_booking_system/Airport.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-#include "Airport.h"
-
-Airport::Airport(const char* cityName,const char* id)
-{
- this->cityName = new char[strlen(cityName) + 1];
- strcpy(this->cityName, cityName);
-
- strcpy(this->id, id);
-}
-
-void Airport::CopyFrom(const Airport& other)
-{
- cityName = new char[strlen(other.cityName) + 1];
- strcpy(cityName, other.cityName);
-
- strcpy(id, other.id); //въпреки че не е динамично заделен, се налага до разпишем ръчно копирането, защото го разписваме за другите член-данни в класа.
-}
-
-void Airport::Free()
-{
- delete[] cityName;
-}
-
-Airport::Airport(const Airport& other)
-{
- CopyFrom(other);
-}
-
-Airport& Airport::operator=(const Airport& other)
-{
- if (this != &other)
- {
- Free();
- CopyFrom(other);
- }
- return *this;
-
-}
-
-Airport::~Airport()
-{
- Free();
-}
-
-const char* Airport::getId() const
-{
- return id;
-}
-const char* Airport::getCityName() const
-{
- return cityName;
-}
-void Airport::print() const
-{
- std::cout << cityName << '(' << id << ')';
-}
diff --git a/Big4_and_composition/Airlines_booking_system/Airport.h b/Big4_and_composition/Airlines_booking_system/Airport.h
deleted file mode 100644
index 98b3547..0000000
--- a/Big4_and_composition/Airlines_booking_system/Airport.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#include <iostream>
-
-class Airport
-{
-
- char* cityName;
- char id[4];
-
- void CopyFrom(const Airport& other);
- void Free();
-
-public:
-
- Airport(const char* cityName,const char* id);
- Airport(const Airport& other);
- Airport& operator=(const Airport& other);
- ~Airport();
-
- const char* getId() const;
- const char* getCityName() const;
- void print() const;
-}; \ No newline at end of file
diff --git a/Big4_and_composition/Airlines_booking_system/Flight.cpp b/Big4_and_composition/Airlines_booking_system/Flight.cpp
deleted file mode 100644
index b7436a3..0000000
--- a/Big4_and_composition/Airlines_booking_system/Flight.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "Flight.h"
-
-Flight::Flight(const char* originAirportName, const char* originAirportId,
- const char* destAirportName, const char* destAirportId, int durration) : origin(originAirportName, originAirportId), dest(destAirportName,destAirportId)
-{
- this->durration = durration;
-}
-
-Flight::Flight(const Airport& _origin, const Airport& _dest, int durration) : origin(_origin), dest(_dest)
-{
- this->durration = durration;
-}
-const Airport& Flight::getOrigin()
-{
- return origin;
-}
-const Airport& Flight::getDestination()
-{
- return dest;
-}
-void Flight::print() const
-{
- origin.print();
- std::cout << "-->";
- dest.print();
- std::cout << std::endl;
-} \ No newline at end of file
diff --git a/Big4_and_composition/Airlines_booking_system/Flight.h b/Big4_and_composition/Airlines_booking_system/Flight.h
deleted file mode 100644
index 177aeaa..0000000
--- a/Big4_and_composition/Airlines_booking_system/Flight.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "Airport.h"
-
-class Flight
-{
-
-
- Airport origin;
- Airport dest;
- int durration;
-
-public:
- Flight(const char* originAirportName, const char* originAirportId,
- const char* destAirportName, const char* destAirportId, int durration);
-
- Flight(const Airport& origin,const Airport& dest, int durration);
-
- const Airport& getOrigin();
- const Airport& getDestination();
-
- void print() const;
-}; \ No newline at end of file
diff --git a/Big4_and_composition/Airlines_booking_system/Source.cpp b/Big4_and_composition/Airlines_booking_system/Source.cpp
deleted file mode 100644
index 6d84dbd..0000000
--- a/Big4_and_composition/Airlines_booking_system/Source.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-
-#include "Airline.h"
-
-
-
-int main()
-{
-
- Airline a("Lufthansa");
- a.addFlight("Sofia", "SOF", "Berlin", "TGL", 33);
-
- a.addFlight("Berlin", "TGL", "London", "LTN", 55);
-
- a.addFlight("London", "LTN", "Sofia", "SOF", 66);
-
- a.addFlight("Berlin", "SCH", "Sofia", "SOF", 51);
-
- a.addFlight("London", "LTN", "Moscow", "MSC", 96);
-
- a.print();
-
-
-} \ No newline at end of file
diff --git a/Big4_and_composition/test b/Big4_and_composition/test
deleted file mode 100644
index 9daeafb..0000000
--- a/Big4_and_composition/test
+++ /dev/null
@@ -1 +0,0 @@
-test