Previous
Appendix 
Tcl/Tk Tutorial - Create GUI using Tk with Tcl Language
Exercise

Exercise

Giving this exercise to you is for for my own amusement, knowing full well that, no one would do it, unless commanded so with a Colt .45 against his temple.

Q1. This is the problem - I forgot how to add, multiply and divide. It is easy to understand why I forgot such things. You see, I have to remember every thing about programming languages like C++, C, Perl, Java, JavaScript, HTML etc, etc and etc. So my mind automatically throws out unwanted stuff like mathematics, alphabets etc. So what I want to do is make a script that will do my calculations.

So, I went to this restaurant with my two friends and ordered a Hamburger and coke for all three people. Then I bought a pizza for my self. My friends, of course, expect me to pay the bill, those sneaky parasites. But I want to surprise them - I want to divide the bill among all three. They will cry out that it is unfair and I bought that pizza for myself, etc. But those are unnecessary details. Now I want a script to do the calculations for me because, as you know, I forgot mathematics. Store the last price in a variable called 'price'(what else) and also add the lines at the end:

label .price_average -text "All three people should pay $price Rs."
pack .price_average

This will show the last price. The prices are given below - whether the prices are accurate or not is irrelevant. Just do the script.

Hamburger - 15 Rs
Coke - 5 Rs
Pizza - 30 Rs

For those who don't know mathematics, the formula is given below.

((Hamburer + Coke) x 3) + Pizza
-------------------------------
               3

Now fire up the notepad and write the script - You can refer to the above explanations, but don't refer to the answer at the bottom. You can save the script as "price.tcl"(Be sure that the extension is 'tcl') and run the script to check the result.

If you get the correct answer, assuming that you have forgot mathematics too, it should come out as "All three people should pay 30 Rs." See I have given the answer too - 30. How many teachers would do that? Ain't I a great teacher?

If you get the script correctly, don't jump into the conclusion that you have become a tcl scripter.

Check Answer -- Appendix A

Comments

Ashok Yadav at 31 Jan, 2007 10:26
congratulations for writing the best online tutorial on TCL/TK!!!!!!!!!!

Being a geophysicist, we sometime require programming and scripting, I am a newbie in TCL/TK.
ur tutorial is very helpful for beginners like me.I suggest u to write some advanced tutorial on TCL/Tk,especially give some examples ur quite good at it.
Reply to this.
Anonymous at 24 Jan, 2008 09:00
I am a student in 10th grade that uses the Blue Jay program. This is my first time using notepad. How do you run your program?
Reply to this.
Anonymous at 10 Sep, 2008 10:57
hi,
thanks i was trying to understand TCL with cisco ios and ur tutorial made it a lot easier
Reply to this.
Jins Thomas at 11 Feb, 2010 01:33
Stopped to Say.. Great Workkkkkkkkkkkk!!!!!! I was googling for a intro for TCL/TK and thanks alot for this.
Reply to this.
Comment

Please dont enter you comments in this form - this is a fake form to confuse spamming bots. The next form is the real one.




Comment




Comment Formating : HTML tags a, strong, em, b, i, code, pre, p and br allowed. Other tags will be shown as code(< will become &lt;). Urls, Line breaks will be auto-formated.
Subscribe to Feed