19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

156 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

TABLE 5.7<br />

A Comparison of 1988 Fuel Prices <strong>and</strong> Per Capita Motor Fuel Use<br />

Price per Tons of Oil Price per Tons of Oil<br />

gallon in per 1000 gallon in per 1000<br />

Country U.S. Dollars Person Country U.S. Dollars Person<br />

USA $1.00 1400 France $3.10 580<br />

W. Ger. $2.20 620 Norway $3.15 600<br />

Engl<strong>and</strong> $2.60 550 Japan $3.60 410<br />

Austria $2.75 580 Denmark $3.70 570<br />

Sweden $2.80 700 Italy $3.85 430<br />

Holl<strong>and</strong> $3.00 490<br />

Source: World Resources Institute<br />

FIGURE 5-14 Least-Squares Fit to Data from Table 5.7<br />

FIGURE 5-15 Sample Run of <strong>Programming</strong> Project 5<br />

6. Write a program to provide information on the height of a ball thrown straight<br />

up into the air. The program should request the initial height, h feet, <strong>and</strong> the initial<br />

velocity, v feet per second, as input. The four options to be provided by comm<strong>and</strong><br />

buttons are as follows:<br />

(a) Determine the maximum height of the ball. Note: The ball will reach its<br />

maximum height after v/32 seconds.<br />

(b) Determine approximately when the ball will hit the ground. Hint: Calculate<br />

the height after every .1 second <strong>and</strong> observe when the height is no longer a<br />

positive number.<br />

(c) Display a table showing the height of the ball every quarter second for 5 seconds<br />

or until it hits the ground.<br />

(d) Quit.<br />

The formula for the height of the ball after t seconds, h + v * t – 16 * t * t,<br />

should be specified in a user-defined function. (Test the program with v = 148<br />

<strong>and</strong> h = 0. This velocity is approximately the top speed clocked for a ball thrown<br />

by a professional baseball pitcher.)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!