Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ Need to add an iterator, and the main functions. I believe that you need to add five functions and nested class definition. Please

In C++

Need to add an iterator, and the main functions. I believe that you need to add five functions and nested class definition. Please fulfill out the code without changing anything that is posted below and explain why you picked those functions and how the nested class definition with the iterator work. Please show 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

6. Are my sources reliable?

Answered: 1 week ago

Question

5. Are my sources compelling?

Answered: 1 week ago