Next: Arrays
Up: Further User-defined functions in
Previous: Review Questions
void floattopp(float q, int& L, int& P)which converts the sum of money
q
in pounds into L
pounds
and P
pence
where the pence are correctly rounded. Thus if q
was 24.5678
then L
should be set to 24 and P
should be set to 57.
Remember that when assigning a real to an integer the real is truncated.
Thus to round a real to the nearest integer add 0.5 before assigning to
the integer.
Write a simple driver program to test the function. Think carefully about the boundary conditions.
P
, the repayment time n
in
years and the rate of interest r
as a percentage rate and will
return the monthly repayment in pounds and pence.
Transform your algorithm into a C++ program. Write a function prototype for the repayment calculation function and write the function itself as a function stub. That is a function that does not perform the correct calculation but delivers values that are sufficient to test the rest of the program. In this case it should return values of zero for the pounds and pence of the monthly repayment. This will allow you to test that your program lays the table out properly.
Once you have the table layout working you can now write the function
itself. The repayment each month on a mortgage of P
pounds, taken out
over n
years at an interest rate of r
% is given by:
In writing this function use the function power
from
Section 21.5. This means you must add this function,
and a suitable prototype, to your program. Also use the function of
exercise 1 above.