简单计算器程序VC#2008(控制台应用程序) [英] Simple calculator program VC# 2008(Console Application)

查看:278
本文介绍了简单计算器程序VC#2008(控制台应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我是Roger.我对.NET不太了解.请问有人可以帮助我在VC#2008(控制台应用程序)中编写一个简单的计算器程序.这非常紧急.我正在阅读与.Net相关的内容但我无法在编程中实现.

规格

要求
在本文中,您将准备一个将用作简单计算器的C#程序.
计算器将从命令行运行,并且仅适用于整数和
以下算术运算符+-*/%. %运算符是模数运算符,不是
百分比.
例如,如果将C#程序编译为calc.exe,则下面的示例演示了它如何
可以工作
calc 3 + 5-7
1
在命令行中,参数是重复的序列,格式为
数字运算符
并以
结尾 编号
按下Enter键将使程序评估参数并打印结果.在
这种情况1.
该程序必须遵循通常的算术定律,即
1.必须在+和–运算符之前对*/和%运算符进行求值.
2.必须从左到右评估操作员.
例如,使用规则1
2 + 4 * 3 – 6
成为
2 + 12 – 6
导致
8
如果我们不使用规则1,则2 + 4 * 3 – 6将变成6 * 3 – 6,然后
18 – 6,最后是12.这是不正确的结果.

如果我们不使用规则2,则以下内容将说明如何出错
4 * b</b> 5%2
从左到右,我们首先评估*,这将表达式减小为20%2
变为0.如果我们首先评估%,则表达式将减少为4 * 1
变为1.这是错误的结果.请记住,我们使用的是整数数学
在进行计算时,因此进行除法运算时会得到整数结果.例如
calc 20/3
6
另外请注意,我们可以使用一元+和–运算符.例如
calc -5/+2
-2
您的程序还必须检查以确保命令行参数正确.如果不是
您的程序必须生成适当的错误消息,然后终止.


这是我的要求的规范.请任何人帮我给出正确的编码.



谢谢你

Roger.

Hi
This is Roger.I dont have pretty good idea on .NET.Could any one please help me in coding a simple calculator program in VC# 2008(Console application).This is very much urgent.I am reading the stuff related to .Net but I am not able to implement that in the programming.

Specification

Requirement
In this you are to prepare a C# program that will act as a simple calculator. The
calculator will be run from the command line and will only work with integer numbers and
the following arithmetic operators + - * / %. The % operator is the modulus operator, not
the percentage.
For example, if the C# program is compiled to calc.exe, the following demonstrates how it
will work
calc 3 + 5 - 7
1
In the command line, the arguments are a repeated sequence in the form
number operator
and ending in a
number
Hitting the enter key will cause the program to evaluate the arguments and print the result. In
this case 1.
The program must follow the usual laws of arithmetic which says
1. The * / and % operators must all be evaluated before the + and – operators.
2. Operators must be evaluated from left to right.
For example, using Rule 1
2 + 4 * 3 – 6
becomes
2 + 12 – 6
which results in
8
If we did not use Rule 1 then 2 + 4 * 3 – 6 would become 6 * 3 – 6 and then
18 – 6 and finally 12. This is an incorrect result.

If we do not use Rule 2 then the following illustrates how it can go wrong
4 *<b></b> 5 % 2
Going from left to right we evaluate the * first, which reduces the expression to 20 % 2
which becomes 0. If we evaluated the % first then the expression would reduce to 4 * 1
which becomes 1. This is an incorrect result. Remember, we are using integer mathematics
when doing our calculations, so we get integer results when doing division. For example
calc 20 / 3
6
Also note that we can use the unary + and – operators. For example
calc -5 / +2
-2
Your program must also check to make sure the command line arguments are correct. If not
your program must generate an appropriate error message and then terminate.


This is the specification of my requirement.Could any one please help me out in giving out a correct coding for this.



Thanking you

Roger.

推荐答案

请参见此处此处.

没有人会为您提供该问题的完整代码.
Well see here or maybe here.

Noone is going to give you the entire code for the problem.


这篇关于简单计算器程序VC#2008(控制台应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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