| | |
having problems to complete implement a simple calculator program in c
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2005
Posts: 1
Reputation:
Solved Threads: 0
I really need some help to finish my assignment which is due 2005/05/23
I have the other header and c files but i need to do some more work ........if u can help me i would be very greatful plzzzzzzzzz
this is the code that follows for exptree.c
note:
make_exptree() creates an expression tree from a postfix expression, consisting of nodes defined in exptree.h. To See this file for details on the implementation of each treenode structure plz ask
Thank you ......and looking forward for your help.
I have the other header and c files but i need to do some more work ........if u can help me i would be very greatful plzzzzzzzzz
this is the code that follows for exptree.c
C Syntax (Toggle Plain Text)
#include "exptree.h" void make_exptree( treenodeptr *root, char *postfix ){ char **arr_exp; int argn, i; expstack mystack; expop myop; treenode *newnode; char space = ' '; mystack = make_stack(100); arr_exp = exptok(postfix, &argn); for(i=0; i<argn; i++){ newnode = (treenodeptr) malloc( sizeof(treenode) ); newnode->left = NULL; newnode->right = NULL; switch( arr_exp[i][0] ){ case '/': case '*': case '+': case '-': newnode->operator = arr_exp[i][0]; pop(mystack, &myop); newnode->right = (treenodeptr) myop.op; pop(mystack, &myop); newnode->left = (treenodeptr) myop.op; myop.op = (void *)newnode; push(mystack, myop); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': sscanf(arr_exp[i],"%d", &(newnode->operand)); myop.op = (void *)newnode; push(mystack, myop); break; default: break; } } pop(mystack, &myop); *root = (treenodeptr) myop.op; destroy_stack(mystack); destroy_exp(arr_exp, argn); } /*-----------------------------------------------------------*/ void destroy_exptree( treenodeptr * root){ if (*root == NULL) return; destroy_exptree( &((*root)->left) ); destroy_exptree( &((*root)->right) ); free( *root ); *root = NULL; } /*-----------------------------------------------------------*/ int eval_exptree( treenodeptr exp_root){ [COLOR=DarkRed]this is the prat that i am having problem with[/COLOR] --> /* implement me */ }
note:
make_exptree() creates an expression tree from a postfix expression, consisting of nodes defined in exptree.h. To See this file for details on the implementation of each treenode structure plz ask
Thank you ......and looking forward for your help.
Last edited by Catweazle; May 20th, 2005 at 9:27 pm.
•
•
Join Date: Mar 2004
Posts: 3,826
Reputation:
Solved Threads: 144
Hi jean and welcome to Daniweb.
I've removed the email contact from your post, as it is forum policy to encourage all discussion of a topic to occur in the thread, rather than via email.
I've also moved this topic to the appropriate forum section for you. Good luck with your assignment
I've removed the email contact from your post, as it is forum policy to encourage all discussion of a topic to occur in the thread, rather than via email.
I've also moved this topic to the appropriate forum section for you. Good luck with your assignment
Think recursively. Operands return the value, binary operators perform themselves on the left and right value:
It's also easy to turn the four function calculator into something more powerful. You can easily modify the algorithm to handle unary operators and add error checking to verify that the syntax of the expression is correct.
C Syntax (Toggle Plain Text)
if (is_operand()) return value; T a = recurse(left); T b = recurse(right); switch (operator()) { case '+': return a + b; case '-': return a - b; case '*': return a * b; case '/': return a / b; }
![]() |
Similar Threads
- install and run tomcat3 and implement a simple jsp page (JSP)
- calculator program (Java)
- need help for c++ calculator (C++)
- Wierd error messages with calculator program (C++)
- simple calculator help (Java)
- need help with calculator program in C (C)
- writing a simple cat program (C)
Other Threads in the C Forum
- Previous Thread: C help calculate grand total
- Next Thread: WM_SIZING Probelm in my application
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory drawing dynamic fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop interest kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix problem probleminc program programming pyramidusingturboccodes radix recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming spoonfeeding stack standard string strings structures student systemcall testautomation turboc unix user variable voidmain() wab windows.h






