Okay then let's go little steps by little steps.
First try to write something that can handle only:
And then let's worry about putting things together.
Let
a = 0; b = 1; c =1; d = 0; e = 0; |
like you had said earlier.
We have to store these values, you could use a map, two arrays, or a structure and probably more ways.
Since you want to use arrays lets use a structure.
Define a structure say 'values', with two members.
first member: char data type which holds key value. i,e the character a,b,c,d or e
second member: bool or int (either can be used) data type which holds the value.
Now make an array of this structure with the size of how many ever letters there are. 5 letters in our case. And enter the two structure member values for all elements. You should have an array of 5 'values' structure that have filled data members.
Now for parsing.
We have
.
By using stringstream, string::find, manual for-loops etc. you can separate the expression into words.
Let's store the words into an array like you intended to.
So we now have an array of strings with 9 elements.
Each element is either a letter a, b, c, d, e or an operation.
But a, b, c, d and e are not useful to use. What is useful is their values.
Write a loop that will iterate over each of the array with 9 elements such that,
under each element, if the element is not an operator, there will be another for-loop to compare it with all the elements of the first data members of the array of structures we had made.
If a match is found, then change the element of the 9 elements where a match was found into 0 or 1 according to the 2nd data member.
Now you have
0 or 1 or 1 or 0 or 0
Write another loop to search for operators.
Once you've found an 'or', evaluate the element before it and after it, and pop the two evaluated elements. Replace the operator with what the elements evaluated to, i.e either 1 or 0.
You can use vector::erase to pop elements. Try to write code until here. You know the logic so if you're able to write until here then you might be able to complete it.