For this assignment due 3/4/2013, I have to write a program to read in and evaluate a post fixed expression. I also have to print out the expression read in followed by the results of the evaluated expression (while handling the add, subtract, and multiply operators) and handle multi digit numbers. The expressions I'm using are in the textle is PostFix.txt, which I've attached to this article so you can look at it The thing is that I can't use stacks in my code. Instead I have to use functions to act the same way as stack member functions. I also have to use characters and not strings.
These are the errors I get when I build it:
-Lines 15 and 18 have too many arguments to functions int top & bool full.
-Lines 57, 59, and 104 say "error: at this point in file".
Again, it is due 3/4/2013. You don't have to advice me on displaying the results; I'll handle that. But first, can you help fix this program?
Here's my code for the assignment:
//Autthor: Connor Wells
//Date: 2/27/2013
//Theme: Post Fix Expression Evaluation
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MAX 50
using namespace std;
int push(int v);
int top();
int pop(int d);
bool empty();
bool full();
int TOS = 50;
char input[MAX];
int STACK[MAX];
int number1;
int number2;
int main()
{
int i = 0;
int output;
ifstream inputFile;
ofstream outputFile;
inputFile.open("PostFix.txt");
outputFile.open("Evaluation");
cout << "Here are the postfix expressions.\n\n";
outputFile << "Here are the postfix expressions.\n\n";
for (int y = 0; y < MAX ; y++)
{
inputFile >> input[y];
cout << input[y] << "\n";
outputFile << input[y] << "\n";
}
while (input[i] != '\n')
{
if (isdigit(input[i]))
{
int x;
x = input[i] - '0';
push(x);
}
else if((input[i] == '*') || (input[i] == '/') || (input[i] == '-') || (input[i] == '+'))
{
number2 = top(i);
pop(i);
number1 = top(i);
pop(i);
if (input[i] == '+')
{
output = number1 + number2;
}
if (input[i] == '-')
{
output = number1 - number2;
}
if (input[i] == '*')
{
output = number1 * number2;
}
if (input[i] == '/')
{
output = number1 / number2;
}
push(i);
}
i++;
}
cout << "\nHere are the evaluated results.\n\n";
outputFile << "Here are the evaluated results.\n\n";
for (int y = 0; y < MAX ; y++)
{
cout << output << "\n";
outputFile << output << "\n";
}
inputFile.close();
outputFile.close();
return 0;
}
int top()
{
if(TOS != MAX)
{
return STACK[TOS];
}
}
int push(int v)
{
if(TOS != full(v))
{
TOS = TOS - 1;
STACK[TOS] = v;
return TOS;
}
else
{
number1 = STACK[++TOS];
}
}
int pop(int d)
{
if(TOS != empty())
{
return -999;
}
else
{
return STACK[TOS--];
}
}
bool empty()
{
if(TOS == MAX)
{
return TOS == MAX;
}
}
bool full()
{
if(TOS == 0)
{
return TOS == 0;
}
}