A Calculator For Advanced Requirements
Catalogs
Overall introduction
In terms of this blog,
1.Create a calculator with a visual interface.
2.Record necessary work content and process.
Link to the finished project code:
https://github.com/Aeolian12/-
Program Requirements:
1.Basic requirement: Implement addition, subtraction, multiplication, division, and clear functions.
2.Advanced requirement: Implement functionality for exponentiation, trigonometric functions, and more.
The Link Your Class | https://bbs.csdn.net/forums/ssynkqtd-04 |
---|---|
The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/617332156 |
The Aim of This Assignment | an advanced calculator |
MU STU ID and FZU STU ID | MU:21124639 FZU:832101208 |
I. PSP form for this work
Personal Software Process Stages | Estimated Time(minutes) | Actual Time(minutes) |
---|---|---|
Planning | 20 | 20 |
• Estimate | 20 | 20 |
Development | 150 | 150 |
• Analysis | 10 | 10 |
• Design Spec | 20 | 20 |
• Design Review | 20 | 20 |
• Coding Standard | 20 | 20 |
• Design | 20 | 20 |
• Coding | 30 | 30 |
• Code Review | 10 | 10 |
• Test | 20 | 20 |
Reporting | 40 | 40 |
• Test Repor | 10 | 10 |
• Size Measurement | 10 | 10 |
• Postmortem & Process Improvement Plan | 20 | 20 |
Sum | 210 | 210 |
II. Problem-solving ideas for designation
This is a simple task, so there should be many ways to solve this problem, the way I have chosen is through python language as the main programming method. The benefits are as follows:
- python language is an in-class program, so after systematic learning, it is more skillful in the programming stage.
- python is a higher level language, so there are simple and efficient libraries that can be used to solve this problem, which makes it easier to solve and less prone to bugs.
- Because not all users can run the .py file, so the .py file will be converted to an .exe file. Make it easy for users to use.
III. Practical implementation and process
IV. Code description
// number button
btn7=tkinter.Button(root,text='7',command= lambda : pressnum('7'))
btn7.place(x=10,y=50,width=50,height=50)
btn8=tkinter.Button(root,text='8',command= lambda : pressnum('8'))
btn8.place(x=60,y=50,width=50,height=50)
btn9=tkinter.Button(root,text='9',command= lambda : pressnum('9'))
btn9.place(x=110,y=50,width=50,height=50)
//operator button
btnadd=tkinter.Button(root,text='+',command= lambda : presscal('+','+'))
btnadd.place(x=160,y=50,width=50,height=100)
btnsub=tkinter.Button(root,text='-',command= lambda : presscal('-','-'))
btnsub.place(x=210,y=50,width=50,height=100)
btnmul=tkinter.Button(root,text='x',command= lambda : presscal('*','x'))
btnmul.place(x=160,y=150,width=50,height=100)
btndiv=tkinter.Button(root,text='÷',command= lambda : presscal('/','÷'))
btndiv.place(x=210,y=150,width=50,height=100)
//advanced Operators button
btnsin=tkinter.Button(root,text='sin',command= lambda : presshigh('sin','sin'))
btnsin.place(x=160,y=250,width=50,height=50)
btncos=tkinter.Button(root,text='cos',command= lambda : presshigh('cos','cos'))
btncos.place(x=210,y=250,width=50,height=50)
//function
def pressnum(no):
global numberornot
global highornot
highornot = 0
numberornot=1
oldno=num.get()
if oldno.isdigit():
if oldno=='0':
num.set(no)
else:
num.set(oldno+no)
else:
num.set(no)
#high
def presshigh(sym1,sym2):
global numberornot
global steplist
if numberornot==1:
steplist.append(num.get())
steplist.append(sym1)
num.set(sym2)
print(steplist)
#pi
def presspi():
global numberornot
global highornot
if numberornot == 1:
numberornot=0
num.set('pi')
steplist.append(str(math.pi))
#运算
def presscal(sym1,sym2):
global numberornot
global steplist
if numberornot==1 :
numberornot = 0
steplist.append(num.get())
steplist.append(sym1)
num.set(sym2)
print(steplist)
#等于
def pressequ():
global numberornot
global highornot
highornot = 0
if numberornot==1:
numberornot = 0
global steplist
steplist.append(num.get())
for i in range(len(steplist)):
if steplist[i] == 'pi':
steplist[i] = ''
for b in range(len(steplist)):
if steplist[b] == 'sin':
steplist[b + 1] = str(math.sin(float(steplist[b + 1])))
steplist[b] = ''
elif steplist[b] == 'cos':
steplist[b + 1] = str(math.cos(float(steplist[b + 1])))
steplist[b] = ''
elif steplist[b] == 'exp':
steplist[b + 1] = str(math.exp(float(steplist[b + 1])))
steplist[b] = ''
elif steplist[b] == 'ln':
steplist[b + 1] = str(math.log(float(steplist[b + 1])))
steplist[b] = ''
print(steplist)
result = eval(''.join(steplist))
num.set(result)
steplist = []
#归零
def presszero():
global steplist
global highornot
highornot = 0
num.set(0)
steplist=[]
#撤回
def presswith():
global steplist
global numberornot
global highornot
highornot = 0
num.set(num.get()[:-1])
if numberornot==0:
steplist.pop()
if steplist[-1].isdigit():
numberornot=1
V. Display
VI. Summary
This software is an efficient calculator tool, developed using the Python programming language. It provides a user-friendly interface, enabling users to perform various mathematical operations such as addition, subtraction, multiplication, and division with ease. Not only limited to basic calculations, but this software is also capable of handling complex computations involving logarithmic, trigonometric, and exponential functions. Key features include a clean and intuitive design, high computation speed, and accurate results. With its focus on usability, this calculator software is suitable for both educational and professional uses, catering to a wide range of users from students to engineers. This software represents a perfect blend of Python’s power and simplicity, providing a reliable tool for all your calculation needs.