Chapter 4 Programming Projects


[Page 188 (continued)]

  1. The numbers of calories per gram of carbohydrate, fat, and protein are 4, 9, and 4, respectively. Write a program that requests the nutritional content of a serving of food and displays the number of calories in the serving. The input and output should be handled by Sub procedures and the calories computed by a function. A sample run for a typical breakfast cereal is shown in Figure 4.10.


    [Page 189]

    Figure 4.10. Sample run for Programming Project 1.

  2. Annually, 1.7 billion dollars worth of toothpaste are sold each year in the United States. Table 4.3 gives the market share for the four top brands. Write a program that displays the annual sales (in millions of dollars) for each of the top four. The input and output should be handled by Sub procedures and the annual sales calculated by a Function procedure.

    Table 4.3. 2001 market shares of the top-selling toothpaste brands.

    Company

    Market Share

    Crest

    19.4%

    Colgate

    17.2%

    Aquafresh

    8.0%

    Colgate Total

    6.6%

    Source: The World Almanac and Book of Facts 2002.


  3. Table 4.4 gives the research and development budgets (in billions of dollars) for four departments of the federal government for the years 2004 and 2005. Write a program that displays the percentage change in the budget for each department. Sub procedures should be used for input and output, and the percentage change should be computed with a Function procedure. Note: The percentage change is ([2005 budget] [2004 budget])/[2004 budget].

    Table 4.4. Research and development budget for several departments.

    Department

    2004 Budget

    2005 Budget

    Defense

    65.6

    70.3

    Health and Human Services

    28.5

    29.1

    NASA

    10.9

    11.1

    Homeland Security

    1.0

    1.2

    Source: American Association for the Advancement of Science.



  4. [Page 190]
  5. A fast-food vendor sells pizza slices ($1.25), fries ($1.00), and soft drinks ($.75). Write a program to compute a customer's bill. The program should request the quantity of each item ordered in a Sub procedure, calculate the total cost with a Function procedure, and use a Sub procedure to display an itemized bill. A sample output is shown in Figure 4.11.

    Figure 4.11. Sample run for Programming Project 4.

  6. Write a program to generate a business travel expense attachment for an income-tax return. The program should request as input the name of the organization visited, the date and location of the visit, and the expenses for meals and entertainment, airplane fare, lodging, and taxi fares. (Only 50% of the expenses for meals and entertainment are deductible.) A possible form layout and run are shown in Figures 4.12 and 4.13, respectively. The output is displayed in a list box that becomes visible when the button is clicked. Sub procedures should be used for the input and output.


    [Page 191]

    Figure 4.12. Form with sample data for Programming Project 5.

    Figure 4.13. Output in list box for sample run of Programming Project 5.


  7. [Page 192]
  8. A furniture manufacturer makes two types of furniturechairs and sofas. The file PRICE&TAXDATA.TXT contains three numbers giving the cost per chair, cost per sofa, and sales tax rate. Write a program to create an invoice form for an order. See Figure 4.14. After the data on the left side of Figure 4.14 are entered, you can display an invoice in a list box by pressing the Process Order button. You can press the Clear Order Form button to clear all text boxes and the list box, and you can press the Quit button to exit the program. The invoice number consists of the capitalized first two letters of the customer's last name, followed by the last four digits of the zip code. The customer name is input with the last name first, followed by a comma, a space, and the first name. However, the name is displayed in the invoice in the proper order. The generation of the invoice number and the reorder of the first and last names should be carried out in Function procedures.

    Figure 4.14. Sample run for Programming Project 6.




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