Z
zfareed
I have a program with a list being read from a file and stored in an
array. On compilation I get the following errors in my implementation
file.I cannot figure out the problem.
//specification List.h
#include <fstream>
const int MAX_ITEMS = 20;
typedef int ItemType;
class List
{
public:
void Store(ifstream& infile,ItemType item);
// Pre: The list is not full
// Post: item is in the list
void PrintList();
// Post: If the list is not empty, the elements are
// printed on the screen; otherwise "The list
// is empty" is printed on the screen.
int Length();
// Post: return value is the number of items in the
list.
bool IsEmpty();
// Post: returns true if list empty;false otherwise
bool IsFull();
// Post: returns true if there is no more room in the
// list; false otherwise.
List();
// Constructor
// Post: Empty list is created.
private:
int length;
ItemType values[MAX_ITEMS];
};
//implementation List .cpp
#include <fstream>
#include <iostream>
#include "List.h"
using namespace std;
List::List()
{
length = 0;
}
bool List::IsFull()
{
return (length == MAX_ITEMS);
}
bool List::IsEmpty()
{
return (length == 0);
}
int List::Length()
{
return length;
}
void List:rintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values << " , " << endl;
}
void List::Store(ifstream& infile,ItemType item)
{
infile >> item;
while(infile)
{
values[length] = item;
length++;
infile >> item;
}
}
#include <fstream>
#include <iostream>
#include "List.h"
using namespace std;
List::List()
{
length = 0;
}
bool List::IsFull()
{
return (length == MAX_ITEMS);
}
bool List::IsEmpty()
{
return (length == 0);
}
int List::Length()
{
return length;
}
void List:rintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values << " , " << endl;
}
void List::Store(ifstream& infile,ItemType item)
{
infile >> item;
while(infile)
{
values[length] = item;
length++;
infile >> item;
}
}
#include <fstream>
#include <iostream>
#include "List.h"
using namespace std;
List::List()
{
length = 0;
}
bool List::IsFull()
{
return (length == MAX_ITEMS);
}
bool List::IsEmpty()
{
return (length == 0);
}
int List::Length()
{
return length;
}
void List:rintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values << " , " << endl;
}
void List::Store(ifstream& infile,ItemType item)
{
infile >> item;
while(infile)
{
values[length] = item;
length++;
infile >> item;
}
}
#include <fstream>
#include <iostream>
#include "List.h"
using namespace std;
List::List()
{
length = 0;
}
bool List::IsFull()
{
return (length == MAX_ITEMS);
}
bool List::IsEmpty()
{
return (length == 0);
}
int List::Length()
{
return length;
}
void List:rintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values << " , " << endl;
}
void List::Store(ifstream& infile,ItemType item)
{
infile >> item;
while(infile)
{
values[length] = item;
length++;
infile >> item;
}
}
#include <fstream>
#include <iostream>
#include "List.h"
using namespace std;
List::List()
{
length = 0;
}
bool List::IsFull()
{
return (length == MAX_ITEMS);
}
bool List::IsEmpty()
{
return (length == 0);
}
int List::Length()
{
return length;
}
void List:rintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values << " , " << endl;
}
void List::Store(ifstream& infile,ItemType item)
{
infile >> item;
while(infile)
{
values[length] = item;
length++;
infile >> item;
}
}
3 ..List.cpp In file included from List.cpp
9 ..List.h variable or field `Store' declared void
9 ..List.h expected `;' before '(' token
37 List.cpp no `void List::Store(std::ifstream&, ItemType)' member
function declared in class `List'
Please advise. I dont see any syntax errors.
array. On compilation I get the following errors in my implementation
file.I cannot figure out the problem.
//specification List.h
#include <fstream>
const int MAX_ITEMS = 20;
typedef int ItemType;
class List
{
public:
void Store(ifstream& infile,ItemType item);
// Pre: The list is not full
// Post: item is in the list
void PrintList();
// Post: If the list is not empty, the elements are
// printed on the screen; otherwise "The list
// is empty" is printed on the screen.
int Length();
// Post: return value is the number of items in the
list.
bool IsEmpty();
// Post: returns true if list empty;false otherwise
bool IsFull();
// Post: returns true if there is no more room in the
// list; false otherwise.
List();
// Constructor
// Post: Empty list is created.
private:
int length;
ItemType values[MAX_ITEMS];
};
//implementation List .cpp
#include <fstream>
#include <iostream>
#include "List.h"
using namespace std;
List::List()
{
length = 0;
}
bool List::IsFull()
{
return (length == MAX_ITEMS);
}
bool List::IsEmpty()
{
return (length == 0);
}
int List::Length()
{
return length;
}
void List:rintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values << " , " << endl;
}
void List::Store(ifstream& infile,ItemType item)
{
infile >> item;
while(infile)
{
values[length] = item;
length++;
infile >> item;
}
}
#include <fstream>
#include <iostream>
#include "List.h"
using namespace std;
List::List()
{
length = 0;
}
bool List::IsFull()
{
return (length == MAX_ITEMS);
}
bool List::IsEmpty()
{
return (length == 0);
}
int List::Length()
{
return length;
}
void List:rintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values << " , " << endl;
}
void List::Store(ifstream& infile,ItemType item)
{
infile >> item;
while(infile)
{
values[length] = item;
length++;
infile >> item;
}
}
#include <fstream>
#include <iostream>
#include "List.h"
using namespace std;
List::List()
{
length = 0;
}
bool List::IsFull()
{
return (length == MAX_ITEMS);
}
bool List::IsEmpty()
{
return (length == 0);
}
int List::Length()
{
return length;
}
void List:rintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values << " , " << endl;
}
void List::Store(ifstream& infile,ItemType item)
{
infile >> item;
while(infile)
{
values[length] = item;
length++;
infile >> item;
}
}
#include <fstream>
#include <iostream>
#include "List.h"
using namespace std;
List::List()
{
length = 0;
}
bool List::IsFull()
{
return (length == MAX_ITEMS);
}
bool List::IsEmpty()
{
return (length == 0);
}
int List::Length()
{
return length;
}
void List:rintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values << " , " << endl;
}
void List::Store(ifstream& infile,ItemType item)
{
infile >> item;
while(infile)
{
values[length] = item;
length++;
infile >> item;
}
}
#include <fstream>
#include <iostream>
#include "List.h"
using namespace std;
List::List()
{
length = 0;
}
bool List::IsFull()
{
return (length == MAX_ITEMS);
}
bool List::IsEmpty()
{
return (length == 0);
}
int List::Length()
{
return length;
}
void List:rintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values << " , " << endl;
}
void List::Store(ifstream& infile,ItemType item)
{
infile >> item;
while(infile)
{
values[length] = item;
length++;
infile >> item;
}
}
3 ..List.cpp In file included from List.cpp
9 ..List.h variable or field `Store' declared void
9 ..List.h expected `;' before '(' token
37 List.cpp no `void List::Store(std::ifstream&, ItemType)' member
function declared in class `List'
Please advise. I dont see any syntax errors.