Page 204 - Open Soource Technologies 304.indd
P. 204

Event Driven Programming



                               person’s THR can be calculated from his age and resting heart rate (pulse when first
                               awakening) as follows:
                                (a) Calculate the maximum heart rate as 220 age.

                                (b) Subtract the resting heart rate from the maximum heart rate.
                                (c) Multiply the result in step (b) by 60%, and then add the resting heart rate.
                                   Write a program to request a person’s age and resting heart rate as input and display
                                   their THR. (Test the program with an age of 20 and a resting heart rate of 70, and then
                                   determine your training heart rate.)
                            5. The three ingredients for a serving of popcorn at a movie theater are popcorn, butter
                               substitute, and a bucket. Write a program that requests the cost of these three items and
                               the price of the serving as input and then displays the profit. (Test the program where
                               popcorn costs 5 cents, butter substitute costs 2 cents, the bucket costs 25 cents, and the selling
                               price is $5.)

                            6. Rewrite the population-density program from Example 4 of Section 4.1 using a function to
                               calculate the population density.
                            7. The original cost of airmail letters was 5 cents for the first ounce and 10 cents for each
                               additional ounce. Write a program to compute the cost of a letter whose weight is given
                               by the user in a text box. Use a function called Ceil that rounds noninteger numbers up
                               to the next integer. The function Ceil can be defined by Ceil(x) = Int(x).(Test the program
                               with the weights 4, 1, 2.5, and .5 ounces.)

                            8. Suppose a fixed amount of money is deposited at the beginning of each month into a
                               savings account paying 6% interest compounded monthly. After each deposit is made, [new
                               balance] = 1.005 * [previous balance one month ago] + [fixed amount]. Write a program
                               that requests the fixed amount of the deposits as input and displays the balance after each
                               of the first four deposits. A sample outcome when 800 is typed into the text box for the
                               amount deposited each month follows.
                                   Month 1     800.00

                                   Month 2   1,604.00
                                   Month 3   2,412.02
                                   Month 4   3,224.08

                            9. Write a program to request the name of a United States senator as input and display the
                               address and greeting for a letter to the senator. Assume the name has two parts, and use
                               a function to determine the senator’s last name. A sample outcome when Robert Smith is
                               typed into the input dialog box requesting the senator’s name follows.
                               The Honorable Robert Smith
                               United States Senate

                               Washington, DC 20001
                               Dear Senator Smith,
                           10. Difference between Class Module and Standard Module.



                          198                    LOVELY PROFESSIONAL UNIVERSITY
   199   200   201   202   203   204   205   206   207   208   209