Sharing of my labs carried out during the TDDE18 course at Linköping University
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

components.h 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef COMPONENTS
  2. #define COMPONENTS
  3. #include <string>
  4. /*
  5. Lab 4 - TDDE18 - Components - Header file
  6. */
  7. /// Link class, represents a node between different components
  8. class Link {
  9. public:
  10. Link();
  11. ~Link();
  12. double charge;
  13. };
  14. /// Base component class
  15. class Component {
  16. public:
  17. Component(std::string const _name, Link& _a, Link& _b);
  18. virtual ~Component() = default;
  19. std::string get_name() const;
  20. virtual void simulate(double const _dt) = 0;
  21. virtual double voltage() const;
  22. virtual double current() const = 0;
  23. protected:
  24. std::string name{};
  25. Link& a;
  26. Link& b;
  27. };
  28. /// Derived (from component) class resistor
  29. class Resistor : public Component {
  30. public:
  31. Resistor(std::string const _name, Link& _a, Link& _b, double const _resistance);
  32. virtual void simulate(double const _dt) override;
  33. using Component::voltage;
  34. virtual double current() const override;
  35. private:
  36. double resistance;
  37. };
  38. /// Derived (from component) class capacitor
  39. class Capacitor : public Component {
  40. public:
  41. Capacitor(std::string const _name, Link& _a, Link& _b, double const _farad);
  42. virtual void simulate(double const _dt) override;
  43. using Component::voltage;
  44. virtual double current() const override;
  45. private:
  46. double farad;
  47. double charge;
  48. };
  49. /// Derived (from component) class battery
  50. class Battery : public Component {
  51. public:
  52. Battery(std::string const _name, Link& _a, Link& _b, double const _potential);
  53. virtual void simulate(double const) override;
  54. virtual double voltage() const override;
  55. virtual double current() const override;
  56. private:
  57. double potential;
  58. };
  59. #endif