473,378 Members | 1,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Classes,lists

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::PrintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values[i] << " , " << 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::PrintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values[i] << " , " << 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::PrintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values[i] << " , " << 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::PrintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values[i] << " , " << 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::PrintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values[i] << " , " << 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.

Mar 19 '07 #1
4 1275
zf*****@umd.umich.edu wrote:
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::PrintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values[i] << " , " << 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::PrintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values[i] << " , " << 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::PrintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values[i] << " , " << 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::PrintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values[i] << " , " << 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::PrintList()
{
if(length == 0)
cout << "The list is empty" << endl;
else
for(int i=0; i < MAX_ITEMS-1;i++)
cout << values[i] << " , " << 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.
Except that you triple posted List.cpp and a few style issues, your code
is valid. Are you sure this is the same code that showed you the compile
error at List.h::9?

Fei
Mar 19 '07 #2
3 ..List.cpp In file included from List.cpp
9 ..List.h variable or field `Store' declared void
Except that you triple posted List.cpp and a few style issues, your code
is valid. Are you sure this is the same code that showed you the compile
error at List.h::9?

Fei- Hide quoted text -

- Show quoted text -
I apologise for the triple paste. Yes this is exactly the same code
and their is one more file, the driver.

#include <fstream>
#include <iostream>
#include "List.h"

using namespace std;

ifstream infile;
ItemType item;

int main()
{
infile.open("int.dat");
Store(infile,item);
PrintList();

system("PAUSE");
return 0;
}

I am lost.

Mar 19 '07 #3
JE
On Mar 19, 11:00 am, zfar...@umd.umich.edu wrote:
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);
<snip>
Please advise. I dont see any syntax errors.
std::ifstream

Mar 19 '07 #4

A couple of style tips:
>
List::List()
{
length = 0;
}
Better is:
List::List() : length(0) {}
void List::Store(ifstream& infile,ItemType item)
Better is:
void List::Store(istream& infile,ItemType item)
Then you can store to other types of streams besides files.

Mar 20 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Hal Vaughan | last post by:
I think a lot of this is definately a question of personal programming style, but I'm new to Java and would like to hear a few opinions. I'm writing a control panel for an application that runs...
145
by: David MacQuigg | last post by:
Playing with Prothon today, I am fascinated by the idea of eliminating classes in Python. I'm trying to figure out what fundamental benefit there is to having classes. Is all this complexity...
9
by: Pierre Barbier de Reuille | last post by:
Ok, I first want to stress that I looked through the newsgroups archives (on Google) for an answer to my question, but I didn't find it. It's about the interface of the set classes as defined in...
12
by: Ron Garret | last post by:
Why doesn't this work? >>> from weakref import ref >>> class C(str): pass .... >>> ref(C()) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: cannot create weak...
5
by: Andrew Ward | last post by:
Hi All, Sorry if this is off topic, but I could not seem to find a suitable OO Design newsgroup. If there is one feel free to let me know. Here is a simplification of a general design problem I...
3
by: Claudio Grondi | last post by:
Trying to understand the outcome of the recent thread (called later reference thread): "Speed quirk: redundant line gives six-fold speedup" I have put following piece of Python code together:...
5
by: Anthony Evans | last post by:
Greetings I'm using VC++.NET to create a class library. The class library contains managed classes that wrap legacy unmanaged classes by the same name. I use regasm to register the DLL for...
7
by: alternativa | last post by:
Hello, I have a few questions concerning classes. 1) Why some people use default constructos, i.e constructors with no parameters? To me it doesn't make any sense, is there something I should...
16
by: chameleon | last post by:
I have 2 classes with exactly the same members (all static except dtor/ctor). Classes have different implementantion in only one static member function and first class has one more member...
2
by: sndive | last post by:
q#1: in C I want to check if a given PyObject is a xml.dom.minidom.Node (or a derivative). how do i extract a PyTypeObject for such a class? issue #2 I'm in a situation when i don't really...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.