I'm writing my own calculator program and it's going to kick ass.
I've defined a class called 'cterm' in order to make assigning values and signs and operations to each term in the input problem a little easier. Like this:
1 2 3 4 5
|
class cterm{
protected:
double dvalue;
char indicator[3];
int nlocation;
|
dvalue is the numerical value of the term. nlocation is the location that the term appears in the input string (102+4*9.2;the cterm instance that has 102 would have an nlocation of 0, and the instance of 9.2 would have an nlocation of 2).
The indicator array is what I'm going to use to store all non-numerical characters in the input array (+,-,*,/,(,)), and the indicator array of any cterm instance will have every operator/sign that is immediately to the left of the number.
(102+4*9.2;the cterm instance for 9.2 would have an indicator array of '*__',4 would have '+__')
The problem i'm having occurs when I declare an array of cterm objects at the beginning of my program.
//main.cpp
1 2 3 4 5 6 7 8 9
|
cterm TERMS[MAX];
int counter=0;
cterm* termpnt=&(TERMS[0]);
while(counter<=MAX){
termpnt=&(TERMS[counter]);
termpnt->setOP(input);
termpnt->setTerm(input);
counter++;
}
|
Only the 1st line of code here is important, but i posted the rest for context.
MAX is defined as 10. I have explicitly defined the default constructor (which is called 10 times at the line 'cterm TERMS[MAX];') as...
1 2 3 4 5 6 7 8 9
|
cterm():
dvalue(0),nlocation(-1){
int counter=0;
while(counter<=2){
indicator[counter]='a';
counter++;
}
std::cout << indicator << std::endl;
}
|
Here, the while loop is simply present in order to default unassigned elements to 'a,' which, to me, seems preferable to having them contain junk values.
tldr;
Why does the std::cout << indicator << std::endl; line print this...
http://imageshack.us/photo/my-images/829/cppforumprob.jpg/
Thanks for reading. It's a long one I know, and I apologize if my description wasn't sufficient. Let me know if it is lacking and I'll explain in more detail.