< previous page page_130 next page >

Page 130
Programming Problems
1. Write a C++ program that converts a Celsius temperature to its Fahrenheit equivalent. The formula is
0130-01.gif
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Make the Celsius temperature a named constant so that its value can be changed easily. The program should print both the value of the Celsius temperature and its Fahrenheit equivalent, with appropriate identifying messages. Be sure to include appropriate comments in your program, choose meaningful identifiers, and use indentation as we do in the programs in this chapter.
2. Write a program to calculate the diameter, the circumference, and the area of a circle given a radius of 6.75. Assign the radius to a float variable, and then output the radius with an appropriate message. Declare a named constant PI with the value 3.14159. The program should output the diameter, the circumference, and the area, each on a separate line, with identifying labels. Print each value to five decimal places within a total fieldwidth of 10. Be sure to include appropriate comments in your program, choose meaningful identifiers, and use indentation as we do in the programs in this chapter.
3. You have bought a car, taking out a loan with an annual interest rate of 9%. You will make 36 monthly payments of $165.25 each. You want to keep track of the remaining balance you owe after each monthly payment. The formula for the remaining balance is
0130-02.gif
where
balk
= balance remaining after the kth payment
k
= payment number (1, 2, 3, )
pmt
= amount of the monthly payment
i
= interest rate per month (annual rate ÷ 12)
n
= total number of payments to be made

3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Write a program to calculate and print the balance remaining after the first, second, and third monthly car payments. Before printing these three results, the program should output the values on which the calculations are based (monthly payment, interest rate, and total number of payments). Label all output with identifying messages, and print all money amounts to two decimal places. Be sure to include appropriate comments in your program, choose meaningful identifiers, and use indentation as we do in the programs in this chapter.
Case Study Follow-Up
1. Modify the Walk program to include a roundoff factor so that the rounding of miles can be modified easily. Currently, the program uses a literal constant (10.0) in several places to round miles to the nearest tenth, requiring us to make multiple changes if we want a different roundoff factor.
2. Should the roundoff factor in Question 1 be a constant or a variable? Explain.
3. In the Walk program, a particular pattern of statements is repeated four times with small variations. Identify the repeating pattern. Then circle those parts of the statements that vary with each repetition.

 
< previous page page_130 next page >