SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. ** EPITECH PROJECT, 2019
  3. ** Droid.cpp
  4. ** File description:
  5. ** Droid.cpp
  6. */
  7.  
  8. #include "Droid.hpp"
  9.  
  10. // CONSTRUCTOR
  11.  
  12. Droid::Droid(std::string serialNumber) : Attack(25), Toughness(15)
  13. {
  14.     this->Id = serialNumber;
  15.     this->Status = new std::string("Standing by");
  16.     this->Energy = 50;
  17.     std::cout << "Droid '"<< this->Id << "' Activated" << std::endl;
  18. }
  19.  
  20. // COPY CONSTRUCTOR
  21.  
  22. Droid::Droid(const Droid &other) : Attack(other.Attack), Toughness(other.Toughness)
  23. {
  24.     this->Id = other.Id;
  25.     this->Status = other.Status;
  26.     this->Energy = other.Energy;
  27.  
  28.     std::cout << "Droid '" << this->Id << "' Activated, Memory Dumped" << std::endl;
  29. }
  30.  
  31. // DESTRUCTOR
  32.  
  33. Droid::~Droid()
  34. {
  35.     std::cout << "Droid '" << this->Id << "' Destroyed" << std::endl;
  36. }
  37.  
  38. // OPERATEUR
  39.  
  40. Droid &Droid::operator=(Droid &rhs)
  41. {
  42.     this->Id = rhs.Id;
  43.     this->Status = rhs.Status;
  44.     this->Energy = rhs.Energy;
  45.     return (*this);
  46. }
  47.  
  48. bool Droid::operator==(Droid &rhs)
  49. {
  50.     if (this->Id == rhs.Id)
  51.         if (this->Status == rhs.Status)
  52.             if (this->Energy == rhs.Energy)
  53.                 return (true);
  54.     return (false);
  55. }
  56.  
  57. bool Droid::operator!=(Droid &rhs)
  58. {
  59.     if (this->Id == rhs.Id)
  60.         if (this->Status == rhs.Status)
  61.             if (this->Energy == rhs.Energy)
  62.                 return (false);
  63.     return (true);
  64. }
  65.  
  66. std::ostream& operator<<(std::ostream& os, Droid &droid)
  67. {
  68.     return (os << "Droid '" << droid.getId() << "'," << droid.getStatus() << "," << droid.getEnergy());
  69. }
  70.  
  71. void Droid::operator<<(size_t &battery)
  72. {
  73.     while (this->getEnergy() < 100 && battery > 0) {
  74.         this->setEnergy((this->getEnergy() + 1));
  75.         battery--;
  76.     }
  77. }
  78.  
  79. // GETTER AND SETTER
  80.  
  81. std::string Droid::Droid::getId()
  82. {
  83.     return (this->Id);
  84. }
  85.  
  86. size_t Droid::Droid::getEnergy()
  87. {
  88.     return (this->Energy);
  89. }
  90.  
  91. const size_t Droid::Droid::getAttack()
  92. {
  93.     return (this->Attack);
  94. }
  95.  
  96. const size_t Droid::Droid::getToughness()
  97. {
  98.     return (this->Toughness);
  99. }
  100.  
  101. std::string &Droid::Droid::getStatus()
  102. {
  103.     return (*this->Status);
  104. }
  105.  
  106. void Droid::Droid::setId(std::string Id)
  107. {
  108.     this->Id = Id;
  109. }
  110.  
  111. void Droid::Droid::setEnergy(size_t Energy)
  112. {
  113.     this->Energy = Energy;
  114. }
  115.  
  116. void Droid::Droid::setStatus(std::string *Status)
  117. {
  118.     this->Status = new std::string (*Status);
  119. }
  120.  
  121.  
  122. ---------------------------------------------------------------------------------------------------------------------------
  123. /*
  124. ** EPITECH PROJECT, 2019
  125. ** Droid.hpp
  126. ** File description:
  127. ** Droid.hpp
  128. */
  129.  
  130. #ifndef DROID_HPP_
  131. # define DROID_HPP_
  132.  
  133. #include <iostream>
  134. #include <string>
  135. #include <fstream>
  136.  
  137. class Droid {
  138.     public:
  139.         Droid(std::string serialNumber = "");
  140.         Droid(const Droid &other);
  141.         ~Droid();
  142.         Droid &operator=(Droid &rhs);
  143.         bool operator==(Droid &rhs);
  144.         bool operator!=(Droid &rhs);
  145.         void operator<<(size_t &battery);
  146.         std::string getId();
  147.         size_t getEnergy();
  148.         const size_t getAttack();
  149.         const size_t getToughness();
  150.         std::string &getStatus();
  151.         void setId(std::string Id);
  152.         void setEnergy(size_t Energy);
  153.         void setAttack(const size_t Attack);
  154.         void setToughness(const size_t Toughness);
  155.         void setStatus(std::string *Status);
  156.  
  157.     private:
  158.         std::string Id;
  159.         size_t Energy;
  160.         const size_t Attack;
  161.         const size_t Toughness;
  162.         std::string *Status;
  163. };
  164.  
  165. std::ostream &operator<<(std::ostream& os, Droid &droid);
  166.  
  167. #endif
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top