HELP! infix to postfix using two stacks

Please...I am desparate. This program is due tomorrow

I have looked at this program and changed it so many times i don't know what to do next.
I am trying to import a file containing an Infix expression then changing to a postfix and placing that expression in another file.

Any changes will be noted and credited when I hand this thing in.

I have a precedence algorithm but I don't know how to implement.

Thanks,



#include
#include
#include

fstream infile(infix_exp.txt,ios::in); // instream
fstream fileout(postfix_exp.txt,ios::out);// outstream

class Stack
{
public:
stack(); // constructor
~stack(); // destructor
void push(char i); // push data
int pop(); // pop data
int top(); // data item at top of stack
bool isempty();
bool isfull();

void get_data(): ///gets file
void send_data(); // sends contents to file
int getsize();

private:
char operator[SIZE]; // initialize operator stack 10
char operand[SIZE]; //initialize operand array 10
int size; // current size(TOP)tack

};
stack::stack()
{
size =0; // initialize stack

}

stack::~stack() //deconstructor

{
if(size >0)
cout<<"The stack is not empty
";
size = 0;
}

void stack::get_data()//retrieve file containing infix expression
{

char InFix,TopItem;
char I: //THIS function is supposed to read in the elements and send them to ///////////the push

Stack stk();
infile>>InFix;
while(InFix != /n)

for (I=0; !/n ; I++)
stk.push(i);

{

int stack::getsize()

{
return size;
}

void stack::push(char i)

{
if(full() ==true)
{
cout<<"Stack is full
";
}
else
{

operator[size] =i; // put data on the stack and increment
size++;
}
}
int stack::pop()
{
if(empty() ==true)
{
cout<<"Stack is empty
";
return true;
}
else
{
size--; // remove top data by setting size of stack -1
return operator[size]; // return next value

}
}
int stack::top()
{
if(empty() ==true)
{
cout<<"Stack is Empty
";
return 0;
}
else
{
return operator[size-1]; // return value at top of stack
}
}
void send_data()
{
char i;
if(empty() ==true)
cout<<"Stack is Empty
";
else
{
for(i = size-1; i >=0; i--) // count down from top
fileout <<
}
}
bool stack::empty()
{
if(size==0)
return true;
else
return false;
}
bool stack::full()
{
if(size ==SIZE)
return true;
else
return false;
}
void main()
{
If (fileout.fail())

{
cerr<<couldnt open stackout.txt;
exit(-1)
{

Comments

  • Hi!!

    Give at least 3 days for doing this

    Shaunak

    : Please...I am desparate. This program is due tomorrow
    :
    : I have looked at this program and changed it so many times i don't know what to do next.
    : I am trying to import a file containing an Infix expression then changing to a postfix and placing that expression in another file.
    :
    : Any changes will be noted and credited when I hand this thing in.
    :
    : I have a precedence algorithm but I don't know how to implement.
    :
    : Thanks,
    :
    :
    :
    : #include
    : #include
    : #include
    :
    : fstream infile(infix_exp.txt,ios::in); // instream
    : fstream fileout(postfix_exp.txt,ios::out);// outstream
    :
    : class Stack
    : {
    : public:
    : stack(); // constructor
    : ~stack(); // destructor
    : void push(char i); // push data
    : int pop(); // pop data
    : int top(); // data item at top of stack
    : bool isempty();
    : bool isfull();
    :
    : void get_data(): ///gets file
    : void send_data(); // sends contents to file
    : int getsize();
    :
    : private:
    : char operator[SIZE]; // initialize operator stack 10
    : char operand[SIZE]; //initialize operand array 10
    : int size; // current size(TOP)tack
    :
    : };
    : stack::stack()
    : {
    : size =0; // initialize stack
    :
    : }
    :
    : stack::~stack() //deconstructor
    :
    : {
    : if(size >0)
    : cout<<"The stack is not empty
    ";
    : size = 0;
    : }
    :
    : void stack::get_data()//retrieve file containing infix expression
    : {
    :
    : char InFix,TopItem;
    : char I: //THIS function is supposed to read in the elements and send them to ///////////the push
    :
    : Stack stk();
    : infile>>InFix;
    : while(InFix != /n)
    :
    : for (I=0; !/n ; I++)
    : stk.push(i);
    :
    : {
    :
    : int stack::getsize()
    :
    : {
    : return size;
    : }
    :
    : void stack::push(char i)
    :
    : {
    : if(full() ==true)
    : {
    : cout<<"Stack is full
    ";
    : }
    : else
    : {
    :
    : operator[size] =i; // put data on the stack and increment
    : size++;
    : }
    : }
    : int stack::pop()
    : {
    : if(empty() ==true)
    : {
    : cout<<"Stack is empty
    ";
    : return true;
    : }
    : else
    : {
    : size--; // remove top data by setting size of stack -1
    : return operator[size]; // return next value
    :
    : }
    : }
    : int stack::top()
    : {
    : if(empty() ==true)
    : {
    : cout<<"Stack is Empty
    ";
    : return 0;
    : }
    : else
    : {
    : return operator[size-1]; // return value at top of stack
    : }
    : }
    : void send_data()
    : {
    : char i;
    : if(empty() ==true)
    : cout<<"Stack is Empty
    ";
    : else
    : {
    : for(i = size-1; i >=0; i--) // count down from top
    : fileout <<
    : }
    : }
    : bool stack::empty()
    : {
    : if(size==0)
    : return true;
    : else
    : return false;
    : }
    : bool stack::full()
    : {
    : if(size ==SIZE)
    : return true;
    : else
    : return false;
    : }
    : void main()
    : {
    : If (fileout.fail())
    :
    : {
    : cerr<<couldnt open stackout.txt;
    : exit(-1)
    : {
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion