[程式]Arithmetic

8 views
Skip to first unread message

cpyi

unread,
Apr 29, 2013, 4:37:05 PM4/29/13
to code_fellow...@googlegroups.com
This is a program for arithmetic, that is, for the four operation +,-,*,/ and bracket (,). Obey the rule that bracket has top priority, then * and /, then + and -. Even most people learn arithmetic at elementary school, it has no straightforward method to calculate it using programming. I used the c++ knowledge I just learned from Savitch's book, such as template, namespace, to construct three classes : list(an array-like data structure, but no random access), stack(FILO data structure), and the four_operation. They are hierarchy structure, although you can use c++ STL library to implement stack, make one from scratch is also lots of fun. Another difficult part is the algorithm to implement arithmetic operation. But I don't want to go into to detail here. You can search it on the internet or ask me for more information.
Sample Code(Developed on unix-like using Makefile, but easy to understand and port):
Reply all
Reply to author
Forward
0 new messages