diff --git a/Planet.hpp b/Planet.hpp deleted file mode 100644 index 0bcc679..0000000 --- a/Planet.hpp +++ /dev/null @@ -1,259 +0,0 @@ -#ifndef PLANET_HPP -#define PLANET_HPP - -#include -#include -#include -#include -#include -#include -#include - - -using namespace std; - -/* - * PlanetType (enum class) - Strict type safety for planet creation - * Unlike raw char inputs, enum class prevents invalid states at compile time - * and provides a clear, self-documenting set of valid planet types. - */ -enum class PlanetType { Vector, Stack, Queue }; - -/* - * parsePlanetType: Converts user input to a validated PlanetType enum - * Accepts both uppercase and lowercase input for user convenience. - * Throws std::invalid_argument if the input is not a recognized type. - */ -inline PlanetType parsePlanetType(char input) { - switch (input) { - case 'V': - case 'v': - return PlanetType::Vector; - case 'S': - case 's': - return PlanetType::Stack; - case 'Q': - case 'q': - return PlanetType::Queue; - default: - throw invalid_argument(string("Invalid planet type: '") + input + - "'. Use V, S, or Q."); - } -} - -/* - * BasePlanet (Abstract Base Class Template) - * Generics: template allows planets to store ANY data type, - * not just int. This follows the Open/Closed Principle. - * - * Const-Correctness: All non-modifying methods are marked const. - * Virtual destructor ensures safe polymorphic deletion (RAII). - */ -template class BasePlanet { -public: - string name; // RAII: std::string manages its own memory - int metadata = 0; // RAII: plain int, no dynamic allocation needed - - virtual ~BasePlanet() = - default; // Virtual destructor for safe polymorphic deletion - - // Pure virtual functions - each derived class implements its own behavior - virtual void push(const T &value) = 0; // const ref: avoids unnecessary copy - virtual void pop() = 0; - virtual int size() const = 0; // const: does not modify state - virtual bool empty() const = 0; // const: does not modify state - virtual void display() const = 0; // const: does not modify state - virtual string typeName() const = 0; // const: does not modify state - virtual void removeBelow(const T &threshold, int &removedCount) = 0; -}; - -/* - * VectorPlanet - Planet that uses std::vector for storage - * Only allocates a vector, no stack or queue memory wasted. - */ -template class VectorPlanet : public BasePlanet { -public: - vector v; - - void push(const T &value) override { v.push_back(value); } - - void pop() override { - if (v.empty()) - throw underflow_error("Cannot pop from empty Vector planet"); - v.pop_back(); - } - - int size() const override { return v.size(); } - bool empty() const override { return v.empty(); } - string typeName() const override { return "Vector"; } - - void display() const override { - cout << "(" << this->typeName() << ") : "; - if (v.empty()) - cout << "EMPTY"; - for (size_t i = 0; i < v.size(); i++) - cout << v[i] << " "; - cout << endl; - } - - void removeBelow(const T &threshold, int &removedCount) override { - int beforeSize = v.size(); - vector survivors; - size_t j = 0; - while (j < v.size()) { - const T °er = v[j]; - if (deger >= threshold) { - survivors.push_back(deger); - } - j++; - } - v = move(survivors); // Move semantics: avoids copying the entire vector - removedCount += (beforeSize - (int)v.size()); - } -}; - -/* - * StackPlanet - Planet that uses std::stack for storage - * Only allocates a stack, no vector or queue memory wasted. - */ -template class StackPlanet : public BasePlanet { -public: - stack s; - - void push(const T &value) override { s.push(value); } - - void pop() override { - if (s.empty()) - throw underflow_error("Cannot pop from empty Stack planet"); - s.pop(); - } - - int size() const override { return s.size(); } - bool empty() const override { return s.empty(); } - string typeName() const override { return "Stack"; } - - void display() const override { - cout << "(" << this->typeName() << ") : "; - stack temp = s; - if (temp.empty()) - cout << "EMPTY"; - while (!temp.empty()) { - cout << temp.top() << " "; - temp.pop(); - } - cout << endl; - } - - void removeBelow(const T &threshold, int &removedCount) override { - int beforeSize = s.size(); - stack survivors; - stack temp; - - while (!s.empty()) { - temp.push(move(s.top())); // Move semantics - s.pop(); - } - - while (!temp.empty()) { - T deger = move(temp.top()); // Move semantics - temp.pop(); - if (deger >= threshold) { - survivors.push(move(deger)); - } - } - - s = move(survivors); // Move semantics: avoids copying the entire stack - removedCount += (beforeSize - (int)s.size()); - } -}; - -/* - * QueuePlanet - Planet that uses std::queue for storage - * Only allocates a queue, no vector or stack memory wasted. - */ -template class QueuePlanet : public BasePlanet { -public: - queue q; - - void push(const T &value) override { q.push(value); } - - void pop() override { - if (q.empty()) - throw underflow_error("Cannot pop from empty Queue planet"); - q.pop(); - } - - int size() const override { return q.size(); } - bool empty() const override { return q.empty(); } - string typeName() const override { return "Queue"; } - - void display() const override { - cout << "(" << this->typeName() << ") : "; - queue temp = q; - if (temp.empty()) - cout << "EMPTY"; - while (!temp.empty()) { - cout << temp.front() << " "; - temp.pop(); - } - cout << endl; - } - - void removeBelow(const T &threshold, int &removedCount) override { - int beforeSize = q.size(); - queue survivors; - - while (!q.empty()) { - T deger = move(q.front()); // Move semantics - q.pop(); - if (deger >= threshold) { - survivors.push(move(deger)); - } - } - - q = move(survivors); // Move semantics: avoids copying the entire queue - removedCount += (beforeSize - (int)q.size()); - } -}; - -/* - * PlanetFactory (Factory Design Pattern) - * Centralizes planet creation logic in one place. - * Open/Closed Principle: To add a new planet type (e.g., DequePlanet), - * you only add a new case here - no changes to SolarSystem needed. - * - * Returns unique_ptr for RAII ownership transfer via move semantics. - */ -template class PlanetFactory { -public: - static unique_ptr> create(PlanetType type) { - switch (type) { - case PlanetType::Vector: - return make_unique>(); - case PlanetType::Stack: - return make_unique>(); - case PlanetType::Queue: - return make_unique>(); - } - throw invalid_argument("Unknown PlanetType in factory"); - } -}; - -/* - * SMART POINTER VARIETY - Future Extension Guide - * - * Current: unique_ptr> — exclusive ownership (one owner per - * planet) - * - * For inter-planet interactions (e.g., moons orbiting planets): - * - shared_ptr> — multiple owners share a planet - * - weak_ptr> — non-owning observer (breaks circular - * references) - * - * Example: - * shared_ptr> planet = make_shared>(); - * weak_ptr> moon_ref = planet; // Moon observes, doesn't - * own if (auto p = moon_ref.lock()) { p->display(); } // Safe access check - */ - -#endif // PLANET_HPP diff --git a/SolarSystem.cpp b/SolarSystem.cpp deleted file mode 100644 index f2cd8be..0000000 --- a/SolarSystem.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "SolarSystem.hpp" - -/* - * Explicit Template Instantiation - * - * Since SolarSystem is a template class with implementations in the header, - * the compiler instantiates it on demand. However, we provide explicit - * instantiations here for commonly used types to: - * 1. Improve compile times in large projects (avoids redundant instantiation) - * 2. Document which types are officially supported - * 3. Maintain the 4-file project structure (Planet.hpp, SolarSystem.hpp, - * SolarSystem.cpp, main.cpp) - * - * To support a new data type (e.g., double, string), simply add: - * template class SolarSystem; - */ -template class SolarSystem; diff --git a/SolarSystem.hpp b/SolarSystem.hpp deleted file mode 100644 index 8422576..0000000 --- a/SolarSystem.hpp +++ /dev/null @@ -1,170 +0,0 @@ -#ifndef SOLARSYSTEM_HPP -#define SOLARSYSTEM_HPP - -#include "Planet.hpp" - -/* - * SolarSystem (Encapsulated Class Template) - * Generics: template allows the system to manage planets - * of any data type, not just int. - * - * All data members are private - no external access to internal state. - * All operations are public const-correct methods - controlled interface only. - * No global state - instances are created where needed. - * - * Note: Template class implementations must be in the header file - * so the compiler can instantiate them for any type T. - */ -template class SolarSystem { -private: - struct Star { - int id = 0; // Star's identifier - to access the core - int planet_count = 0; // Number of planets in the system - int element_count = 0; // Total element count in the system - }; - - Star star; - vector>> - planets; // Polymorphic ownership via unique_ptr (RAII) - -public: - /* - * elementCount: Displays total element count in the system - * Const-Correctness: marked const - only reads data - * Time Complexity: O(1) - */ - void elementCount() const { - cout << " Element count :" << star.element_count << endl; - } - - /* - * planetCount: Displays total planet count in the system - * Const-Correctness: marked const - only reads data - * Time Complexity: O(1) - */ - void planetCount() const { - cout << " Planet count :" << star.planet_count << endl; - } - - /* - * pushToPlanet: Inserts an element into a specific planet - * Uses const T& to avoid unnecessary copy of the value - * Time Complexity: O(1) amortized - */ - void pushToPlanet(int index, const T &value) { - if (index < 0 || index >= (int)planets.size()) - throw out_of_range("Planet index " + to_string(index) + - " is out of range"); - planets[index]->push(value); // Polymorphic call - star.element_count++; - } - - /* - * addPlanet: Creates a new planet using PlanetFactory (Factory Pattern) - * The factory centralizes creation logic - SolarSystem doesn't need to - * know about derived classes. Adding new planet types requires no changes - * here. Move Semantics: unique_ptr is moved into the planets vector. Time - * Complexity: O(1) amortized - */ - void addPlanet() { - char input; - cout << "Enter the type of Planet" << endl - << "V For Vector- S For Stack- Q For Queue : "; - cin >> input; - - // Validate input through enum class - throws if invalid - PlanetType type = parsePlanetType(input); - - // Factory Pattern: creation logic is delegated to PlanetFactory - unique_ptr> p = PlanetFactory::create(type); - - p->name = p->typeName() + "_Planet"; - p->metadata = planets.size(); - - cout << "Planet Id: " << p->metadata << " (" << p->name << ")" << endl; - - planets.push_back(move(p)); // Move semantics: transfers ownership - star.planet_count = planets.size(); - star.id = planets.size() - 1; - } - - /* - * blackHole: Completely destroys a planet and frees its memory - * unique_ptr ensures automatic deallocation when erased (RAII) - * Time Complexity: O(n) where n is the number of planets - */ - void blackHole(int planetIndex) { - if (planetIndex < 0 || planetIndex >= (int)planets.size()) - throw out_of_range("Planet index " + to_string(planetIndex) + - " is out of range"); - - BasePlanet &p = *planets[planetIndex]; - int elementsLost = p.size(); // Polymorphic call - - cout << "BLACK HOLE: Planet [" << p.name << "] absorbed! " << elementsLost - << " elements lost." << endl; - - // Erase planet - unique_ptr automatically deletes the derived object - planets.erase(planets.begin() + planetIndex); - star.planet_count--; - star.element_count -= elementsLost; - } - - /* - * supernova: Destroys entire solar system - * planets.clear() destroys all unique_ptrs, triggering automatic cleanup - * Time Complexity: O(n) where n is the number of planets - */ - void supernova() { - planets.clear(); - star.planet_count = 0; - star.element_count = 0; - star.id = 0; - } - - /* - * gravityPull: Removes elements below threshold from all planets - * Uses const T& for the threshold to avoid unnecessary copy - * Time Complexity: O(n*m) where n=planets, m=elements per planet - */ - void gravityPull(const T &threshold) { - cout << "GRAVITY PULL: Absorbing elements < " << threshold << endl; - int totalPulled = 0; - - for (size_t i = 0; i < planets.size(); i++) { - planets[i]->removeBelow(threshold, totalPulled); // Polymorphic call - } - - star.element_count -= totalPulled; - cout << totalPulled << " elements absorbed by gravity." << endl; - } - - /* - * deleteElement: Removes one element from a specific planet - * Time Complexity: O(1) - */ - void deleteElement(int index) { - if (index < 0 || index >= (int)planets.size()) - throw out_of_range("Planet index " + to_string(index) + - " is out of range"); - planets[index] - ->pop(); // Polymorphic call (may throw underflow_error if empty) - star.element_count--; - } - - /* - * travelPlanet: Traverses all planets and prints their elements - * Const-Correctness: marked const - only reads and displays data - * Time Complexity: O(n * m) where n = planets, m = elements per planet - */ - void travelPlanet() const { - for (size_t i = 0; i < planets.size(); i++) { - BasePlanet &p = *planets[i]; - cout << i + 1 << ". Planet [" << p.name << "] (ID: " << p.metadata - << ") Elements "; - p.display(); // Polymorphic call - } - } -}; - -#endif // SOLARSYSTEM_HPP diff --git a/data_sturctures_project.cpp b/data_sturctures_project.cpp deleted file mode 100644 index b8036c8..0000000 --- a/data_sturctures_project.cpp +++ /dev/null @@ -1,443 +0,0 @@ -/*Central management of collections with various behaviors*/ -#include -using namespace std; -#include // For unique_ptr (RAII ownership of polymorphic planets) -#include -#include -#include // For exception handling (out_of_range, underflow_error, invalid_argument) -#include // RAII-based string management -#include - - -/* - * PlanetType (enum class) - Strict type safety for planet creation - * Unlike raw char inputs, enum class prevents invalid states at compile time - * and provides a clear, self-documenting set of valid planet types. - */ -enum class PlanetType { Vector, Stack, Queue }; - -/* - * parsePlanetType: Converts user input to a validated PlanetType enum - * Accepts both uppercase and lowercase input for user convenience. - * Throws std::invalid_argument if the input is not a recognized type. - */ -PlanetType parsePlanetType(char input) { - switch (input) { - case 'V': - case 'v': - return PlanetType::Vector; - case 'S': - case 's': - return PlanetType::Stack; - case 'Q': - case 'q': - return PlanetType::Queue; - default: - throw invalid_argument(string("Invalid planet type: '") + input + - "'. Use V, S, or Q."); - } -} - -/* - * Planet (Base Class) - Abstract interface for all planet types - * Each derived class holds ONLY the data structure it actually uses, - * eliminating the memory waste of the old design. - * - * Virtual functions enable polymorphism: the correct behavior is - * dispatched at runtime without any if/else type-checking. - */ -class Planet { -public: - string name; // RAII: std::string manages its own memory - int metadata = 0; // RAII: plain int, no dynamic allocation needed - - virtual ~Planet() = - default; // Virtual destructor for safe polymorphic deletion - - // Pure virtual functions - each derived class implements its own behavior - virtual void push(int value) = 0; - virtual void pop() = 0; - virtual int size() const = 0; - virtual bool empty() const = 0; - virtual void display() const = 0; - virtual string typeName() const = 0; - virtual void removeBelow(int threshold, int &removedCount) = 0; -}; - -/* - * VectorPlanet - Planet that uses std::vector for storage - * Only allocates a vector, no stack or queue memory wasted. - */ -class VectorPlanet : public Planet { -public: - vector v; - - void push(int value) override { v.push_back(value); } - - void pop() override { - if (v.empty()) - throw underflow_error("Cannot pop from empty Vector planet"); - v.pop_back(); // Removes the last element - } - - int size() const override { return v.size(); } - bool empty() const override { return v.empty(); } - string typeName() const override { return "Vector"; } - - void display() const override { - cout << "(" << typeName() << ") : "; - if (v.empty()) - cout << "EMPTY"; - for (size_t i = 0; i < v.size(); i++) - cout << v[i] << " "; - cout << endl; - } - - void removeBelow(int threshold, int &removedCount) override { - int beforeSize = v.size(); - vector survivors; - size_t j = 0; - while (j < v.size()) { - int deger = v[j]; - if (deger >= threshold) { - survivors.push_back(deger); - } - j++; - } - v = survivors; - removedCount += (beforeSize - v.size()); - } -}; - -/* - * StackPlanet - Planet that uses std::stack for storage - * Only allocates a stack, no vector or queue memory wasted. - */ -class StackPlanet : public Planet { -public: - stack s; - - void push(int value) override { s.push(value); } - - void pop() override { - if (s.empty()) - throw underflow_error("Cannot pop from empty Stack planet"); - s.pop(); // LIFO - removes the top element - } - - int size() const override { return s.size(); } - bool empty() const override { return s.empty(); } - string typeName() const override { return "Stack"; } - - void display() const override { - cout << "(" << typeName() << ") : "; - stack temp = s; // Backup to prevent data loss - if (temp.empty()) - cout << "EMPTY"; - while (!temp.empty()) { - cout << temp.top() << " "; - temp.pop(); - } - cout << endl; - } - - void removeBelow(int threshold, int &removedCount) override { - int beforeSize = s.size(); - stack survivors; - stack temp; - - // Extract all elements to temp stack (reverses order) - while (!s.empty()) { - temp.push(s.top()); - s.pop(); - } - - // Check each element and keep survivors - while (!temp.empty()) { - int deger = temp.top(); - temp.pop(); - if (deger >= threshold) { - survivors.push(deger); - } - } - - s = survivors; - removedCount += (beforeSize - s.size()); - } -}; - -/* - * QueuePlanet - Planet that uses std::queue for storage - * Only allocates a queue, no vector or stack memory wasted. - */ -class QueuePlanet : public Planet { -public: - queue q; - - void push(int value) override { q.push(value); } - - void pop() override { - if (q.empty()) - throw underflow_error("Cannot pop from empty Queue planet"); - q.pop(); // FIFO - removes the first element - } - - int size() const override { return q.size(); } - bool empty() const override { return q.empty(); } - string typeName() const override { return "Queue"; } - - void display() const override { - cout << "(" << typeName() << ") : "; - queue temp = q; // Backup to prevent data loss - if (temp.empty()) - cout << "EMPTY"; - while (!temp.empty()) { - cout << temp.front() << " "; - temp.pop(); - } - cout << endl; - } - - void removeBelow(int threshold, int &removedCount) override { - int beforeSize = q.size(); - queue survivors; - - // Check each element in queue - while (!q.empty()) { - int deger = q.front(); - q.pop(); - if (deger >= threshold) { - survivors.push(deger); - } - } - - q = survivors; - removedCount += (beforeSize - q.size()); - } -}; - -/* - * SolarSystem (Encapsulated Class) - * All data members are private - no external access to internal state. - * All operations are public methods - controlled interface only. - * No global state - instances are created where needed. - */ -class SolarSystem { -private: - struct Star { - int id = 0; // Star's identifier - to access the core - int planet_count = 0; // Number of planets in the system - int element_count = 0; // Total element count in the system - }; - - Star star; - vector> - planets; // Polymorphic ownership via unique_ptr (RAII) - -public: - /* - * elementCount: Displays total element count in the system - * Time Complexity: O(1) - Direct access to counter variable - * Space Complexity: O(1) - No additional memory used - */ - void elementCount() const { - cout << " Element count :" << star.element_count << endl; - } - - /* - * planetCount: Displays total planet count in the system - * Time Complexity: O(1) - Direct access to counter variable - * Space Complexity: O(1) - No additional memory used - */ - void planetCount() const { - cout << " Planet count :" << star.planet_count << endl; - } - - /* - * pushToPlanet: Inserts an element into a specific planet - * Time Complexity: O(1) amortized - virtual dispatch to the correct push() - * Space Complexity: O(1) - Only stores one element - */ - void pushToPlanet(int index, int value) { - if (index < 0 || index >= (int)planets.size()) - throw out_of_range("Planet index " + to_string(index) + - " is out of range"); - planets[index]->push(value); // Polymorphic call - star.element_count++; - } - - /* - * addPlanet: Creates a new planet using polymorphism - * Time Complexity: O(1) amortized - * Space Complexity: O(1) - Only the needed data structure is allocated - */ - void addPlanet() { - char input; - cout << "Enter the type of Planet" << endl - << "V For Vector- S For Stack- Q For Queue : "; - cin >> input; - - // Validate input through enum class - throws if invalid - PlanetType type = parsePlanetType(input); - - unique_ptr p; - - switch (type) { - case PlanetType::Vector: - p = make_unique(); - break; - case PlanetType::Stack: - p = make_unique(); - break; - case PlanetType::Queue: - p = make_unique(); - break; - } - - // Set planet name based on its polymorphic type - p->name = p->typeName() + "_Planet"; - p->metadata = planets.size(); - - cout << "Planet Id: " << p->metadata << " (" << p->name << ")" << endl; - - planets.push_back(move(p)); // Transfer ownership to SolarSystem - star.planet_count = planets.size(); - star.id = planets.size() - 1; - } - - /* - * blackHole: Completely destroys a planet and frees its memory - * Time Complexity: O(n) where n is the number of planets - */ - void blackHole(int planetIndex) { - if (planetIndex < 0 || planetIndex >= (int)planets.size()) - throw out_of_range("Planet index " + to_string(planetIndex) + - " is out of range"); - - Planet &p = *planets[planetIndex]; - int elementsLost = p.size(); // Polymorphic call - - cout << "BLACK HOLE: Planet [" << p.name << "] absorbed! " << elementsLost - << " elements lost." << endl; - - // Erase planet - unique_ptr automatically deletes the derived object - planets.erase(planets.begin() + planetIndex); - star.planet_count--; - star.element_count -= elementsLost; - } - - /* - * supernova: Destroys entire solar system - * Time Complexity: O(n) where n is the number of planets - */ - void supernova() { - // Clear all planets - unique_ptr automatically deletes each derived object - planets.clear(); - star.planet_count = 0; - star.element_count = 0; - star.id = 0; - } - - /* - * gravityPull: Removes elements below threshold from all planets - * Time Complexity: O(n*m) where n=planets, m=elements per planet - */ - void gravityPull(int threshold) { - cout << "GRAVITY PULL: Absorbing elements < " << threshold << endl; - int totalPulled = 0; - - for (size_t i = 0; i < planets.size(); i++) { - planets[i]->removeBelow(threshold, totalPulled); // Polymorphic call - } - - star.element_count -= totalPulled; - cout << totalPulled << " elements absorbed by gravity." << endl; - } - - /* - * deleteElement: Removes one element from a specific planet - * Time Complexity: O(1) - Polymorphic dispatch to the correct pop() - * Space Complexity: O(1) - No additional memory used - */ - void deleteElement(int index) { - if (index < 0 || index >= (int)planets.size()) - throw out_of_range("Planet index " + to_string(index) + - " is out of range"); - planets[index] - ->pop(); // Polymorphic call (may throw underflow_error if empty) - star.element_count--; - } - - /* - * travelPlanet: Traverses all planets and prints their elements - * Time Complexity: O(n * m) where n = number of planets, m = elements per - * planet Space Complexity: O(m) - Temporary copy for stack/queue traversal - */ - void travelPlanet() const { - for (size_t i = 0; i < planets.size(); i++) { - Planet &p = *planets[i]; - cout << i + 1 << ". Planet [" << p.name << "] (ID: " << p.metadata - << ") Elements "; - p.display(); // Polymorphic call - } - } -}; - -int main() { - try { - SolarSystem system; // Local instance, no global state - - system.addPlanet(); - system.addPlanet(); - system.addPlanet(); - - system.planetCount(); - system.deleteElement(0); - - system.pushToPlanet(0, 10); - system.pushToPlanet(0, 20); - system.pushToPlanet(0, 30); - system.pushToPlanet(1, 10); - system.pushToPlanet(1, 20); - system.pushToPlanet(1, 30); - system.pushToPlanet(2, 10); - system.pushToPlanet(2, 20); - system.pushToPlanet(2, 30); - - system.elementCount(); - system.travelPlanet(); - - system.deleteElement(0); - system.deleteElement(1); - system.deleteElement(2); - - system.travelPlanet(); - system.elementCount(); - - system.blackHole(1); // Destroy second planet - system.travelPlanet(); - system.planetCount(); - - system.gravityPull(15); // Remove elements < 15 - system.travelPlanet(); - system.elementCount(); - - system.supernova(); // Destroy everything - system.travelPlanet(); - system.planetCount(); - } catch (const out_of_range &e) { - cerr << "[Out of Range Error] " << e.what() << endl; - return 1; - } catch (const underflow_error &e) { - cerr << "[Underflow Error] " << e.what() << endl; - return 2; - } catch (const invalid_argument &e) { - cerr << "[Invalid Argument] " << e.what() << endl; - return 3; - } catch (const exception &e) { - cerr << "[Unexpected Error] " << e.what() << endl; - return 4; - } - - return 0; -} \ No newline at end of file diff --git a/main.cpp b/main.cpp deleted file mode 100644 index bbeed27..0000000 --- a/main.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/*Central management of collections with various behaviors*/ -#include "SolarSystem.hpp" - -int main() { - try { - SolarSystem - system; // Generics: int type, local instance (no global state) - - system.addPlanet(); - system.addPlanet(); - system.addPlanet(); - - system.planetCount(); - system.deleteElement(0); - - system.pushToPlanet(0, 10); - system.pushToPlanet(0, 20); - system.pushToPlanet(0, 30); - system.pushToPlanet(1, 10); - system.pushToPlanet(1, 20); - system.pushToPlanet(1, 30); - system.pushToPlanet(2, 10); - system.pushToPlanet(2, 20); - system.pushToPlanet(2, 30); - - system.elementCount(); - system.travelPlanet(); - - system.deleteElement(0); - system.deleteElement(1); - system.deleteElement(2); - - system.travelPlanet(); - system.elementCount(); - - system.blackHole(1); // Destroy second planet - system.travelPlanet(); - system.planetCount(); - - system.gravityPull(15); // Remove elements < 15 - system.travelPlanet(); - system.elementCount(); - - system.supernova(); // Destroy everything - system.travelPlanet(); - system.planetCount(); - } catch (const out_of_range &e) { - cerr << "[Out of Range Error] " << e.what() << endl; - return 1; - } catch (const underflow_error &e) { - cerr << "[Underflow Error] " << e.what() << endl; - return 2; - } catch (const invalid_argument &e) { - cerr << "[Invalid Argument] " << e.what() << endl; - return 3; - } catch (const exception &e) { - cerr << "[Unexpected Error] " << e.what() << endl; - return 4; - } - - return 0; -}