Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- class Circle {
- public:
- double radius;
- int x, y;
- Circle(double radius, int x, int y) {
- this->radius = radius;
- this->x = x;
- this->y = y;
- }
- Circle() {};
- };
- class CircleArray {
- private:
- Circle * arr;
- int n;
- double *lengths;
- double PI = 3.14159265;
- public:
- CircleArray(Circle *a, int n) {
- lengths = new double[n];
- for (int i = 0; i < n; i++) {
- lengths[i] = 2 * PI * a[i].radius;
- }
- this->n = n;
- arr = a;
- }
- ~CircleArray() {
- delete lengths;
- }
- Circle& operator[] (int i) {
- return arr[i];
- };
- circleIterator& begin() {
- return circleIterator(this);
- }
- circleIterator& end() {
- circleIterator it(this);
- it.setCount = getSize();
- return it;
- }
- double *getLenghts() {
- return lengths;
- }
- int getSize() {
- return n;
- }
- Circle *getArray() {
- return arr;
- }
- };
- class circleIterator : public iterator<forward_iterator_tag, Circle> {
- private:
- CircleArray * circleArray;
- int count;
- double PI = 3.14159265;
- public:
- circleIterator(CircleArray *arr) {
- circleArray = arr;
- count = 0;
- }
- bool isEnd() {
- return count >= circleArray->getSize();
- }
- double operator* () {
- if (isEnd()) {
- throw "index out of range";
- }
- return circleArray->getLenghts()[count];
- }
- circleIterator& operator++ () {
- count++;
- return *this;
- }
- circleIterator& operator++ (int) {
- circleIterator temp(*this);
- operator++();
- return temp;
- }
- circleIterator& operator= (double newLen) {
- int i = getCount();
- circleArray->getLenghts()[i] = newLen;
- circleArray->getArray()[i].radius = newLen / (2 * PI);
- return *this;
- }
- int getCount() {
- return count;
- }
- void setCount(int n) {
- this->count = n;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement