I am suppose to replace the iterator GetNextItem function with two seperate iterators with void advance(); ItemType CurrentItem() const;. Also the only wayto get the program to work is to make int num a global variable. Well I dont think my professor wants any global variables. He asks for a function that prints out to a file. Here is my program:
#include <fstream>
#include <iomanip>
#include <iostream>
using namespace std;
#include "list.cpp"
int num;
List myclass;
void printlist (ofstream&, List);
int main ()
{
ifstream enter;
ofstream output4;
//open data file
enter.open("enter.txt");
//if not open give error message
if (!enter)
{
cout << "Did not open enter.txt" <<endl;
return 1;
}
//open output file
output4.open("exit.txt");
//if not give error message
if (!output4)
{
cout << "Did not open exit.txt" << endl;
return 1;
}
// end of file loop with test (call ispresent).
enter >> num;
while (enter && !myclass.IsFull())
{
if (!myclass.IsPresent(num))
{
myclass.Insert(num);
}enter >> num;
}
printlist (output4, myclass);
cout << "THE END" << endl;
enter.close();
output4.close();
getchar();
return 0;
}
void printlist (ofstream& output4, List myclass)
{
myclass.Reset();
int limit = myclass.Length();
output4 << "Number of numbers: " << limit << endl;
output4 << "New List" << endl;
for (int count =0; count < limit; count++)
{
num = myclass.GetNextItem();
output4 << num << endl;
}
}
The GetNextItem Function in the class:
ItemType List::GetNextItem()
// Precondition:
// Iteration has been initialized by call to Reset;
// No transformers have been invoked since last call
// Postcondition:
// Returns item at the currentPos@entry in the list and
// resets current to next position or first position if
// last item is returned
{
ItemType item;
item = data[currentPos];
if (currentPos == length - 1)
currentPos = 0;
else
currentPos++;
return item;
}
sorry post is so long...dont know how to make seperate scrolling windows inside the post.

Please do not tell me the answer...i need to learn this, so just point me in the right direction. Thanks guys.
