0

it gives me that there's an error in declaring st in the print_reverse function cout<<st<<endl;
i've declared the st in the private..

#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include<cstdlib>
#include <fstream>
using std::ifstream;
using std::ofstream;
#include"ItemType.h"
using namespace std;
class stack
{
private:
        static const int MAX_ITEMS=10;  
        int st[MAX_ITEMS];
        int top;
public:
	
	stack();
	void push(int);
	int pop();
	bool isempty();
	bool isfull();
	void print();
	void print_reverse(int);
};

stack::stack(){top=-1;}
void stack::push(int v){st[++top]=v;}
int stack::pop(){return st[top--];}
bool stack::isempty(){return (top==-1);}
bool stack::isfull(){return top==MAX_ITEMS-1;}
void stack::print()
{
while(!isempty())
cout<<pop()<<endl;
}

void print_reverse(int i)
{
	
   if(i<MAX_ITEMS && i >= 0)
   {
         cout<<st[i]<<endl;
         print_reverse(--i);
   }
}


int main()
{  
stack x;
int data;
ItemType item;

	ifstream instream; 
	ofstream outstream;
      
	instream.open("input.txt");
	outstream.open("output.txt");
	if(instream.fail()){
    	cout<<"Error opening file\n";
	exit(1);
	}

	while ( !instream.eof() )
	{	
		if (x.isfull())
			break;
		instream>> data;	
		item.Initialize(data);
		 int temp = item.getvalue();
		x.push(temp); 
		x.print();
		
	}
	instream.close();

	cout<<"--------\n";
	x.print_reverse(MAX_ITEMS-1);
	cin.get();
	outstream.close();
    return 0;
}
0

1> Please use 'code tags', do you see the 'Help with code Tags' on the right hand corner of your code? click that and read.
2>print_reverse definition should be preceded by scope resolution operator.
3>I don't see anywhere where you are writing the output to outstream?

please make these changes and then post the code with the 'code tags'

0

Yep, i know..You declare print_reverse as a global function too..
Should be..

void stack::print_reverse(int i)
0

im sorry it slipped my mind that i should be doing the stack using a linked list..
could u help me?
here is what i have done again..but there are too many errors

#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include<cstdlib>
#include <fstream>
using std::ifstream;
using std::ofstream;
#include"ItemType.h"
using namespace std;

class stack
{
private:
        NodeType* topPtr;
public:
	
	stack();
	void push(ItemType);
	int pop();
	bool isempty();
	bool isfull();
	void print();
	void print_reverse(stack);
	void reverse(Node*)
	void push(stack, int);
};

stack::stack()
{
	topPtr = NULL;
}
void stack::push(int ItemType newItem)
{
	NodeType*  location;
	location = new  NodeType;
	location->info = newItem;
	location->next = topPtr;
	topPtr = location;
}
int stack::pop()
{
	NodeType* tempPtr;
	tempPtr = topPtr;
	topPtr = topPtr ->next;
	delete tempPtr;
}
bool stack::isempty()
{
	return (topPtr == NULL);
}
bool stack::isfull()
{
	NodeType* location;
	location = new NodeType;
	if(location != null)
	{
		delete location;
		return false;
	}
	else
		return true;
}
void stack::print()
{
while(!isempty())
cout<<pop()<<endl;
}

void stack::print_reverse(stack st)
{
	if (ptr! =(node*) NULL)
		print_reverse(ptr->next)
		print ptr->info;
}

void stack::reverse(Node* head,){ 
Node* current = head; 
stack stk; 

while(current->next() != NULL){ 
stk.push(current);
current->next(); 
} 

head->next = NULL;
assign null to its next 
head = current;
the first node now 

while(current->next() != NULL) { 
Node* prevNode = stk.pop();
current->addLink(prevNode);
prevnode 
current = current->next();
} 
} 

int main()
{  
stack x;
int data;
ItemType item;

	ifstream instream; 
	ofstream outstream;
      
	instream.open("input.txt");
	outstream.open("output.txt");
	if(instream.fail()){
    	cout<<"Error opening file\n";
	exit(1);
	}

	while ( !instream.eof() )
	{	
		if (isfull())
			break;
		instream>> data;	
		item.Initialize(data);
		 int temp = item.getvalue();
		push(temp); 
		print();
		
	}
	instream.close();

	cout<<"--------\n";
	print_reverse(MAX_ITEMS);
	cin.get();
	outstream.close();
    return 0;
}

this is the ItemType.h

/* Information provided by the user */
const int MAX_ITEMS = 50;
struct NodeType{
	ItemType  info;
	NodeType* next;
};
class ItemType {
public:
	Stack();
	bool IsEmpty() const;
	bool IsFull() const;
	void Push(ItemType item);
	void Pop();
	ItemType Top() const;

private:
	NodeType* topPtr;

};
0

There are so many errors, I don't even know where to begin...

Let's take your headerfile for example:

struct NodeType
{
	ItemType  info;  //class Itemtype not defined yet.
	NodeType* next;
};

class ItemType {
public:
	Stack(); //What??! Are you trying to call the constructor from here?
	bool IsEmpty() const; //implementation missing
	bool IsFull() const; //implementation missing
	void Push(ItemType item); //implementation missing
	void Pop(); //implementation missing
	ItemType Top() const; //implementation missing
private:
	NodeType* topPtr;
};

Your other file is a mayhem of missing semicolons and curly-brackets.

To be honest: It looks like you asked for code from a few people (and got it) then wacked it together in one big mysterious program. Do you even have a clue what you're doing?

I suggest you take a step back and look at what you have on paper. Also for the next assignment: Stay awake in class and learn your books. If you're learning stacks and recursion you should really know that this is a syntax error:

head->next = NULL;
assign null to its next  // <--- What
head = current;
the first node now  // <--- What

[edit]
Oh, and I really recommend you to read this

0

im sorry i didnt recognize i did such a thing..i realized afterwards that i should have done it using a linked list..
mmmm why should we define the
bool IsEmpty() const;
bool IsFull() const;
void Push(ItemType item);
void Pop(); in the header file?
could u plz show me where my other mistakes are?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.