I need help in solving an Array Based Expression Calculator

I am not understanding how I can print this array in the form that the question is asking. Please help.

Problem:

This problem considers specifying an expression using five arrays. Entries in array names store strings with a textual representation of the expression at the entry. Entries in array types specify whether the entry is a variable, a unary operation, or a binary operation. Entries in array operand1 specify the index of the first operand expression in case the entry was an operation. Entries in array operand2 specify the index of the second operand expression in case the entry was a binary operation. Array values holds the value of the expression once it is evaluated.Array representation of expressions.

Entries at index 10 in the arrays specify expression

This it the expression that should be displayed
!(-((x + z)/(y *(-x))) > (y/z)).



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  The following is my code so far:
#include <iostream>
#include <string>

using namespace std;

enum Type {VAR,BIN,UNI};

void printExpression ( Type a[], string b[],int c[],int d[]){

	for (int i=0; i<12; i++){

		if (c[i] && d[i]==-1){
			c[i]=NULL;
			d[i]=NULL;
		}
	
		cout<<a[i]<<" "<<b[i]<<""<<c[i]<<""<<d[i]<<endl;
	
	}
}

int main(){
	string names[12]={"x","y","z","-","*","+","/",">","!"};
	Type type[12]={VAR,VAR,VAR,UNI,BIN,BIN,BIN,UNI,BIN,BIN,UNI};
	int oper1[12]={-1,-1,-1,0,1,1,5,6,1,7,9};// index incase entry was operation
	int oper2[12]={-1,-1,-1,-1,3,2,4,-1,2,8,-1};//index of the second operand if binary 
	string values[12];
	

	printExpression(type, names, oper1,oper2);

	system ("pause");
	return 0;
}
Last edited on
Topic archived. No new replies allowed.