Question: I need help getting an iterator's output in C++; I know that five functions need to be added. I also need the program to work

I need help getting an iterator's output in C++; I know that five functions need to be added. I also need the program to work in Mobaxterm and have this as the compile with these two commands and this output. Please show the code and output in Mobaxterm. Thank you.

g++ -std=c++11 IntegerBuffer.cpp testHW2.cpp

a.out

C++ 23 12 -6 14 0 37 -26 5 11 -4 16 12 8 -3 6 -2 23 12 -6 14 0 37 -26 5 11 -4 16 12 8 -3 6 -2

Here is the code and files.

// 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!