Chapter 5 Programming Projects


[Page 243 (continued)]

  1. Table 5.15 gives the price schedule for Eddie's Equipment Rental. Full-day rentals cost one-and-a-half times half-day rentals. Write a program that displays Table 5.15 in a list box when an appropriate button is clicked and displays a bill in another list box based on the item number and time period chosen by a customer. The bill should include a $30.00 deposit. A possible form layout and sample run are shown in Figure 5.9.


    [Page 244]

    Table 5.15. Price schedule for Eddie's Equipment Rental.
    (This item is displayed on page 243 in the print version)

    Piece of Equipment

    Half-Day

    Full-Day

    1.Rug cleaner

    $16.00

    $24.00

    2.Lawn mower

    $12.00

    $18.00

    3.Paint sprayer

    $20.00

    $30.00


    Figure 5.9. Form layout and sample run for Programming Project 1.

  2. The American Heart Association suggests that at most 30 percent of the calories in our diet come from fat. Although food labels give the number of calories and amount of fat per serving, they often do not give the percentage of calories from fat. This percentage can be calculated by multiplying the number of grams of fat in one serving by 9, dividing that number by the total number of calories per serving, and multiplying the result by 100. Write a program that requests the name, number of calories per serving, and the grams of fat per serving as input, and tells us whether the food meets the American Heart Association recommendation. A sample run is as in Figure 5.10.

    Figure 5.10. Sample run of Programming Project 2.


  3. [Page 245]
  4. Table 5.16 gives the 2004 federal income tax rate schedule for single taxpayers. Write a program that requests taxable income and calculates federal income tax. Use a Sub procedure for the input and a Function procedure to calculate the tax.

    Table 5.16. 2004 federal income tax rates for single tax payers.

    Taxable Income Over

    But Not Over

    Your Tax Is

    Of Amount Over

    $0

    $7,150

    10%

    $0

    $7,150

    $29,050

    $715.00 + 15%

    $7,150

    $29,050

    $70,350

    $4,000.00 + 25%

    $29,050

    $70,350

    $146,750

    $14,325.00 + 28%

    $70,350

    $146,750

    $319,100

    $35,717.00 + 33%

    $146,750

    $319,100

     

    $92,592.50 + 35%

    $319,100


  5. Write a program to determine the real roots of the quadratic equation ax2 + bx + c = 0 (where a 0 ) after requesting the values of b, and c. Use a Sub procedure to ensure that a is nonzero. Note: The equation has 2, 1, or 0 solutions depending on whether the value of b^2 - 4*a*c is positive, zero, or negative. In the first two cases, the solutions are given by the quadratic formula (-b ± Sqrt(b^2 - 4*a*c))/2*a). Test the program with the following sets of coefficients:

    a = 1

    b = -11

    c = 28

    Solutions are 4 and 7

    a = 1

    b = -6

    c = 9

    Solution is 3

    a = 1

    b = 4

    c = 5

    No solution


  6. Table 5.17 contains seven proverbs and their truth values. Write a program that presents these proverbs one at a time and asks the user to evaluate them as true or false. The program should then tell the user how many questions were answered correctly and display one of the following evaluations: Perfect (all correct), Excellent (5 or 6 correct), You might consider taking Psychology 101 (less than 5 correct).

    Table 5.17. Seven proverbs.

    Proverb

    Truth Value

    The squeaky wheel gets the grease.

    True

    Cry and you cry alone.

    True

    Opposites attract.

    False

    Spare the rod and spoil the child.

    False

    Actions speak louder than words.

    True

    Familiarity breeds contempt.

    False

    Marry in haste, repent at leisure.

    True

    Source: "You Know What They Say..., " by Alfie Kohn, Psychology Today, April 1988.



  7. [Page 246]
  8. Write a program to analyze a mortgage. The user should enter the amount of the loan, the annual rate of interest, and the duration of the loan in months. When the user clicks on the button, the information that was entered should be checked to make sure it is reasonable. If bad data have been supplied, the user should be so advised. Otherwise, the monthly payment and the total amount of interest paid should be displayed. The formula for the monthly payment is

    payment = p * r / (1 - (1 + r)^(-n)),

    where p is the amount of the loan, r is the monthly interest rate (annual rate divided by 12) given as a number between 0 (for 0 percent) and 1 (for 100 percent), and n is the duration of the loan in months. The formula for the total interest paid is

    total interest = n * payment - p.

    (Test the program for a mortgage of $240,000 at 6% annual rate of interest, and duration 360 months. Such a mortgage will have a monthly payment of $1,438.92 and total interest of $278,011.65.)

  9. Five, Six, Pick up Sticks.

    Write a program that allows the user to challenge the computer to a game of Pick-up-Sticks. Here is how the game works. The user chooses the number of matchsticks (from 5 to 50) to place in a pile. Then, the computer chooses who will go first. At each turn, the contestant can remove one, two, or three matchsticks from the pile. The contestant who chooses the last matchstick loses.

    The computer should make the user always select from a pile where the number of matchsticks has a remainder of 1 when divided by 4. For instance, if the user initially chooses a number of matchsticks that has a remainder of 1 when divided by 4, then the computer should have the user go first. Otherwise, the computer should go first and remove the proper number of matchsticks. [Note: The remainder when n is divided by 4 is (n Mod 4).] After writing the program, play a few games with the computer and observe that the computer always wins.

    Figure 5.11. A possible outcome of Programming Project 7.




An Introduction to Programming Using Visual Basic 2005
Introduction to Programming Using Visual Basic 2005, An (6th Edition)
ISBN: 0130306541
EAN: 2147483647
Year: 2006
Pages: 164

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net