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.

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

6. Write a program to analyze a mortgage. The user should enter the amount of the<br />

loan, the annual rate of interest, <strong>and</strong> the duration of the loan in months. When<br />

the user clicks on the comm<strong>and</strong> button, the information that was entered should<br />

be checked to make sure it is reasonable. If bad data have been supplied, the<br />

user should be so advised. Otherwise, the monthly payment <strong>and</strong> the total<br />

amount of interest paid should be displayed. The formula for the monthly payment<br />

is<br />

payment = p * r / (1 – (1 + r) ^ (–n))<br />

where p is the amount of the loan, r is the monthly interest rate (annual rate<br />

divided by 12) given as a number between 0 (for 0 percent) <strong>and</strong> 1 (for 100 percent),<br />

<strong>and</strong> n is the duration of the loan. The formula for the total interest paid is<br />

total interest = n * payment - p<br />

(Test the program for a mortgage of $140,000 at 8% annual rate of interest, <strong>and</strong><br />

duration 360 months. Such a mortgage will have a monthy payment of<br />

$1,027.27.)<br />

7. Write a program using the form in Figure 4-8. Each time the comm<strong>and</strong> button<br />

is pressed, Rnd is used to simulate a coin toss <strong>and</strong> the values are updated. The<br />

figure shows the status after 27 coin tosses. Note: You can produce tosses<br />

quickly by just holding down the Enter key. Although the percentage of heads<br />

initially will fluctuate considerably, it should stay close to 50% after many (say,<br />

1000) tosses.<br />

FIGURE 4-8 Form for <strong>Programming</strong>

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

Saved successfully!

Ooh no, something went wrong!