PointSystem.cpp 895 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //
  2. // Created by jovian on 15/01/18.
  3. //
  4. #include <iostream>
  5. #include "PointSystem.h"
  6. PointSystem::PointSystem() : nb(0) {}
  7. void PointSystem::addPoint(int p) {
  8. if (nb >= MAX_SIZE)
  9. return;
  10. points[nb] = p;
  11. nb ++;
  12. }
  13. void PointSystem::display() {
  14. std::cout << "Welcome in my system !!!" << std::endl;
  15. std::cout << nb << " points." << std::endl;
  16. for (int i(0); i < nb; i++)
  17. std::cout << i << " : " << points[i] << std::endl;
  18. }
  19. std::ostream &operator<<(std::ostream &os, const PointSystem &pointSystem) {
  20. os << pointSystem.nb << std::endl;
  21. for (int i(0); i < pointSystem.nb; i++)
  22. os << pointSystem.points[i] << std::endl;
  23. return os;
  24. }
  25. std::istream &operator>>(std::istream &is, PointSystem &pointSystem) {
  26. is >> pointSystem.nb;
  27. for (int i(0); i < pointSystem.nb; i++)
  28. is >> pointSystem.points[i];
  29. return is;
  30. }