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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
