FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » C++ Project is A.c.c.o.m.p.l.i.s.h.e.d Thank you Bokomon, KoM for your tutoring (Page 2)

  This topic comprises 2 pages: 1  2   
Author Topic: C++ Project is A.c.c.o.m.p.l.i.s.h.e.d Thank you Bokomon, KoM for your tutoring
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
the code posted somewhere above is out of date allow me to update it asap on my laptop and dont have my password for smartftp stored.
IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
k

http://www.vassili.zambinidirect.com/asst3%20v3.cpp

here's my source file.

For some reaosn pop won't pop.

IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Ah, I see the problem. Your stack is popping quite correctly. However, cout doesn't know that it's dealing with a stack; it thinks you are passing it a quite ordinary char pointer. It therefore prints it out until it reaches a null character. Since you don't actually delete your items, just make the top pointer point elsewhere, it looks as though they're all there, even though they aren't for stack-operations purposes. You can fix this in at least two ways : Write your own stack-printer, which only prints out those elements that are below the top index; or else set deleted (popped) elements to zero again.

I see you fixed your local-global confusion; good. But for the love of god, can you rewrite that empty function? One line, I tell you; one.

Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
But it works [Frown] Fine, you win. How do I write it as one line again?

Next how do I set popped elements back to zero?

IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
would it be instead of:

opr = oprstk.item[oprstk.top];

make it

oprstk.item[oprstk.top] = ' ';

??

I think it wokrs my output is:

A
AB
ABC
AB
A

Not sure if this is working I think it is.

IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Well, tell you what, take it step by step. Here's your code:

code:
bool empty( OPERATOR_STACK& oprstk )
{

bool RESULT;

if (oprstk.top == -1)
{
RESULT = true;
return RESULT;
}
else
{
RESULT = false;
return RESULT;
}
}

Just to start with, why have you got two separate return statements in here? Didn't your mother teach you that single exit points are good? Also, let me mention that you have come down on the wrong side of the Brace Wars, and your soul will therefore burn in hell for all eternity. One True Brace Style for the win!

As for setting things to zero... dude, if at this point you need me to tell you how to assign a value to a variable, I suggest you just drop the course.

Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Wupsie, cross-post. Yes, what you have works. I was actually thinking

oprstk.item[oprstk.top] = 0;

to take advantage of the behaviour of null-terminated strings, but as long as it prints out the right thing, who cares? However, you should have this line in addition to, as my supervisor is fond of saying, the line

opr = oprstk.item[oprstk.top];

since you still want to return what you just popped, presumably.

Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Too stubburn to drop it but I believe I was simply confused by what you meant and I think I did what you suggested am I correct in amking top = to a blank?

Also brace styles? you mean the

if () {


etc etc

}

style?

IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Alrighty then, version 3 is done then, next vesion 4 evaluating the polish notation expression and reutn a number.

Afk for a bit nature calls.

IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Making top equal to a blank works, in that it prints out only un-popped letters. I believe making top equal to zero is better, because it makes cout behave the same as your stack logic; that is, it sees 'string ends' in its own internal logic where you've got 'stack ends' in your internal logic. But such consistency, it's true, is more a matter of taste. You're only using cout for testing, so as long as it prints out non-confusing results, you're fine.

Never mind about the brace styles, I was joking. [Smile]

Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Well obviously ^-^ I changed it from ' ' to 0 never know what little critters will show up.
IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Ack I spent 4-5 hours working in emacs today writing a awk script and look what happens! When im coding in C++ whenever I go to save I press CTRL x, CTRL s rather then just control s, grrrr. [Mad]
IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Okay V4 is to evaluate a Postfix expression past to the function for its numurical value.

I was given a sheet of pascal pseudo code and I got rid of the majority of the bugs me thinks:

http://www.vassili.zambinidirect.com/asst3%20v4.cpp

Basically the remaining compiling errors are:

Expon funciton is undefined, safely ignorable atm because I'm not sure how to calculate exponants so I'll save it for later.

'ord' apparnetly in pascal I can derive the value of the number wihtit, well I dont know how it works in C++.

In our assignment there are letters A-G that make up each Infix/Postfix expression. eg: A+B*C or AB+C*

A-G will be given preset numbers exmaple:

symval[NMAX] = { -1, 5, 4, 2, 10, 3, 7 };

I think I'm a little fuzzy on this part of the instructions since they're only implied.

So how would I say within the code that 'A' = 5? I don't think we ar eot go manually A= 5, B=1 etc

And I'm not sure how an array would work.

Would it be symval = { 'A' = 5, 'B' = 3, ... }; ?

And then have the code do value = symval[count]...


But I dont thinkthat will work.

if ( sym is an operand )

value = ord( symb ) - ord('0')

I think we're supposed to do something similar to this but I'm not sure what. I'll have to ask tomorrow.

Next I get '=' cannot convert 'void' to 'char' on the opnd1/opnd2 - Popopr( sym, oprndstk); lines

is it because Popopr is a void? What should I do?

:EDIT:

I made empty a bit neater but I didn't have time yet to make it one line of code.

IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Ok, now it would be two lines if not for your horrible brace style. You don't need braces anyway for little one-liners like this, unless they're required by your professor or something. You could get

code:
  if (oprstk.top == -1) return true;
return false;

which is a considerable improvement, to be sure. At least you got rid of the useless intermediate variable. Next I suggest you get rid of the if statement and just return the bool directly.

Incidentally, indenting by a whole tab like that is going to come back and bite you in the ass. Set the indentation to two spaces.

About the 'ord' function, if ti does what I think it does the code you posted has a bug, so I'll let you think a bit about what it is supposed to be doing.

Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Bokonon
Member
Member # 480

 - posted      Profile for Bokonon           Edit/Delete Post 
quote:
Originally posted by King of Men:
Also, let me mention that you have come down on the wrong side of the Brace Wars, and your soul will therefore burn in hell for all eternity. One True Brace Style for the win!

[Smile] Blayne don't let KoM lead you astray! Your brace style is beautiful (and certainly the most easy to logically follow!). Let the compiler do what it does best: strip whitespace!! [Big Grin]

--
But yeah, your empty function can be reduced to one line... And when possible, always place your returns in an area of a function that will always be called. Return in conditional blocks are often a warning that things are being over-engineered. In fact, if you follow this one suggestion alone, you'll shrink your empty method by one line!

-Bok

Posts: 7021 | Registered: Nov 1999  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Okays! http://www.vassili.zambinidirect.com/asst3%20v4.cpp


Version 4 is: C.o.m.p.l.e.t.e...d


^-^

I had a slight problem where despite if I isolated the Eval function and passed a single Postfix expression and returned the accurate value ("AB+C-") in this exmaple 2, would output 3 for EVERY postfix expression depsite my stopwatch cout showing the correct anwser being return from my Operations function.

I brilliantly determiend that Pfval being in a for loop was being on each loop replaced by the proceeding value and thus all 3's.

Then I put pfval as an array an put in a counter and now it works flawlessly ^-^.

Now onwards ot version 5.

IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
EEEEIEEE!


Grrr...

V5 is the same as v3, basically do 3 pushes, then do a while that pops until empty and then out put whats in stack after each pop/push.

Annoyingness: Hery high

A whole lot of cpy and pasty and variable changing. Grr.

IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Okay version 5 is done, now onwards! The final version versian 6is all thats left all I needs to do is get a full blown conversation function working that will cnfix to Postfix.

I am going in, wish me luck.

IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Alright Quadruple posts.

Question:

'Prcd' cannot convert parameter 2 from 'int' to 'OPERATOR_STACK'

http://www.vassili.zambinidirect.com/asst3%20v6.cpp

=( I keep getting these errors and I keep fixing them and I keep forgetting how I fix them.

IP: Logged | Report this post to a Moderator
Bokonon
Member
Member # 480

 - posted      Profile for Bokonon           Edit/Delete Post 
I can't help with the immediate issue, but I recommend you don't pass-by-reference a variable, assign it a value and then also return it. If you want to return a value, I recommend you pass everything by-value. If you want to modify a data structure, pass-by-reference is required, of course, but then I would either make it a void function, or return an int error code (with zero signifying success by default). passing a reference to a variable 3 or 4 functions deep can be an exercise in debugging masochism, IMO.

Remember the KISS principle. The first rule in development.

-Bok

Posts: 7021 | Registered: Nov 1999  |  IP: Logged | Report this post to a Moderator
Sean
Member
Member # 689

 - posted      Profile for Sean   Email Sean         Edit/Delete Post 
It's the Prcd( sym, opstk.top ) call in Convert. opstk.top is an int. Prcd wants an OPERATOR_STACK.
Posts: 148 | Registered: Feb 2000  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Okay I fixed it by modifying Prcd to not accept OPERATOR_STACK as an arguement, now its simply Prcd( sym) which works cuz' OPERATOR_STACK is a global and I can call opstk inside the functions.

Not to figure out why my variables keep becomming undefined mid debug.

Okay, its because Pfx = Pfx + Sym doesn't acually work Time to do strcpy ftw.

IP: Logged | Report this post to a Moderator
Bokonon
Member
Member # 480

 - posted      Profile for Bokonon           Edit/Delete Post 
quote:
Originally posted by Blayne Bradley:
Okay I fixed it by modifying Prcd to not accept OPERATOR_STACK as an arguement, now its simply Prcd( sym) which works cuz' OPERATOR_STACK is a global and I can call opstk inside the functions.

This is evil. Like "get booted from a job" bad. It may work for a class assignment but DO NOT let this become a habit.

-Bok

Posts: 7021 | Registered: Nov 1999  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Not only that, it is actually by far the more complicated solution, measured in amount of typing. If you do evil hacks, they should at least save you some work! The obvious thing to do is just to pass the stack instead of its 'top' member. I mean, duh. That's like 4 backspaces, instead of all this changing of interfaces and kludging of globals.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
[Smile]

MY latest problem is ha I didn't quit understand at first the logic behind the given flowchart for detmrining the preedneces of operators so I did it only with brakets in mind so I ended up with postfix stirngs like ABC+- not AB+C-

Now I have to code in this mother of all case statements.

IP: Logged | Report this post to a Moderator
Bokonon
Member
Member # 480

 - posted      Profile for Bokonon           Edit/Delete Post 
Stop. Think. Design.

When you say, "mother of all case statements", that should immediately make you think if there isn't a Better Way(tm). In fact, I would strongly look into using recursion for some of the processing of the statements... I believe that is a more "classical" way to solve this type of problem (even if it is a bit rough on the stack [system stack, not the one you've implemented]).

Have you learned about recursion yet?

-Bok

Posts: 7021 | Registered: Nov 1999  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
I think so, ya I think so, problem is I already have the case statements my teacher typed for aomwonw else and I really don't think there's a better way that is currently within my programming skills and time slot.

code:
bool Prcd( char top, char symbol )
{

switch( top )
{

switch( sym )
{
case '+': return true;
break;
case '*': return false;
break;
case '-': return true;
break;
case '/': return false;
break;
case '$': return false;
break;
case '(': return false;
break;
case ')': return true;
break;
}
break;

case '*':
switch( sym )
{
case '+': return true;
break;
case '*': return true;
break;
case '-': return true;
break;
case '/': return true;
break;
case '$': return false;
break;
case '(': return false;
break;
case ')': return true;
break;
}
break;

case '-':
switch( sym )
{
case '+': return true;
break;
case '*': return false;
break;
case '-': return true;
break;
case '/': return false;
break;
case '$': return false;
break;
case '(': return false;
break;
case ')': return true;
break;
}
break;

case '/':
switch( sym )
{
case '+': return true;
break;
case '*': return true;
break;
case '-': return true;
break;
case '/': return true;
break;
case '$': return false;
break;
case '(': return false;
break;
case ')': return true;
break;
}
break;

case '$':
switch( sym )
{
case '+': return true;
break;
case '*': return true;
break;
case '-': return true;
break;
case '/': return true;
break;
case '$': return true;
break;
case '(': return false;
break;
case ')': return true;
break;
}
break;

case '(': return false;
break;
}


}

Gah! Now it says indirection not allowed. Why me of all people getting these errors...

:EDIT: Figrued it out had opstk.item[opstk.item] not a good thing.

[ October 18, 2006, 04:24 PM: Message edited by: Blayne Bradley ]

IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Ok, in the first place, if you're going to have returns in every case, you don't need breaks. In the second place, your posted code has a bug in it. In the third place, could you for the love of Papa Janitor use [ code] blocks?
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
MrSquicky
Member
Member # 1802

 - posted      Profile for MrSquicky   Email MrSquicky         Edit/Delete Post 
Oh sweet Jebus.

Incidentally, I think you people are going way overboard in helping Blayne with his homework. And you're not going him any favors either. A huge part of learning to program is figuring out how to debug on your own.

Posts: 10177 | Registered: Apr 2001  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Oh, and in the fourth place, about your current thread title, 'stupid syntax errors' : Consider who put the syntax errors in there.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
OKays, Version 6 complted. Thank KoM for your help.

MrSquicky; I'm 90% sure Ive only asked for help in regards to syntax errors, I am pretty sure that that I have indeed learned a great deal and my skill in managing the debugger has increased drastically.

If you look at the entirety of my code and look at my requests you'lll see that I'e only asked for help in only a small minority of my code.

:edit: previous code segments turned to code bocks /edit.

IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Well, it's a code block, which is good, but it's still got a bug in it, so I hope that's not your final code. [Smile]
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Nopers: Final Code is Here:

http://www.vassili.zambinidirect.com/asst3%20v6.cpp

code:
// asst3v1.cpp    fall 2006 ALG  starts from straray.cpp ch.7
// array of strings
#include <iostream>
#include <iomanip> //for setw function to format output
#include "string.h"
#include <math.h>

//standard namespace
using namespace std;

const int LMAX = 50; //maximum number of infix strings in array
const int NMAX = 30; //maximum size of each infix string
const int LSIZE = 5; //number of actual infix strings in array
const int MAXSTACK = 100;

//array of infix strings
char infix[LMAX][NMAX] = { "A+B-C",
"(A+B)*(C-D)",
"A$B*C-D+E/F/(G+H)",
"((A+B)*C-(D-E))$(F+G)",
"A-B/(C*D$E)" };

char postfix[NMAX][LMAX] = { };

float symval[8] = { 3, 1, 2, 5, 2, 4, -1, 3 };


struct OPERATOR_STACK
{
int top;
char item[MAXSTACK];
};

struct OPERAND_STACK
{
int top;
float item[MAXSTACK];
};

OPERATOR_STACK opstk; //declare variable opstk of OPERATOR_STACK
OPERAND_STACK opndstk; //declare variable opndstk of OPERATOR_STACK

char pfx[NMAX];
char ifx[NMAX];

int infixindex;

float pfval[NMAX] = {};

bool empty( OPERATOR_STACK& );
bool empty_oprnd( OPERAND_STACK& );
bool Oprnd( char );
bool Prcd( char, char );

void Pop( char&, OPERATOR_STACK& );
void Convert( char in[NMAX], char out[NMAX] );
void push( char, OPERATOR_STACK& );
void pushopr( float, OPERAND_STACK& );

float Popopr( float&, OPERAND_STACK& );
float Oper( char symb, float, float );
float Expon( float, float );
float Eval( char in[NMAX], OPERAND_STACK& opndstk );

int main()
{

opndstk.top = -1;
opstk.top = -1;

cout << endl << endl;

printf("%-25s%-25s%-25s\n", "Infix Expression", "Postfix Expression", "Final Value");
for ( int j=0; j < LSIZE; j++)
{
strcpy_s(ifx, infix[j]);
infixindex=j;
Convert( ifx, pfx );
strcpy_s( postfix[j], pfx);
pfval[j] = Eval( postfix[j], opndstk );

}




/****************************************************************************
PRINT OUT THE INFIX EXPRESSIONS
****************************************************************************/


cout << endl << endl;

for(int j=0; j<LSIZE; j++) //display name strings & corresponding weights
{
printf("%-25s%-25s%-25f\n", infix[j], postfix[j], pfval[j] );
}

cout << endl << endl;

system("pause");

return 0;

}


/****************************************************************************
CONVERT INFIX EXPRESSION TO POSTFIX NOTATION
****************************************************************************/
void Convert( char Infix[NMAX], char Postfix[NMAX] )
{
OPERATOR_STACK opstk;
opstk.top = -1;

char Pfx[LMAX] = {""};

char sym;
char topsym;


int i;
int j;


i=0;

for ( j = 0; j < ( strlen(Infix) ); j++ )
{
sym = Infix[j];

if ( Oprnd( sym ) )
{
Pfx[i] = sym;
i++;

}
else
{
while ( ( opstk.top != -1 ) && ( Prcd( opstk.item[opstk.top], sym ) ) )
{
Pop( topsym, opstk );
//topsym = opstk.top;
Pfx[i] = topsym;
i++;

}

if ( sym == ')' && opstk.item[opstk.top] == '(' )
{
Pop( sym, opstk );
}
else
{
push( sym, opstk );
}

}



}

while ( !empty( opstk ) )
{
Pop( topsym, opstk );
//topsym = opstk.top;
Pfx[i] = topsym;
i++;

}

strcpy( Postfix, Pfx );

}



/****************************************************************************
EVALUATE THE POSTFIX EXPRESSION
****************************************************************************/
float Eval( char expr[NMAX], OPERAND_STACK& oprndstk )
{


float opnd1;
float opnd2;
char symb;
float sym;

int position;
float value;
float eval;

opndstk.top = 0;
position = 0;
symb = expr[position];



do
{

if ( Oprnd( symb ) ) //function call 'is it an operand?'
{
value = symval[ symb - 'A'];
pushopr( value, oprndstk );
}
else // it is an 'operator'
{
opnd2 = Popopr( sym, oprndstk);
opnd1 = Popopr( sym, oprndstk);
value = Oper( symb, opnd1, opnd2 );
pushopr( value, oprndstk );
}

if ( position < MAXSTACK )
{

position++;
symb = expr[position];
}
else
{
symb = ' ';
}

}
while ( symb != 0 );

eval = Popopr( sym, oprndstk );
return eval;

}

/*********************************************
Is the stack empty?
*********************************************/
bool empty( OPERATOR_STACK& oprstk )
{

if (oprstk.top == -1) return true;
return false;

}

/*********************************************
Is the stack empty?
*********************************************/
bool empty_oprnd( OPERAND_STACK& operand_stk )
{

if (operand_stk.top == -1) return true;
return false;

}

/*********************************************
Push a Operator onto the stack
**********************************************/
void push( char opr, OPERATOR_STACK& oprstk )
{

oprstk.top++;
oprstk.item[oprstk.top]=opr;


}

/*********************************************
Push a Operand onto the stack
**********************************************/
void pushopr( float oprnd, OPERAND_STACK& oprndstk )
{

oprndstk.top++;
oprndstk.item[oprndstk.top]=oprnd;


}

/*********************************************
Operations
*********************************************/
float Oper( char symb, float op1, float op2 )
{

float anwser;


switch( symb )
{

case '+':
anwser = op1 + op2;

break;
case '*':
anwser = op1 * op2;

break;
case '-':
anwser = op1 - op2;

break;
case '/':
anwser = op1 / op2;

break;
case '$':
anwser = Expon( op1, op2);

break;
}

return anwser;

}

/*********************************************
Is it an Operand?
*********************************************/
bool Oprnd( char symb )
{
if (isupper(symb)) return true;
return false;
}

/*********************************************
Pop the top Operator from the stack
*********************************************/
void Pop( char& sym, OPERATOR_STACK& oprstk )
{

sym = oprstk.item[oprstk.top];
oprstk.item[oprstk.top] = 0;
oprstk.top--;
}

/*********************************************
Pop the top Operand from the stack
*********************************************/
float Popopr( float& sym, OPERAND_STACK& oprndstk )
{

sym = oprndstk.item[oprndstk.top];
oprndstk.item[oprndstk.top] = 0;
oprndstk.top--;

return sym;

}

/*********************************************
Exponate Calculations
*********************************************/
float Expon( float operator_1, float operator_2 )
{
float val;

//makes the op_1 to the op_2 = val
val = pow( operator_1, operator_2 );

return val;

}

/*********************************************
Precendence Function
*********************************************/
bool Prcd( char top, char symbol )
{

switch( top )
{

switch( symbol )
{
case '+': return true;
break;
case '*': return false;
break;
case '-': return true;
break;
case '/': return false;
break;
case '$': return false;
break;
case '(': return false;
break;
case ')': return true;
break;
}
break;

case '*':
switch( symbol )
{
case '+': return true;
break;
case '*': return true;
break;
case '-': return true;
break;
case '/': return true;
break;
case '$': return false;
break;
case '(': return false;
break;
case ')': return true;
break;
}
break;

case '-':
switch( symbol )
{
case '+': return true;
break;
case '*': return false;
break;
case '-': return true;
break;
case '/': return false;
break;
case '$': return false;
break;
case '(': return false;
break;
case ')': return true;
break;
}
break;

case '/':
switch( symbol )
{
case '+': return true;
break;
case '*': return true;
break;
case '-': return true;
break;
case '/': return true;
break;
case '$': return false;
break;
case '(': return false;
break;
case ')': return true;
break;
}
break;

case '$':
switch( symbol )
{
case '+': return true;
break;
case '*': return true;
break;
case '-': return true;
break;
case '/': return true;
break;
case '$': return true;
break;
case '(': return false;
break;
case ')': return true;
break;
}
break;

case '(': return false;
break;
}


}


IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Get rid of the breaks in your precedence function (and why are you calling it Prcd, anyway? Didn't your prof tell you to use descriptive names? Dropping out all the vowels is not descriptive.) Then take a closer look at your outer switch statement.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
well I ran it with the Infix array we were given and it works perfectly but yes I have 24 hours reamining now to fix up my code to get it to look nicer ^-^ so ya breaks wiill now = gone soonish.
IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
and on another note my prof actually prefers less descriptive names. [Confused] I dont understand why.
IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Actually on closer inspection it DIDNT work perfectly ^-^ I had a '+' inbetween E and an F on one and an extra '/' on the end.

Debuggging told me it was always returning true so I checked the case.

Turns out I was missing a '+' case.

Thanks KoM.

Got rid of all the breaks and now I'm commenting my code.

IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
My teacher after I anncounced my completion of v5, congrauated me for my focus and dedication to the assignment. I feel so proud ^-^
IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
OKay new versions posted: Versions 2-6


http://www.vassili.zambinidirect.com/asst3%20v2.cpp
http://www.vassili.zambinidirect.com/asst3%20v3.cpp
http://www.vassili.zambinidirect.com/asst3%20v4.cpp
http://www.vassili.zambinidirect.com/asst3%20v5.cpp
http://www.vassili.zambinidirect.com/asst3%20v6.cpp


Version 6 fully coded and styled.

No bugs whatsoever.

I'm emailing in soft copy to my teacher now.

IP: Logged | Report this post to a Moderator
  This topic comprises 2 pages: 1  2   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2