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.

togram of 1994 levels, respectively. Write a program that allows the user to display<br />

any one of these tables as an option <strong>and</strong> quit as a fourth option.<br />

TABLE 5.4<br />

Bachelor Degrees Conferred in Certain Fields<br />

Field of Study 1980 1994<br />

Business <strong>and</strong> management 185,361 246,654<br />

<strong>Computer</strong> <strong>and</strong> info. science 11,154 24,200<br />

Education 118,169 167,600<br />

Engineering 68,893 62,220<br />

Social sciences 103,519 133,680<br />

Source: U.S. National Center of Educational Statistics<br />

TABLE 5.5<br />

Percentage Change in Bachelor Degrees Conferred<br />

Field of Study % Change (1980–1994)<br />

Business <strong>and</strong> management 33.1<br />

<strong>Computer</strong> <strong>and</strong> info. science 117.0<br />

Education 41.8<br />

Engineering –9.7<br />

Social sciences 29.1<br />

TABLE 5.6<br />

Bachelor Degrees Conferred in 1994 in Certain Fields<br />

Business <strong>and</strong> management ************************* 246,654<br />

<strong>Computer</strong> <strong>and</strong> info. science *** 24,200<br />

Education ***************** 167,600<br />

Engineering ****** 62,220<br />

Social sciences ************* 133,680<br />

5. Least-Squares Approximation. Table 5.7 shows the 1988 price of a gallon of fuel<br />

<strong>and</strong> the consumption of motor fuel for several countries. Figure 5-14 displays<br />

the data as points in the xy plane. For instance, the point with coordinates<br />

(1, 1400) corresponds to the USA. Figure 5-14 also shows the straight line that<br />

best fits these data in the least squares sense. (The sum of the squares of the distances<br />

of the 11 points from this line is as small as possible.) In general, if<br />

(xi, y1), (x2, y2), . . , (xn, yn) are n points in the xy coordinate system, then the<br />

least squares approximation to these points is the line y = mx + b, where<br />

<strong>and</strong><br />

m =<br />

n * (sum of xi * yi) – (sum of xi) * *=(sum of yi)<br />

������<br />

n * (sum of xi * xi) – (sum of xi) 2<br />

b = ((sum of yi) – m * (sum of xi))/n<br />

Write a program that calculates <strong>and</strong> displays the equation of the least squares line, <strong>and</strong> then<br />

allows the user to enter a fuel price <strong>and</strong> uses the equation of the line to predict the corresponding<br />

consumption of motor fuel. (Place the numeric data from the table in a data file.) A<br />

sample run is shown in Figure 5-15.<br />

<strong>Programming</strong> Projects 155

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

Saved successfully!

Ooh no, something went wrong!