#ifndef List02
#define List02 1
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
struct ListException
{
ListException(char* m)
{
cout<<endl;
cout<<"I am the list and I am"<<m<<".";
cout<<endl;
}
};
class List
{
int size;
int count;
string* L;
int cursor;
public:
List(int sz=100):size(sz),count(0),cursor(-1){L=new string[size];}
List(istream& i,int sz=100):size(sz),count(0),cursor(-1){L=new string[size];Scan(i);}
~List(){if(L) delete[]L;}
bool IsFull(void)
{
return count>=size-1;
}
void Insert(string v)
{
if(IsFull()) throw ListException("full");
L[count++]=v;
}
void Scan(istream& i)
{
for(;;)/>
{
string v;
i>>v; if(i.eof())break;
Insert(v);
}
}
void Print(ostream& o, const char* title)
{
o<<endl;
o<<title<<"={";
for(int a=0;a<count;a++)
{
if(a!=0) o<<",";
o<<L[a];
}
o<<"}";
o<<endl;
}
void First(void){cursor=0;}
void Next(void){if (cursor<count) cursor++;}
bool IsEol(void)[color="#FF0000"]
{ if (cursor<0||cursor>count) throw ListException(cursor,count); //C2661:'ListException::ListException' : no overloaded[/color] function takes 2
return cursor>=count;
}
string Member(void)
[color="#FF0000"]{ if (cursor<0||cursor>=count) throw ListException(cursor,count); //C2661:'ListException::ListException' : no overloaded[/color]
return L[cursor];
}
};
#endif
This post has been edited by Salem_c: 09 October 2012 - 12:25 PM
Reason for edit:: added [code][/code] tags - learn to use them yourself

New Topic/Question
Reply



MultiQuote




|