Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include "Prison.h"
  2. #include <cstring>
  3.  
  4.  
  5. Prison::Prison()
  6. {
  7. prisoners_count = 0;
  8. guards_count = 0;
  9. }
  10.  
  11. Prison::~Prison()
  12. {
  13. }
  14.  
  15. void Prison::addGuard(const char * name, const unsigned short working_years, const unsigned short cought_criminals)
  16. {
  17. if (guards_count >= MAX_GUARD_COUNT)
  18. {
  19. cout << "Gurads limit reached, current gurads count " << guards_count << endl;;
  20. return;
  21. }
  22. guards[++guards_count - 1] = Guard(name, working_years, cought_criminals);
  23. }
  24.  
  25. void Prison::addPrisoner(const char * name, const char * crime_group, const unsigned short crime_year)
  26. {
  27. if (prisoners_count >= MAX_PRISONER_COUNT)
  28. {
  29. cout << "Prisoners limit reached, current prisoners count " << prisoners_count << endl;;
  30. return;
  31. }
  32. prisoners[++prisoners_count - 1] = Prisoner(name, crime_group, crime_year);
  33. }
  34.  
  35. void Prison::PrintAllPrisoners() const
  36. {
  37. for (size_t i = 0; i < prisoners_count; i++)
  38. {
  39. cout << prisoners[i].getName() << endl;
  40. }
  41. }
  42.  
  43. void Prison::Migrate(const Prison & rhs)
  44. {
  45. // release all prisoners
  46. // if we set the counter to 0 The interface have no way of knowing about the other records
  47. prisoners_count = 0;
  48. for (size_t i = 0; i < rhs.prisoners_count; i++)
  49. {
  50. if (rhs.prisoners[i].getYear() >= 10)
  51. {
  52. prisoners[++prisoners_count - 1] = rhs.prisoners[i];
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement