计算器 [英] Calculator

查看:82
本文介绍了计算器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我想制作一个计算器,我可以用一个单词给出输入。 for

例如:(15 * 3)/(2 + 3)

我认为我最常读的是一个字符串,然后在不同的部分分享

进行计算。但我现在不知道如何开始。可以有人

帮助我。


先谢谢。

Hello,

I wanna make a calculator where i can give the input in one word. for
example : (15*3) / (2+3)
I think i most read this in as a string and then share it in different parts
to do the calculation. But i don''t now how tho start with it. Can somebody
help me.

Thanks in advanced.

推荐答案



Flipke写道:

Flipke wrote:
你好,

我想制作一个计算器,我可以用一个单词给出输入。对于
例如:(15 * 3)/(2 + 3)
我想我最多在一个字符串中读到这个,然后在
不同的部分分享它来进行计算。但我现在不知道如何开始。可以
有人帮助我。

先谢谢。
Hello,

I wanna make a calculator where i can give the input in one word. for
example : (15*3) / (2+3)
I think i most read this in as a string and then share it in different parts to do the calculation. But i don''t now how tho start with it. Can somebody help me.

Thanks in advanced.




你可能会问你的助教/教授一些提示

开始做作业。


你也可以google forrecursive descent parser,这是一个

解决此类问题的标准方法。 K& R还有一个

计算器,但是他们的示例程序使用RPN




-David



You might ask your teaching assistant/professor for some hints on how
to get started on your homework.

You could also google for "recursive descent parser", that being a
standard approach for this sort of problem. K&R also has an
calculator, though
their example program uses RPN.

-David




" Flipke" <是********** @ hotmail.com>在留言中写道

新闻:ld ******************** @ scarlet.biz ...

"Flipke" <am**********@hotmail.com> wrote in message
news:ld********************@scarlet.biz...
你好,

我想制作一个计算器,我可以用一个单词给出输入。对于
例如:(15 * 3)/(2 + 3)
我想我最多在一个字符串中读到这个,然后在不同的
部分分享它来做计算。


是的,'分而治之'是编程中的一个好习惯。

但我现在不知道如何开始。


首先,如你所说,阅读输入。下一步

将其解析为有意义的段(例如(15 * 3),

15等)。你需要跟踪括号

才能实现

算术运算的正确优先级。递归方法是解决此类问题的最常见方法。


有人可以帮助我。
Hello,

I wanna make a calculator where i can give the input in one word. for
example : (15*3) / (2+3)
I think i most read this in as a string and then share it in different
parts
to do the calculation.
Yes, ''divide and conquer'' is a good practice in programming.
But i don''t now how tho start with it.
First, as you said, read the input. The next step
is to parse it into meaningful segments (e.g. (15 * 3),
15, etc.). You''ll need to keep track of the parentheses
in order to implement the correct precedence of the
arithmetic operations. A recursive approach is the most
common approach to this kind of problem.

Can somebody
help me.



是的,但我们需要一些东西来帮助你。没人会为你写b
。显示您最佳尝试的代码,并且

询问具体问题。


-Mike



Yes, but we need something to help you with. Nobody will
write it for you. Show the code of your best attempt, and
ask specific questions.

-Mike


Flipke写道:

你好,

我想做一个计算器,我可以用一个单词给出输入。对于
例如:(15 * 3)/(2 + 3)
我想我最多以字符串形式阅读它,然后在不同的部分分享它来进行计算。但我现在不知道如何开始。有人可以帮助我。

先谢谢。

Hello,

I wanna make a calculator where i can give the input in one word. for
example : (15*3) / (2+3)
I think i most read this in as a string and then share it in different parts
to do the calculation. But i don''t now how tho start with it. Can somebody
help me.

Thanks in advanced.




看看Kruse,数据结构与程序设计 ;。他展示了如何开发一个简单的公式评估器。 IIRC他使用的是解析树而不是递归下降的b $ b。他原来的版本使用的是Pascal,但是那个很接近

足以让C翻译。或者你可能会看一个更新的版本 -

我认为他已经停止了不可避免的战斗,现在使用C或C ++作为他的

插图语言。

-

Julian V. Noble

物理荣誉教授
jv*@lessspamformother.virginia.edu

^^^^^^^^^^^^^^^^^^
http://galileo.phys.virginia.edu/~jvn/


因为从来没有哲学家能耐心地忍受

牙痛。


- Wm。莎士比亚,很多阿多无所事事。法案诉Sc。 1.



Have a look at Kruse, "Data Structures and Program Design". He shows how
to develop a simple formula evaluator. IIRC he uses a parse tree rather
than recursive descent. His original version used Pascal, but that''s close
enough to C to translate. Or you might look at a more recent edition--
I think he has ceased fighting the inevitable and now uses C or C++ as his
illustration language.
--
Julian V. Noble
Professor Emeritus of Physics
jv*@lessspamformother.virginia.edu
^^^^^^^^^^^^^^^^^^
http://galileo.phys.virginia.edu/~jvn/

"For there was never yet philosopher that could endure the
toothache patiently."

-- Wm. Shakespeare, Much Ado about Nothing. Act v. Sc. 1.


这篇关于计算器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆