Menu

19 February 2007

Simple Calculator in TCL/TK

HI,
I got this as an assignment in software lab, the code which i am presenting is not a good and highly optimized but the logic which is used is something good and that what i want to share with you,,,
so this is the package that contain readme.pdf and code file named skycal1.1.tcl
download
but wait, first you need to learn how to run the code
using command line,,,,
$ wish skycal1.1.tcl
so simple....
download the package.
but readme.pdf you can study form here also


Subject : EEP 702 (Software Lab)

Assignment #1 : Simple Calculator ( SkyCal 1.1) using TCL/TK

Author : Narendra Sisodiya 2006EET2473


Features:

  1. Its a free Application

  2. Backspace button is supported

  3. +/- button is supproted.

  4. Clear Button for resetting the calculation

  5. Result is carried is next calculation. It means if user presses 12+23 then * 10 then /2 it will give result as 175.

  6. floating point calculation is supported

  7. Event Driven State Model is used. (Author did not copied this architecture from any where, he himself derived this and named it like this). It is a highly Modular and Scalable Architecture. As initial code (named Skycal 1.0 )was not supporting the +/- button and Backspace button. They were added now , without modifying the existing code , only a little code was added with least efforts.


Snapshot :

What is Event Driven State Model:

It is a simple State Model in which a system is triggered from one state to another state using key events. Every event is corresponds to some action. Because of this feature when i wanted to introduce two new button for +/- and BackSpace, I added two new events to each state. One more feature is that the event also has argument here.


Working:

Various Events :

  1. Event 1 : num_button click event. if user clicked any of numeric button from 0 to 9 or '.' it has key label as argument

  2. Event 2 : Equal button click event if user ckicked '=' button for calculating the result

  3. Event 3 : Clear Button click event

  4. Event 4 : Operator button click event

  5. Event 5 : +/- button is clicked. it also has key label as argument.

  6. Event 6 : Backspace button is clicked


Varoius States:

  1. State_0 : IDLE : Calulator starts from this state. will remain in this state until any num button is clicked.

  2. State_1 : Taking_Operand1: at this state user is keep entrying the value of operand1. during this if we encounter any operator then we jump to next state2

  3. State_2 : Taking_Operator :at this user may enter many operator. only last entered opearator is considered, if we find any numeric button then it goes to next state for taking the next operand.

  4. State_3 : Taking_operand2 : now at this state user will give second argument to program and if user press '=' button then it evaluate and goes to state_4 : FreeState. if user press any operator then it evaluates the expression and put result in operand1 and goes to state_2

  5. State_4 : Free State : at this state if user press numeric key then it goes to state 1 to take operand 1 if user press operator key then last obtained result is hold by operand2 and program goes to state 3


Varoius Events Handler:

the whole code is operated through events handlers. We have six events so that we are having 6 events handler (simply they are functions called whenever a key is pressed).

Operation :

the operation is very simple. Thers is a globel variable state by which every function can see at what state the system is present. Whenever any key is pressed it envokes a correspondind event hander function. Event handler funcion see what is the state and according to state it performs some actions,

State Diagram :

next figure shows state diagram. Note that this is an old state diagram , that does not include the event those were added later,,,main thing you need to do,,, understand the state diagram and correlate with coding architecture.

download this image





14 February 2007

DMOZ : The Open Directory Project

HI Friends, I found this is a very good site,
site name : http://dmoz.org/

The Open Directory Project is the largest, most comprehensive human-edited directory of the Web.

It is constructed and maintained by a vast, global community of volunteer editors.

whenever you want a number of links on a topic, just go to it and have a number of links related to it,

for example, if you want to know some links about operating system,

see the result of the search.

http://dmoz.org/Computers/Software/Operating_Systems/
click on specific topic and you will get a large number of links,, you can add some links also, and become a editor.