Chapter 6 Programming Projects


[Page 301 (continued)]

1.

Write a program to display a company's payroll report in a list box. The program should read each employee's name, hourly rate, and hours worked from a file and produce a report in the form of the sample run shown in Figure 6.18. Employees should be paid time-and-a-half for hours in excess of 40.

Figure 6.18. Sample output from Programming Project 1.

Payroll Report for week ending 11/17/06

Employee

Hourly Rate

Hours Worked

Gross Pay

Al Adams

$6.50

38

$247.00

Bob Brown

$5.70

50

$313.50

Carol Coe

$7.00

40

$280.00

Final Total

  

$840.50



[Page 302]
2.

Table 6.6 shows the standard prices for items in a department store. Suppose prices will be reduced for the annual President's Day Sale. The new price will be computed by reducing the old price by 10 percent, rounding up to the nearest dollar, and subtracting 1 cent. If the new price is greater than the old price, the old price is used as the sale price. Write a program to display in a list box the output shown in Figure 6.19.

Table 6.6. President's Day sale.

Item

Original Price

GumShoes

39.00

SnugFoot Sandals

21.00

T-Shirt

7.75

Maine Handbag

33.00

Maple Syrup

6.75

Flaked Vest

24.00

Nightshirt

26.00


Figure 6.19. Output of Programming Project 2.

Item

Sale Price

GumShoes

35.99

SnugFoot Sandals

18.99

T-Shirt

6.99

Maine Handbag

29.99

Maple Syrup

6.75

Flaked Vest

21.99

Nightshirt

23.99


3.

The Rule of 72 is used to make a quick estimate of the time required for prices to double due to inflation. If the inflation rate is r percent, then the Rule of 72 estimates that prices will double in 72/ryears. For instance, at an inflation rate of 6 percent, prices double in about 72/6 or 12 years. Write a program to test the accuracy of this rule. The program should display a table showing, for each value of r from 1 to 20, the rounded value of 72/r and the actual number of years required for prices to double at an r percent inflation rate. (Assume prices increase at the end of each year.) Figure 6.20 shows the first few rows of the output.

Figure 6.20. Rule of 72 used in Programming Project 3.

Interest Rate (%)

Rule of 72

Actual

1

72

70

2

36

36

3

24

24



[Page 303]
4.

Table 6.7 shows the number of bachelor degrees conferred in 1980 and 2002 in certain fields of study. Tables 6.8 and 6.9 show the percentage change and a histogram of 2002 levels, respectively. Write a program that allows the user to display any one of these tables as an option and quit as a fourth option.

Table 6.7. Bachelor degrees conferred in certain fields.

Field of Study

1980

2002

Business and management

184,867

281,330

Computer and info. science

11,154

47,299

Education

118,038

106,383

Engineering

68,893

59,481

Social sciences

103,662

132,874

Source: U.S. National Center of Educational Statistics


Table 6.8. Percentage change in bachelor degrees conferred.

Field of Study

% Change (1980-2002)

Business and management

52.2

Computer and info. science

324.1

Education

-9.9

Engineering

-13.7

Social sciences

28.2


Table 6.9. Bachelor degrees conferred in 2002 in certain fields.

Business and management

**************************** 281,330

Computer and info. science

***** 47,299

Education

*********** 106,383

Engineering

****** 59,481

Social sciences

************* 132,874


5.

Least-Squares Approximation. Table 6.10 shows the 1988 prices of a gallon of gasoline and the amounts of fuel consumed for several countries. Figure 6.21 displays the data as points in the xy plane. For instance, the point with coordinates (1, 1400) corresponds to the USA. Figure 6.21 also shows the straight line that best fits these data in the least-squares sense. (The sum of the squares of the distances of the 11 points from this line is as small as possible.) In general, if(x1,y1),(x2,y2), ...,(xn,yn) are n points in the xy coordinate system, then the least-squares approximation to these points is the line y=mx+b,where


[Page 304]

and

b = ((sum of yi) - m * (sum of xi))/n.

Write a program that calculates and displays the equation of the least-squares line. The program should then allow the user to enter a gasoline price and use the equation of the line to predict the corresponding consumption of fuel. (Place the numeric data from the table in a text file.) A sample run is shown in Figure 6.22.

Table 6.10. A comparison of 1988 gasoline prices and per capita fuel use.

Country

Price per gallon in U.S. Dollars

Tons of Fuel per 1000 Persons

Country

Price per gallon in U.S. Dollars

Tons of Fuel per 1000 Persons

USA

$1.00

1400

France

$3.10

580

W. Ger.

$2.20

620

Norway

$3.15

600

England

$2.60

550

Japan

$3.60

410

Austria

$2.75

580

Denmark

$3.70

570

Sweden

$2.80

700

Italy

$3.85

430

Holland

$3.00

490

   

Source: World Resources Institute


Figure 6.21. Least-squares fit to data from Table 6.10.


Figure 6.22. Sample run of Programming Project 5.



[Page 305]
6.

Write a program to provide information on the height of a ball thrown straight up into the air. The program should request the initial height, h feet, and the initial velocity, v feet per second, as input. The four options to be provided by buttons are as follows:

  1. Determine the maximum height of the ball. Note: The ball will reach its maximum height after v/32 seconds.

  2. Determine approximately when the ball will hit the ground. Hint: Calculate the height after every .1 second and observe when the height is no longer a positive number.

  3. Display a table showing the height of the ball every quarter second for five seconds or until it hits the ground.

  4. Quit.

The formula for the height of the ball aftert seconds, h + v*t - 16*t*t*, should be specified in a user-defined function. (Test the program with v = 148 and h = 0. This velocity is approximately the top speed clocked for a ball thrown by a professional baseball pitcher.)

7.

Depreciation to a Salvage Value of 0. For tax purposes an item may be depreciated over a period of several years, n. With the straight-line method of depreciation, each year the item depreciates by 1/nth of its original value. With the double-declining-balance method of depreciation, each year the item depreciates by 2/nths of its value at the beginning of that year. (In the last year, it is depreciated by its value at the beginning of the year.) Write a program that performs the following tasks:

  1. Requests a description of the item, the year of purchase, the cost of the item, the number of years to be depreciated (estimated life), and the method of depreciation. The method of depreciation should be chosen by clicking one of two buttons.

  2. Displays a depreciation schedule for the item similar to the schedule shown in Figure 6.23.

Figure 6.23. Depreciation schedule for Programming Project 7.

Description: Computer

Year of purchase: 2002

Cost: $2,000.00

Estimated life: 5

Method of depreciation: double-declining-balance

 
 

Value at

Amount Deprec

Total Depreciation

Year

Beg of Yr

During Year

to End of Year

2002

2,000.00

800.00

800.00

2003

1,200.00

480.00

1,280.00

2004

720.00

288.00

1,568.00

2005

432.00

172.80

1,740.80

2006

259.20

259.20

2,000.00



[Page 306]
8.

The Twelve Days of Christmas. Each year, PNC Advisors of Pittsburgh publishes a Christmas price list. See Table 6.11. Write a program that requests an integer from 1 through 12 and then lists the gifts for that day along with that day's cost. On the nth day, the n gifts are 1 partridge in a pear tree, 2 turtle doves, ..., n of the nth item. The program also should give the total cost of all twelve days. As an example, Figure 6.24 shows the output in the list box when the user enters 3.

Table 6.11. Christmas price list for 2005.

Item

Cost

Item

Cost

partridge in a pear tree

104.99

swan-a-swimming

600.00

turtle dove

20.00

maid-a-milking

5.15

French hen

15.00

lady dancing

508.46

calling bird

99.99

lord-a-leaping

403.91

gold ring

65.00

piper piping

186.65

geese-a-laying

50.00

drummer drumming

185.36


Figure 6.24. Sample output for Programming Project 8.

The gifts for day 3 are

1 partridge in a pear tree

2 turtle doves

3 french hens

Cost: $189.99

Total cost for the twelve days: $72,608.00





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