Python implements a simple arithmetic calculator, python
I. Algorithms
1. The main idea of the algorithm is to convert an Infix expression into a Postfix expression, and then use the stack's simple data structure, returns the result of an expression.
2. The detailed description of how to convert a common expression to a suffix expression and how to process a suffix expression and calculate the result is not described here.
Ii. Simple
calculation of the symbolExp_sum = ADD_SUB (exp)#Call Add_sub to calculate addition and subtraction returnExp_sum#float #返回计算结果defMain (exp): Exp= Exp.replace (' ',"')#Delete spaces in a string whileTrue:ret= Re.search ('\([^()]+\)', exp)#Match parentheses ifRet:#if it matches.Inner_bracket = Ret.group ()#use Group () to extract the bracketed content that matches tores = str (cal (Inner_bracket))#call Cal () to calculate the contents of parentheses and convert the returned result
(i)elifFIND_[INDEX-1] = ="-": #If two negative numbers are subtracted, they are added or subtracted ifTag = =True:res+=float (i)Else: Res-=float (i)Else: #case where I is empty when processing without parentheses ifI! ="": Res=float (i)returnResif __name__=='__main__': whileTrue:calc_input= Input ("Please enter a calculation formula \ n default to:%s:"%a). Strip ()Try: ifLen (calc_input) = =0:calc_input=a calc_input= R'%s'%calc_input#do special treatment t
@__create_say_zsq ()def __init__ (Self,num):Self.__result = num@__check_num_zsq@__create_say_zsq ("plus")def Jia (self,n):Self.__result + = nreturn self@__check_num_zsq@__create_say_zsq ("Minus")Def Jian (self,n):Self.__result-= nreturn self@__check_num_zsq@__create_say_zsq ("multiply")def Chen (self,n):Self.__result *= Nreturn selfDef show (self):Self.__say ("The result of the calculation is:%d"%self.__result)Print ("The result of the calculation is:%d"%self.__result)return selfdef clear (self)
The code is as follows:Import Java.awt.*;import javax.swing.*;p ublic class Gridframe extends JFrame {//define string array, assign a value to the display text of the button string str[] = {"MC", "MR", "MS", "m+", "←", "C", "%", "π", "7", "8", "9", "/", "4", "5", "6", "*", "1", "2", "3", "-", "0", ".", "=", "+"};p UBL IC Gridframe () {//define panel and set to Grid layout, 4 rows 4 columns, component horizontal, vertical spacing is 7JPanel pan = new JPanel ();p an.setlayout (New GridLayout (6, 4
I used to look at PHP when I wanted to do this, but there has been no time, this time finally took a sneak into the code more than the amount of project.First of all, the document structure, all in one folder is good, my example is the following.Start by entering the index.php file.Doing a couple of things.1. The number of passes that can be obtained by $get_[the "action" method and the $_request ["action"] method is rect, triangle or circle.2. The two classes of form.class.php and result.class.
This is my copy of a calculator, feel the process is relatively simple, so share.
1. Create a new file, find a material to put in a grain of wood
2. New layer, fill a black radial gradient
3. Draw a rectangle with rounded corners. The final painting here has a shape filler tool to draw, the right amount of graphics size adjustment is not easy to distort, but also suitable for
Various sizes. Easy to modify. Fill style specific
(atom_exp,res)Else: returnExpdefadd_sub (exp): RET= Re.findall ("[+-]?\d+ (?: \. \d+)?", exp)#Take out the numbers and symbols in front of the numbers FindAll returns a list to find all itemsExp_sum =0 forIinchRet:exp_sum= Exp_sum + float (i)#The string is taken out. returnExp_sumdefCAL (exp): Exp=MUL_DIV (exp) Exp=Format (exp) exp_sum=add_sub (exp)returnExp_sumdefMain (exp): Exp= Exp.replace (" ","") whileTrue:ret= Re.search ("\([^()]+\)", exp)ifRet:inner_bracket=Ret.group ()
This JSP page is designed to implement the ability to submit and receive data on the same page .There are a lot of shortcomings in this small program, I hope you will criticize.The implementation results are as follows:How to implement a simple calculator with JSP (c)
1. Environment Construction Link: http://www.jianshu.com/p/094928ac0b732. qt Create CanvasNow you need to complete the adder, two numbers A and B are added, and the numbers A and B are entered by digital. Drag the element to complete the interface, such as. On the left there is a simple addition input and output display box, click on the calculation button below to start the calculation, to the right there is an output historical calculation of the page. You can see the name of each dragged elem
After Baidu, see the same shoes hint to modify the \phpstudy\apache2\conf\ in the httpd.conf file, the code is as follows
Copy Code code as follows:
ServerAdmin webmaster@163.com
DocumentRoot "D:\www"
ServerName ymywz.com
Options Indexes FollowSymLinks
AllowOverride All
Order Allow,deny
Allow from all
Note: As a result of the code conflict problem, please change the above double title number to a single title number
When you restart Apache after adding the
I. Overview of issues
Using C language to implement a simple calculator, can be used to achieve the function of subtraction
noun Explanation:
function pointer: A pointer that is used to point to a function
Array of function pointers: an array containing multiple function pointers
callback function: A function, if the parameter has a function pointer, then this function is the callback function two, problem analysis
This problem can be implemented wit
This article illustrates a method of implementing a simple calculator based on JSP. Share to everyone for your reference. The implementation methods are as follows:
index.jsp
Copy Code code as follows:
String path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
%>
Result.jsp for displaying results
Copy Code code as follows:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.