This is topic C++ Project is A.c.c.o.m.p.l.i.s.h.e.d Thank you Bokomon, KoM for your tutoring in forum Books, Films, Food and Culture at Hatrack River Forum.


To visit this topic, use this URL:
http://www.hatrack.com/ubb/main/ultimatebb.php?ubb=get_topic;f=2;t=045459

Posted by Blayne Bradley (Member # 8565) on :
 
man its awesome talking to fellow Hatrackers and for free as well!

C'mon people gimme phone numbers so I can call you all up. blayne.bradley@gmail.com

:NOTE: Thanks y'all for your help.

[ October 18, 2006, 04:23 PM: Message edited by: Blayne Bradley ]
 
Posted by MyrddinFyre (Member # 2576) on :
 
I miss teamspeak [Frown]
 
Posted by Blayne Bradley (Member # 8565) on :
 
I know a couple of 24/7 servers we can use for general hatracking.
 
Posted by Blayne Bradley (Member # 8565) on :
 
Okay had a very engaging conversation with Eros, talked about World of Warcraft, hatrack, about how Mr Card never comes anywhere near our homes, raisberries, everquest and about how im going to conquer the world as China in ym multiplayer game with King of Men. (>")>

Gimme more numbers people!
 
Posted by Blayne Bradley (Member # 8565) on :
 
I am very disappointed ATM I only got 2 #'s so far! C'mon!
 
Posted by Blayne Bradley (Member # 8565) on :
 
okay talked with Airman, talked about WoW< CIV4, EU2, Vikky, CHina, GWOT. I need mor enumbers!
 
Posted by airmanfour (Member # 6111) on :
 
It's true. Blayne is surprisingly erudite, and way more aware of the global situation (China specifically) than anyone I've talked to in a long time. I, for one, enjoyed myself. You eventually will too.
 
Posted by Dr Strangelove (Member # 8331) on :
 
Hey, Blayne, I was wondering ... does it cost me anything to recieve calls from this ... Skype? lol. Just wondering. It was cool talking to you for the short time I did though. After I talked to you I went back down to the conference and ironically got a comment on how I sound a lot older [Razz] .
 
Posted by erosomniac (Member # 6834) on :
 
Blayne is much, much different on the phone than he is on the web. Having spoken to him and going back over some of his posts, I think it's because he doesn't filter his typing at all, much the way we aren't afforded much opportunity to filter our spoken conversations.

I highly recommend speaking to him.

Now I'm eager to talk to more people. I imagine the contrast between online persona and real person is astounding, especially in a (relatively) controlled environment like Hatrack. AIM me for a phone number (the SN is in the hatrack profile).
 
Posted by Blayne Bradley (Member # 8565) on :
 
Skype within North America is completely free from Skype-Landline/Cellphone calls.'

If you were in say israel I only have 5 free minutes *unless* you ALSO have skype and then its kinda like a TS conversation.

www.google.com + skype

So that I can talk to Hatrackers beyond NA.
 
Posted by Little_Doctor (Member # 6635) on :
 
My skype name is GDA0612. I'm not that interesting to talk to however.
 
Posted by ElJay (Member # 6358) on :
 
Man, I can barely talk on the phone to people I do know in person. I'm glad y'all are having fun, but the very idea of trying to carry on a conversation with someone I've never met makes me want to crawl into bed and pull the covers over my head.

Looking at the time, I should be doing that anyway. Goodnight. [Smile]
 
Posted by erosomniac (Member # 6834) on :
 
But...but...

I love you, ElJay. [Frown]
 
Posted by rivka (Member # 4859) on :
 
quote:
Originally posted by Blayne Bradley:
Skype within North America is completely free from Skype-Landline/Cellphone calls.

This is called Skype-out, and is only free until the end of 2006.
 
Posted by ElJay (Member # 6358) on :
 
I'm not your type, eros. It could never be. [Razz]
 
Posted by Vasslia Cora (Member # 7981) on :
 
I would think about but I am just bad at talking on the phone no matter who I am talking to. I just have trouble keeping the conversation going, I talk much unless I am very comfortable.
 
Posted by erosomniac (Member # 6834) on :
 
quote:
Originally posted by ElJay:
I'm not your type, eros. It could never be. [Razz]

LIES! All lies...


.....lies...
 
Posted by ElJay (Member # 6358) on :
 
Um, so you were lying when you said you were attracted to slim asian girls? Defining slim as a size six at 5'6"? 'Cause believe me, I don't fit the criteria. [Big Grin]

And I'm not available, anyway.
 
Posted by erosomniac (Member # 6834) on :
 
quote:
Originally posted by ElJay:
Um, so you were lying when you said you were attracted to slim asian girls? Defining slim as a size six at 5'6"? 'Cause believe me, I don't fit the criteria. [Big Grin]

And I'm not available, anyway.

It's the interwebs, dude. If you say you're slim and asian, who am I to call you a liar? (Ignoring the repetition of the word "lies" in my last post for just a brief moment.)

But I see how it is.

<goes back to World of Warcraft>
 
Posted by ElJay (Member # 6358) on :
 
Sorry, man.
 
Posted by pH (Member # 1350) on :
 
eros, you said you loved ME! [Cry] I can't believe you'd do this to me!

-pH
 
Posted by erosomniac (Member # 6834) on :
 
I've got love for everybody!

[Group Hug]
 
Posted by ElJay (Member # 6358) on :
 
*tsk* It's alright, pH, I turned him down. No worries.
 
Posted by erosomniac (Member # 6834) on :
 
quote:
Originally posted by ElJay:
*tsk* It's alright, pH, I turned him down. No worries.

Oh, so she's supposed to take your leftovers?

pH, you're better than that.

...wait. This is me we're talking about, isn't it.
 
Posted by rivka (Member # 4859) on :
 
Yup. And you're right. pH is better than that.
 
Posted by erosomniac (Member # 6834) on :
 
quote:
Originally posted by rivka:
Yup. And you're right. pH is better than that.

As clearly evidenced by her lack of lovin' me. =\
 
Posted by pH (Member # 1350) on :
 
I love you...but all you do is hurt me. [Frown] Oh, cruel life.

-pH
 
Posted by Teshi (Member # 5024) on :
 
quote:
Man, I can barely talk on the phone to people I do know in person. I'm glad y'all are having fun, but the very idea of trying to carry on a conversation with someone I've never met makes me want to crawl into bed and pull the covers over my head.
You're kidding me, ElJay! You're so full of conversation!

My entire worldview is destroyed...
 
Posted by Kama (Member # 3022) on :
 
like i'm giving anyone on the internet my phone number...
 
Posted by ElJay (Member # 6358) on :
 
In person's different, Teshi. [Smile] I just don't like phones.
 
Posted by Blayne Bradley (Member # 8565) on :
 
=( I looked and saw 29 posts =) and I was like yay phone numbers! and then I find no new numbers =(

and your not giving it over the internet your emailing it big difference.
 
Posted by ElJay (Member # 6358) on :
 
Sorry, Blayne. erso was being funny. [Smile]
 
Posted by Blayne Bradley (Member # 8565) on :
 
I know you can make up for it by emailing me your phone number!! =)
 
Posted by Kama (Member # 3022) on :
 
e-mail is not internet? [Confused]
 
Posted by King of Men (Member # 6684) on :
 
Blayne, I got your call on Saturday, but I was in the shower. Six hours of nonstop, intense warfare, you know.
 
Posted by Little_Doctor (Member # 6635) on :
 
It proably would have been better to ask for Skype names Blayne. Most people do not want to have people they met on the internet calling their phones.
 
Posted by Blayne Bradley (Member # 8565) on :
 
*gasp* well email me skype names then, I dont remeber what mine was either Blayne Bradley or Sid Meier.

So ya Skype names so I can stalk the lot of ye' ^-^
 
Posted by Little_Doctor (Member # 6635) on :
 
Blayne:

I got my microphone to work, so next time you see me on skype, give me a call. I'm usually doing homework during the week, so it would be a welcome interruption.
 
Posted by Blayne Bradley (Member # 8565) on :
 
I talked wit KoM, we talked about details about the March Through Time Game (1066-1952) and discussing how he's hoping the Begian AI doesnt backstab him since it will take of europe combined to defeat my China. pfft, as if the yang gui zi can even hope to compare with the Middle Kingdom.

中國 !!!!

Anyways, we talked about what edits owuld be needed such as randomized tech teams for ahistoricalness. *points at whoever has a deeply engrained view of the world*

His accent was kinda Brittish-Scottish awesome combination kinda hard to understand if he talked too fast, although I think he had a harder time understanding me since I need to learn enunciating better.

And because of the inssitent annoyingness of my aprents I had to cut it early and switched to ICQ awhere he helped me with my C++ assignment.
 
Posted by MrSquicky (Member # 1802) on :
 
quote:
In person's different, Teshi. [Smile] I just don't like phones.
Word, sister.
 
Posted by Blayne Bradley (Member # 8565) on :
 
lol thanks to KoM I got rid of all the erros but now the program blows up when I try to run it, I think there now remains a logical inconsistency in my code I'll go on and see where it lies.

system("pause") ftw.
 
Posted by King of Men (Member # 6684) on :
 
It wasn't your enunciation, although I do sometimes have a hard time understanding people when I'm not used to their voice. But your microphone, or something, kept cutting out in the middle of a sentence and coming back a bit later, so your voice would sound a bit like this:

you ...ce wo... ... ... a bit ... this.

Which didn't make comprehension very easy, as you may guess. [Smile]
 
Posted by Blayne Bradley (Member # 8565) on :
 
Okau utilizing the pauses I have determined that everythign works as planned until my "popandtest" function.

Essentially it goes into a infitnit loop when it pops.

Essneitally how it works it will keep popping things off of the stack until it is empty, I had a cout and pasue essentially where I would know it entered the while loop wheere the popandtest function is called.

while !empty
{

cout STOP
system pause
call popandtest

}

essentially I had a million stops which overflowed my memory or something and MVS2k5 stopped the debugging and gave me a dirty error message.

So It could be a couple of things:

my syntax is completely right (no compiling errors) so its probly a logical inconsistency somewhere.

Either It is not pushing anything onto the stack, or empty isnt validating right or both, or popandtest isnt working right either.

Ill sort this out tomorrow, due thursday but im aiming for it to be done wensday so I can thouroghly style the bugger.

:EDIT:

here's my code

http://www.vassili.zambinidirect.com/asst3%20v3%20baseline.cpp
 
Posted by Blayne Bradley (Member # 8565) on :
 
I'm not sure now that I think of it if I even properly defined the stack as being empty at -1 so I'm gonna double check this and put pauses and couts in empty to make sur eits working right.
 
Posted by King of Men (Member # 6684) on :
 
Well, I don't know if any of these are your actual problem, but there are several logic flaws in your code. First, you are pushing things onto opstk, but empty is looking at opndstk. Incidentally, this is why you should not pshthngs tgthr lk ths. And I think I did advise you to make empty look at a local variable, rather than a global.

Second, your empty method (which incidentally does not need to be eleven (!) lines, you can do it in one - a common newbie mistake) is checking whether the 'top' index of your structs is -1. But that number is never initialised. In C++, this means it takes whatever random value is in the computer memory at the moment that space is initialised. Trust me, this is not the behaviour you want. At any rate, this is what most compilers do. Possibly your IDE will set uninitialised variables to a default value. However, firstly you should not rely on that behaviour, as it's not in the standard. Secondly, the default value is almost certainly 0 rather than -1, which means that stacks with no members have a top index of 0, which is bad in your logic.

Why don't you fix these issues and see what happens?
 
Posted by Blayne Bradley (Member # 8565) on :
 
sounds like an excellent plan as soon as I have sleep I'll fix them.
 
Posted by Bokonon (Member # 480) on :
 
I would also recommend NOT using -1. 0 is a much more natural choice, in this case. The more natural defaults you choose, the more readable the code, the easier for you to debug, the easier for the grader (or in the real world, a bug fixer/maintainer) to understand.

-Bok


EDIT: This is a personal style thing, so take it or leave it, but general coding convention is that ALL_CAPS means a constant, so it's best, IMO to actually only use all-caps for constant variables (not for struct names as you have done) and make sure those "constant" variables are actually constant (in C++ that would mean adding 'static' aand 'const' to the variable declaration, right? It's been a while since I worked in C++, so I might be off there).
 
Posted by Nighthawk (Member # 4176) on :
 
In Visual Studio, variables are sometimes initialized to zero IN DEBUG MODE. If you're running in release mode, the variables could be anything.

I see a few things in that code which could warrant style recommendations, but I don't think that's the purpose of this right now. But, if you want me to assault you with commentsand suggestions, I'd be more than happy to. [Smile]

One question I do have: you have a define "MAXSTACK", which I assume is the maximum size of the stack. But why do you define your stack at "MAXSTACK-1"?

Also, just a formality: your "push" call doesn't check for the bounds. Not that it's an issue in this controlled test, but get in to good practice of always checking the bounds of an array you're writing in to. I know of people that got nearly fired at a major development company because of that (because it led to a buffer overrun exploit).
 
Posted by Blayne Bradley (Member # 8565) on :
 
Ok fixed up code and it apears to push fine, popping isnt working right for some reason.

i have out put that after each push loos like this:

A
AB
ABC

pop isnt doing nuffin though

ABC
ABC
ABC

if I do cout oprstk.item[oprstk.top]

i will get

A
B
C
B
A

its pushin but it ain't popping right will post code as soon as I cna upload it.
 
Posted by Bokonon (Member # 480) on :
 
One possibility could be due to what's called "variable visibility" with your "popandtest()" function, and your declaration of the stack. It's been a long time, I remind you again, but what is your rationale for passing the stack to the "push()" function, but not the "popandtest()" function?

* grumbles, "one more example of why global variables are a pain in the neck..." *

-Bok
 
Posted by Blayne Bradley (Member # 8565) on :
 
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.
 
Posted by Blayne Bradley (Member # 8565) on :
 
k

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

here's my source file.

For some reaosn pop won't pop.
 
Posted by King of Men (Member # 6684) on :
 
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.
 
Posted by Blayne Bradley (Member # 8565) on :
 
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?
 
Posted by Blayne Bradley (Member # 8565) on :
 
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.
 
Posted by King of Men (Member # 6684) on :
 
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.
 
Posted by King of Men (Member # 6684) on :
 
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.
 
Posted by Blayne Bradley (Member # 8565) on :
 
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?
 
Posted by Blayne Bradley (Member # 8565) on :
 
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.
 
Posted by King of Men (Member # 6684) on :
 
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]
 
Posted by Blayne Bradley (Member # 8565) on :
 
Well obviously ^-^ I changed it from ' ' to 0 never know what little critters will show up.
 
Posted by Blayne Bradley (Member # 8565) on :
 
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]
 
Posted by Blayne Bradley (Member # 8565) on :
 
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.
 
Posted by King of Men (Member # 6684) on :
 
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.
 
Posted by Bokonon (Member # 480) on :
 
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
 
Posted by Blayne Bradley (Member # 8565) on :
 
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.
 
Posted by Blayne Bradley (Member # 8565) on :
 
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.
 
Posted by Blayne Bradley (Member # 8565) on :
 
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.
 
Posted by Blayne Bradley (Member # 8565) on :
 
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.
 
Posted by Bokonon (Member # 480) on :
 
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
 
Posted by Sean (Member # 689) on :
 
It's the Prcd( sym, opstk.top ) call in Convert. opstk.top is an int. Prcd wants an OPERATOR_STACK.
 
Posted by Blayne Bradley (Member # 8565) on :
 
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.
 
Posted by Bokonon (Member # 480) on :
 
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
 
Posted by King of Men (Member # 6684) on :
 
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.
 
Posted by Blayne Bradley (Member # 8565) on :
 
[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.
 
Posted by Bokonon (Member # 480) on :
 
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
 
Posted by Blayne Bradley (Member # 8565) on :
 
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 ]
 
Posted by King of Men (Member # 6684) on :
 
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?
 
Posted by MrSquicky (Member # 1802) on :
 
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.
 
Posted by King of Men (Member # 6684) on :
 
Oh, and in the fourth place, about your current thread title, 'stupid syntax errors' : Consider who put the syntax errors in there.
 
Posted by Blayne Bradley (Member # 8565) on :
 
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.
 
Posted by King of Men (Member # 6684) on :
 
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]
 
Posted by Blayne Bradley (Member # 8565) on :
 
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;
}


}


 
Posted by King of Men (Member # 6684) on :
 
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.
 
Posted by Blayne Bradley (Member # 8565) on :
 
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.
 
Posted by Blayne Bradley (Member # 8565) on :
 
and on another note my prof actually prefers less descriptive names. [Confused] I dont understand why.
 
Posted by Blayne Bradley (Member # 8565) on :
 
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.
 
Posted by Blayne Bradley (Member # 8565) on :
 
My teacher after I anncounced my completion of v5, congrauated me for my focus and dedication to the assignment. I feel so proud ^-^
 
Posted by Blayne Bradley (Member # 8565) on :
 
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.
 


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