Advertisement
Guest User

Untitled

a guest
May 26th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. class Circle {
  7. public:
  8. double radius;
  9. int x, y;
  10. Circle(double radius, int x, int y) {
  11. this->radius = radius;
  12. this->x = x;
  13. this->y = y;
  14. }
  15. Circle() {};
  16. };
  17.  
  18. class CircleArray {
  19. private:
  20. Circle * arr;
  21. int n;
  22. double *lengths;
  23. double PI = 3.14159265;
  24. public:
  25. CircleArray(Circle *a, int n) {
  26. lengths = new double[n];
  27. for (int i = 0; i < n; i++) {
  28. lengths[i] = 2 * PI * a[i].radius;
  29. }
  30. this->n = n;
  31. arr = a;
  32. }
  33.  
  34. ~CircleArray() {
  35. delete lengths;
  36. }
  37.  
  38. Circle& operator[] (int i) {
  39. return arr[i];
  40. };
  41.  
  42. circleIterator& begin() {
  43. return circleIterator(this);
  44. }
  45.  
  46. circleIterator& end() {
  47. circleIterator it(this);
  48. it.setCount = getSize();
  49. return it;
  50. }
  51. double *getLenghts() {
  52. return lengths;
  53. }
  54.  
  55. int getSize() {
  56. return n;
  57. }
  58.  
  59. Circle *getArray() {
  60. return arr;
  61. }
  62. };
  63.  
  64. class circleIterator : public iterator<forward_iterator_tag, Circle> {
  65. private:
  66. CircleArray * circleArray;
  67. int count;
  68. double PI = 3.14159265;
  69. public:
  70. circleIterator(CircleArray *arr) {
  71. circleArray = arr;
  72. count = 0;
  73. }
  74.  
  75. bool isEnd() {
  76. return count >= circleArray->getSize();
  77. }
  78.  
  79. double operator* () {
  80. if (isEnd()) {
  81. throw "index out of range";
  82. }
  83. return circleArray->getLenghts()[count];
  84. }
  85.  
  86. circleIterator& operator++ () {
  87. count++;
  88. return *this;
  89. }
  90.  
  91. circleIterator& operator++ (int) {
  92. circleIterator temp(*this);
  93. operator++();
  94. return temp;
  95. }
  96.  
  97. circleIterator& operator= (double newLen) {
  98. int i = getCount();
  99. circleArray->getLenghts()[i] = newLen;
  100. circleArray->getArray()[i].radius = newLen / (2 * PI);
  101. return *this;
  102. }
  103.  
  104. int getCount() {
  105. return count;
  106. }
  107.  
  108. void setCount(int n) {
  109. this->count = n;
  110. }
  111. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement