The amortized schedule shows the amounts that go towards interest and principal
ID: 3917201 • Letter: T
Question
The amortized schedule shows the amounts that go towards interest and principal for each month. Write a function that takes the loan terms as parameters and prints the amortized schedule. The function header and a sample output are shown below. The rightmost two columns (INTEREST, PRINCIPAL) are cumulative figures and show the total interest and principal paid to date. Like the sample below, print the year number only for the first month of the year and print the header again for each year.
void output_amortized(double loan_amount, double interest_rate, double term_years);
----------------------------------------------------------------- Year Month Interest Principal Balance | INTEREST PRINCIPAL ----------------------------------------------------------------- 1 1 500 610 149390 | 500 610 2 498 612 148779 | 998 1221 3 496 614 148165 | 1494 1835 4 494 616 147550 | 1988 2450 5 492 618 146932 | 2480 3068 6 490 620 146312 | 2969 3688 7 488 622 145690 | 3457 4310 8 486 624 145066 | 3943 4934 9 484 626 144440 | 4426 5560 10 481 628 143812 | 4908 6188 11 479 630 143182 | 5387 6818 12 477 632 142550 | 5864 7450 ----------------------------------------------------------------- Year Month Interest Principal Balance | INTEREST PRINCIPAL ----------------------------------------------------------------- 2 13 475 634 141916 | 6340 8084 14 473 636 141279 | 6813 8721 15 471 639 140641 | 7284 9359
Explanation / Answer
Screenshot
----------------------------------------------------------------------------------------------------
Program
//Header file for I/o
#include<iostream>
#include<math.h>
using namespace std;
//Function prototytpe
void output_amortized(double loan_amount, double interest_rate, double term_years);
//Test method
int main()
{
//Input prompt
double loan_amount=0.0,interest_rate=0.0,term_years=0.0;
cout << "Please enter the principal amount: ";
cin >> loan_amount;
cout << "Please enter annual interest rate: ";
cin >> interest_rate;
cout << "Please enter term year of loan: ";
cin >> term_years;
output_amortized(loan_amount, interest_rate, term_years);
return 0;
}
//Amortized loan calculator
void output_amortized(double loan_amount, double interest_rate, double term_years) {
//Variable fo rmonth year and loop
int month = 1,year=1,i=0,totalperiod=0;
//Convert year to month
term_years = term_years * 12;
//Arrays for prevoious month interest and principal calculations
double *interestArray,*principalArray;
interestArray = new double[term_years];
principalArray = new double[term_years];
double amount = 0.0,interest=0.0,principal=0.0,intrst=0.0,pr=0.0;
//Interest and emi amount
interest_rate = (interest_rate / (12 * 100));
amount = loan_amount * ((interest_rate*(pow((1 + interest_rate), term_years))) / (pow((1 + interest_rate), term_years) - 1));
cout << "----------------------------------------- Year Month Interest Principal Balance|INTEREST PRINCIPAL ---------------------------------------" << endl;
//Loop for calculation and display
while (totalperiod<term_years) {
//array to store all intersest
*(interestArray+i) = loan_amount * interest_rate;
interest = *(interestArray + i);
//Array to store all princpal
*(principalArray+i)= amount - interest;
principal = amount - interest;
//Loan amount reduction
loan_amount = loan_amount - principal;
//year change
if (month > 12) {
month = 1;
year++;
cout << "----------------------------------------- Year Month Interest Principal Balance|INTEREST PRINCIPAL ---------------------------------------" << endl;
}
//First month display
if (month ==1) {
cout << month << " " << year << " " << interest << " " << principal << " " << loan_amount << endl;
}
//Other months display
else if (month <= 12) {
intrst = 0,pr=0;
for (int j = 0; j < i; j++) {
intrst += (*(interestArray + j));
pr += (*(principalArray + j));
}
if (totalperiod == term_years-1) {
cout << intrst << " " << pr << " " << month << " " << interest << " " << principal << " 0" << endl;
}
else {
cout << intrst << " " << pr << " " << month << " " << interest << " " << principal << " " << loan_amount << endl;
}
}
//Increment variables for looping and calculation
month++;
totalperiod++;
i++;
}
}
---------------------------------------------------------------------
Output
Please enter the principal amount: 15000
Please enter annual interest rate: 7.5
Please enter term year of loan: 5
-----------------------------------------
Year Month Interest Principal Balance|INTEREST PRINCIPAL
---------------------------------------
1 1 93.75 206.819 14793.2
93.75 206.819 2 92.4574 208.112 14585.1
186.207 414.931 3 91.1567 209.413 14375.7
277.364 624.344 4 89.8479 210.721 14164.9
367.212 835.065 5 88.5308 212.038 13952.9
455.743 1047.1 6 87.2056 213.364 13739.5
542.948 1260.47 7 85.8721 214.697 13524.8
628.82 1475.16 8 84.5302 216.039 13308.8
713.351 1691.2 9 83.18 217.389 13091.4
796.531 1908.59 10 81.8213 218.748 12872.7
878.352 2127.34 11 80.4541 220.115 12652.5
958.806 2347.46 12 79.0784 221.491 12431.1
-----------------------------------------
Year Month Interest Principal Balance|INTEREST PRINCIPAL
---------------------------------------
1 2 77.6941 222.875 12208.2
1115.58 2791.82 2 76.3011 224.268 11983.9
1191.88 3016.09 3 74.8994 225.67 11758.2
1266.78 3241.76 4 73.489 227.08 11531.2
1340.27 3468.84 5 72.0698 228.499 11302.7
1412.34 3697.34 6 70.6416 229.928 11072.7
1482.98 3927.27 7 69.2046 231.365 10841.4
1552.18 4158.63 8 67.7586 232.811 10608.6
1619.94 4391.44 9 66.3035 234.266 10374.3
1686.25 4625.71 10 64.8393 235.73 10138.6
1751.09 4861.44 11 63.366 237.203 9901.36
1814.45 5098.64 12 61.8835 238.686 9662.67
-----------------------------------------
Year Month Interest Principal Balance|INTEREST PRINCIPAL
---------------------------------------
1 3 60.3917 240.178 9422.5
1936.73 5577.5 2 58.8906 241.679 9180.82
1995.62 5819.18 3 57.3801 243.189 8937.63
2053 6062.37 4 55.8602 244.709 8692.92
2108.86 6307.08 5 54.3307 246.238 8446.68
2163.19 6553.32 6 52.7918 247.777 8198.9
2215.98 6801.1 7 51.2431 249.326 7949.58
2267.22 7050.42 8 49.6849 250.884 7698.69
2316.91 7301.31 9 48.1168 252.452 7446.24
2365.02 7553.76 10 46.539 254.03 7192.21
2411.56 7807.79 11 44.9513 255.618 6936.59
2456.52 8063.41 12 43.3537 257.216 6679.38
-----------------------------------------
Year Month Interest Principal Balance|INTEREST PRINCIPAL
---------------------------------------
1 4 41.7461 258.823 6420.55
2541.62 8579.45 2 40.1285 260.441 6160.11
2581.74 8839.89 3 38.5007 262.069 5898.04
2620.24 9101.96 4 36.8628 263.706 5634.34
2657.11 9365.66 5 35.2146 265.355 5368.98
2692.32 9631.02 6 33.5561 267.013 5101.97
2725.88 9898.03 7 31.8873 268.682 4833.29
2757.77 10166.7 8 30.2081 270.361 4562.93
2787.97 10437.1 9 28.5183 272.051 4290.88
2816.49 10709.1 10 26.818 273.751 4017.12
2843.31 10982.9 11 25.107 275.462 3741.66
2868.42 11258.3 12 23.3854 277.184 3464.48
-----------------------------------------
Year Month Interest Principal Balance|INTEREST PRINCIPAL
---------------------------------------
1 5 21.653 278.916 3185.56
2913.45 11814.4 2 19.9098 280.659 2904.9
2933.36 12095.1 3 18.1556 282.414 2622.49
2951.52 12377.5 4 16.3906 284.179 2338.31
2967.91 12661.7 5 14.6144 285.955 2052.36
2982.53 12947.6 6 12.8272 287.742 1764.61
2995.35 13235.4 7 11.0288 289.54 1475.07
3006.38 13524.9 8 9.21921 291.35 1183.72
3015.6 13816.3 9 7.39827 293.171 890.553
3023 14109.4 10 5.56595 295.003 595.549
3028.56 14404.5 11 3.72218 296.847 298.702
3032.29 14701.3 12 1.86689 298.702 0
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.