Main Page | Modules | Class Hierarchy | Class List | File List | Class Members

Calculator Class Reference

#include <calculator.h>

Inheritance diagram for Calculator:

CalculatorFSM List of all members.

Detailed Description

A Sample Calculator class.

It supports only four types of actions with integer numbers, so it's quite unuseful. I wrote it only to demonstrate logic simplify with usage of finite state machine drawn with FSME.

Definition at line 18 of file calculator.h.

Public Slots

void slotNumber (int)
 A number have veen entered.
void slotPlus ()
 '+' have been pressed
void slotMinus ()
 '-' have been pressed
void slotMul ()
 '*' have been pressed
void slotDiv ()
 '/' have been pressed
void slotClear ()
 'C' have been pressed
void slotEqual ()
 '=' have been pressed

Public Member Functions

 Calculator (QWidget *parent=0, const char *name=0, WFlags fl=0)
int popOperand ()
 Pop an operand from operands stack. It's used by Calculator::Operation.
void pushOperand (int n)
 Push result to the operands stack. It's used by Calculator::Operation::operator()().

Protected Member Functions

virtual void saveNumber ()
virtual void addNumber ()
virtual void clear ()
virtual void saveOp ()
virtual void showResult ()

Private Member Functions

void showStackTop ()
 Display a top of stack on a screen. This is our result.

Private Attributes

QValueStack< int > operands
 Operands stack.
QPtrStack< Operationoperations
 Operations stack.
int enteredOperand
 Entered digit.
OperationenteredOperation
 Entered operation.


Member Data Documentation

Operation* Calculator::enteredOperation [private]
 

Entered operation.

This is an operation entered by user. For example, when user clicks "1+2", first, enteredOperand will be "1", and enteredOperation will be Calculator::OpPlus Definition at line 112 of file calculator.h.

Referenced by saveOp(), slotDiv(), slotMinus(), slotMul(), and slotPlus().

QValueStack<int> Calculator::operands [private]
 

Operands stack.

There are 2 stacks: operands and operations. This one holds operands being entered. In our simple case this stack will never have more than 1 element. But if parentheses are introduced, deep will grow.

See also:
Calculator::Operation
Definition at line 87 of file calculator.h.

Referenced by addNumber(), clear(), popOperand(), pushOperand(), saveNumber(), and showStackTop().

QPtrStack<Operation> Calculator::operations [private]
 

Operations stack.

See also:
Calculator::Operation
There are 2 stacks: operands and operations. This one holds operations being entered. In our simple case this stack will never have more than 1 element. But if parentheses are introduced, deep will grow.

After '=' is pressed or ')' is entered, operation will be popped from this stack. Then it will be executed (taking appropriate number of arguments from operands stack) and the result will be pushed to operands stack back.

See also:
Calculator::Operation
Definition at line 102 of file calculator.h.

Referenced by clear(), saveOp(), and showResult().


The documentation for this class was generated from the following files:
Generated on Fri Oct 29 13:35:13 2004 for Calculator by doxygen 1.3.8