Question: In C++ please show all code for the answer please. We need to add an iterator and the main functions. I believe that you need

In C++ please show all code for the answer please.

We need to add an iterator and the main functions. I believe that you need to add five functions and nested class definitions. Please fulfill the code without changing anything posted below and explain why you picked those functions and how the nested class definition with the iterator work. Please show the output that you have received.

// GoFIterator.h #ifndef GOF_ITERATOR_H #define GOF_ITERATOR_H class GoFIterator { public: virtual void first() = 0; virtual void next() = 0; virtual bool isDone() = 0; virtual int currentItem() = 0; }; #endif // GOF_ITERATOR_H // IntegerBuffer.h #ifndef INTEGER_BUFFER_H #define INTEGER_BUFFER_H #include "GoFIterator.h" class IntegerBuffer { private: int data[32]; int dataLength = 0; int dataCapacity = 32; public: bool add(int value); int add(int* values, int numValues); }; #endif // INTEGER_BUFFER_H // IntegerBuffer.cpp #include "IntegerBuffer.h" bool IntegerBuffer::add(int value) { if (dataLength < dataCapacity) { data[dataLength] = value; ++dataLength; return true; } else return false; } int IntegerBuffer::add(int values[], int numValues) { int count = 0; for (int i = 0; i < numValues; ++i) if (add(values[i])) ++count; return count; }

// testHW2.cpp #include #include #include "IntegerBuffer.h" using namespace std; int main() { const int numberOfValues = 16; int values[numberOfValues] = {23, 12, -6, 14, 0, 37, -26, 5, 11, -4, 16, 12, 8, -3, 6, -2}; IntegerBuffer ibuf; ibuf.add(values, numberOfValues); ibuf.add(values, numberOfValues); cout << "C++" << endl; /* // this section tests the iterator int column = 0; GoFIterator* iter = ibuf.createIterator(); for (iter->first(); !iter->isDone(); iter->next()) { if (column >= 10) { cout << endl; column = 1; } else ++column; cout << setw(5) << iter->currentItem(); } cout << endl; // end if iterator test */ return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!