90 likes | 246 Vues
In The Name of God. Calculator. Elnaz Barshan Fatemeh Torabi Asr Fahimeh Jamshidian Tehrani Maryam Sharifnia Leyla Kamkar.
E N D
In The Name of God Calculator Elnaz Barshan Fatemeh Torabi Asr Fahimeh Jamshidian Tehrani Maryam Sharifnia Leyla Kamkar
Capabilities:.calculation of ordinary expressions>>> 20*(3-1)+50 .saving given functions>>> def average(x,y): (x+y)/2 .saving values of constants>>> min=0.1 .offering mathematical important functions and constants>>> a=2+sin(pi) – (E)^2
Classes: .Tree : a tool for saving a suitable form of an expression .Operation: containing important static methods .Macro: a tool for saving a suitable form of a function
Treating a right input:>>>2+3*(50-9)+sin(2*pi) >>>min=(E)^0.1 >>>deff(x,y) : (x+y)/2 >>>m=3*f(2,4)+71 >>>f(3+m,5)>>>defg(a) : a+3 >>>garbages=g(f(5,1))
Treating expressions:postfix=Operation.operate(expression)result=Operation.evaluate(postfix) Treating variables(=): dic.add(variable,resultOfexpression) Treating defs: macros.add(new Macro(def))
Expression calculation:Operation.operate(String) makes the tree of expression reads the tree and makes the postfix Operation.evaluate(String[]) gets the postfix and returns the value evaluate works by the power of inheritance >>>
Interface Opt{ double eval();}class Mul implements Opt { Opt a; Opt b; Mul(Opt a, Opt b) { this.a=a; this.b=b; } public double eval(){ return a.eval()*b.eval(); }}...class Mem implements Opt{ double x; Mem(String x){ Double d=new Double(x); this.x=d.doubleValue(); } public double eval(){ return x; }}
Logical wrong and right input:>>>def f (x,y):g(x)+1>>>def f (x,y):g(5)+1>>>def sin(x):x+2*(x^2)>>>def sin(x,y):x+2*(y^2)>>>def f (1,7):1+7>>>def f (x,y):x+y>>>z=f (x,y)>>>z=f (2,5)>>>Pi=3.1>>>myPi=3.1>>>f (x,y)=x+y>>>def f (x,y):x+y
This document and the executable file of the program are available on:http://pasargad.cse.shirazu.ac.ir/~torabi Tempbuffer/presentations/calculator …The end