/[eiffelstudio]/trunk/Delivery/xmldoc/libraries/base/samples/10_calculator/index.xml
ViewVC logotype

Contents of /trunk/Delivery/xmldoc/libraries/base/samples/10_calculator/index.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 63849 - (show annotations)
Mon Sep 25 19:25:28 2006 UTC (13 years, 4 months ago) by patrickr
File MIME type: text/xml
File size: 5716 byte(s)
removed version numbers from library index page
updated sample documentations of most libraries
1 <document title="Calculator">
2 <meta_data>
3 <help>
4 <toc>
5 <envision_location>EiffelEnvision\Examples\EiffelBase</envision_location>
6 </toc>
7 </help>
8 </meta_data>
9 <paragraph>
10 <paragraph> This sample consists of a command line reverse Polish notation (RPN) calculator. </paragraph>
11 <paragraph>
12 <note>
13 <bold>Note:</bold> 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
14 <italic>Accumulator</italic>.
15 <heading>
16 <size>2</size>Compiling
17 </heading>
18 <paragraph> To compile the example: </paragraph>
19 <output output="envision">
20 <list ordered="true">
21 <item>Start Visual Studio .NET</item>
22 <item>Choose Open Project from the File menu.</item>
23 <item>Navigate to <italic>&lt;EiffelEnvision_installation_path&gt;\envision\examples\calculator\</italic> and select <italic>calculator.eifp</italic></item>
24 <item>Clicking open loads the selected project</item>
25 </list>
26 </output>
27 <output output="studio">
28 <list ordered="true">
29 <item>Launch EiffelStudio.</item>
30 <item>Click <bold>Add project</bold></item>
31 <item>Browse to <italic>$ISE_EIFFEL\examples\base\calculator\</italic></item>
32 <item>Choose <italic>calculator.ecf</italic></item>
33 <item>Choose the location where the project will be compiled, by default the same directory containing the configuration file.</item>
34 <item>Click <bold>Open</bold>.</item>
35 </list>
36 </output>
37 <paragraph>
38 <heading>
39 <size>2</size>Running
40 </heading>
41 <paragraph> After you launch the sample, the following text appears in a console: </paragraph>
42 <code_block>
43 *********************************
44 Calculator in reverse Polish form
45 *********************************
46
47 Allowable operations are:
48 '/': Divide top two numbers on the stack.
49 '0': Empty the stack.
50 'a': Enter operand onto stack.
51 '?': Help.
52 '*': Multiply top two numbers on the stack.
53 '+': Add top two numbers on the stack
54 'q': Quit.
55 '-': Subtract top two numbers on the stack.
56 Enter a number, followed by :
57 </code_block>
58 <paragraph> Enter the first number to be put onto the stack, for example
59 <code><symbol>3</symbol></code>.
60 </paragraph>
61 <note>
62 <bold>Note:</bold> 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 and is not protected against unexpected entries.
63 </note>
64 <paragraph> You may then add another number on the stack by entering the character
65 <code><symbol>a</symbol></code>:
66 </paragraph>
67 <code_block>
68 *********************************
69 Calculator in reverse Polish form
70 *********************************
71 Allowable operations are:
72 '/': Divide top two numbers on the stack.
73 '0': Empty the stack.
74 'a': Enter operand onto stack.
75 '?': Help.
76 '*': Multiply top two numbers on the stack.
77 '+': Add top two numbers on the stack
78 'q': Quit.
79 '-': Subtract top two numbers on the stack.
80 Enter a number, followed by : 3
81
82 Accumulator = 3
83
84 Next operation? a
85 Enter a number, followed by :
86 </code_block>
87 <paragraph> Enter a second number, for example
88 <code><symbol>2</symbol></code>. You can then apply any operation to the two operands such as minus:
89 </paragraph>
90 <code_block>
91 ...
92 Next operation? a
93 Enter a number, followed by : 2
94
95 Accumulator = 2
96
97 Next operation? -
98
99 Accumulator = 1
100
101 Next operation?
102 </code_block>
103 <paragraph> You may use the operation
104 <code><symbol>0</symbol></code> to clear the stack at any time. You may use
105 <code><symbol>q</symbol></code> to quit the program.
106 </paragraph>
107 <tip>
108 <bold>Tip:</bold> You can use the command
109 <code><symbol>?</symbol></code> to display the list of available operations.
110 </tip>
111 <heading>
112 <size>2</size>Under the Hood
113 </heading>
114 <paragraph> This sample shows how to leverage EiffelBase data structures in a simple Eiffel system. The root class CALCULATOR first instantiates all
115 <italic>state</italic> objects, each corresponding to one possible operation. The state classes all inherit from STATE. They are:
116 </paragraph>
117 <list ordered="false">
118 <item>PLUS: Add stack's two top numbers. </item>
119 <item>MINUS: Substract stack's two top numbers. </item>
120 <item>MULTIPLY: Multiply stack's two top numbers. </item>
121 <item>DIVIDE: Divide stack's two top numbers. </item>
122 <item>EMPTY: Empty stack. </item>
123 <item>HELP: Prints available commands. </item>
124 <item>QUESTION: Get number from user. </item>
125 <item>QUIT: Close application. </item>
126 </list> Each of these classes implement the feature do_one_state from STATE which performs the operation associated with the state. The initial state is QUESTION which asks for the initial number to put in the
127 <italic>accumulator</italic>. Following states depend on the user input.
128 <line_break/> Every descendant of STATE implement the feature operation which performs the corresponding stack transformation.
129 </paragraph>
130 <paragraph> See the
131 <link>
132 <label>reference</label>
133 </link> for the class interfaces.
134 </paragraph>
135 </note>
136 </paragraph>
137 </paragraph></document>

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23