Updated trunk

git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@2484 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
eifops
2025-02-06 17:17:32 +00:00
parent dfeab946bd
commit de6e7aad63
89 changed files with 516 additions and 129 deletions

View File

@@ -0,0 +1,102 @@
[[Property:title|Calculator: console]]
[[Property:weight|0]]
[[Property:uuid|70cc4687-0d3e-2859-70f6-c603c05d085c]]
=The Calculator Sample=
This sample consists of a command line reverse Polish notation (RPN) calculator.
{{note|A RPN calculator works slightly differently from standard calculators. It consists of a stack of numbers. Operations are applied to the two numbers on top of the stack. The result is then put on top of the stack so that it can be used in the next operation. This sample refers to the top of the stack as ''Accumulator''. }}
==Compiling==
To compile the example:
# Launch EiffelStudio.
# Click '''Add project'''
# Browse to ''$ISE_EIFFEL\examples\base\calculator\''
# Choose ''calculator.ecf''
# Change the target from classic to dotnet
# Choose the location where the project will be compiled, by default the same directory containing the configuration file.
# Click '''Open'''.
==Running==
After you launch the sample, the following text appears in a console:
<code>
*********************************
Calculator in reverse Polish form
*********************************
Allowable operations are:
'/': Divide top two numbers on the stack.
'0': Empty the stack.
'a': Enter operand onto stack.
'?': Help.
'*': Multiply top two numbers on the stack.
'+': Add top two numbers on the stack
'q': Quit.
'-': Subtract top two numbers on the stack.
Enter a number, followed by :
</code>
Enter the first number to be put onto the stack, for example <code>3</code>.
{{note|Failing to enter a number at this stage will cause the sample to stop. This sample was designed to showcase the use of EiffelBase data structures in the Microsoft .NET environment and is not protected against unexpected entries. }}
You may then add another number on the stack by entering the character "<code>a</code>":
<code>
*********************************
Calculator in reverse Polish form
*********************************
Allowable operations are:
'/': Divide top two numbers on the stack.
'0': Empty the stack.
'a': Enter operand onto stack.
'?': Help.
'*': Multiply top two numbers on the stack.
'+': Add top two numbers on the stack
'q': Quit.
'-': Subtract top two numbers on the stack.
Enter a number, followed by : 3
Accumulator = 3
Next operation? a
Enter a number, followed by :
</code>
Enter a second number, for example <code>2</code>. You can then apply any operation to the two operands such as minus:
<code>
...
Next operation? a
Enter a number, followed by : 2
Accumulator = 2
Next operation? -
Accumulator = 1
Next operation?
</code>
You may use the operation<code> 0</code> to clear the stack at any time. You may use <code>q</code> to quit the program.
{{tip|You can use the command <code>?</code> to display the list of available operations. }}
==Under the Hood==
This sample shows how to leverage EiffelBase data structures in a simple Eiffel system. The root class <eiffel>CALCULATOR</eiffel> first instantiates all ''state'' objects, each corresponding to one possible operation. The state classes all inherit from <eiffel>STATE</eiffel>. They are:
* <eiffel>PLUS</eiffel>: Add stack's two top numbers.
* <eiffel>MINUS</eiffel>: Substract stack's two top numbers.
* <eiffel>MULTIPLY</eiffel>: Multiply stack's two top numbers.
* <eiffel>DIVIDE</eiffel>: Divide stack's two top numbers.
* <eiffel>EMPTY</eiffel>: Empty stack.
* <eiffel>HELP</eiffel>: Prints available commands.
* <eiffel>QUESTION</eiffel>: Get number from user.
* <eiffel>QUIT</eiffel>: Close application.
Each of these classes implement the feature <eiffel>do_one_state</eiffel> from <eiffel>STATE</eiffel> which performs the operation associated with the state.The initial state is <eiffel>QUESTION</eiffel> which asks for the initial number to put in the ''accumulator''. Following states depend on the user input.Every descendant of <eiffel>STATE</eiffel> implement the feature <eiffel>operation</eiffel> which performs the corresponding stack transformation.

View File

@@ -0,0 +1,5 @@
[[Property:title|Console Samples]]
[[Property:weight|1]]
[[Property:uuid|3f2c704c-9784-06a5-4cad-02ad58433b2c]]
Console application samples.