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