You are to generate and print the first 8 rows and the last
You are to generate and print the first 8 rows and the last 8 rows of a complete amortization table, very similar to the one shown below (including the dashes). You are to have (and reference), at least, 1 function (other than main) in your program. Sample output: ------------------------------------------------------------------------- | Principal 70000.00 Interest Rate 9.5000 Years 30.0 Payment 588.60 | | | | Month Pay Total Monthly Principal Total Remaining | | Paid Interest Paid Principal Balance | | Paid | | | | 1 588.60 588.60 554.17 34.43 34.43 69965.57 | | 2 588.60 1177.20 553.89 34.70 69.14 69930.86 | | 3 588.60 1765.79 553.62 34.98 104.11 69895.89 | | 4 588.60 2354.39 553.34 35.26 139.37 69860.63 | | 5 588.60 2942.99 553.06 35.53 174.90 69825.10 | | 6 588.60 3531.59 552.78 35.82 210.72 69789.28 | | 7 588.60 4120.19 552.50 36.10 246.82 69753.18 | | 8 588.60 4708.78 552.21 36.39 283.20 69716.80 | | - - - - - - - | | 353 588.60 207775.07 35.98 552.61 66007.25 3992.75 | | 354 588.60 208363.67 31.61 556.99 66564.24 3435.76 | | 355 588.60 208952.27 27.20 561.40 67125.64 2874.36 | | 356 588.60 209540.87 22.76 565.84 67691.48 2308.52 | | 357 588.60 210129.47 18.28 570.32 68261.80 1738.20 | | 358 588.60 210718.06 13.76 574.84 68836.64 1163.36 | | 359 588.60 211306.66 9.21 579.39 69416.03 583.97 | | 360 588.60 211895.26 4.62 583.97 70000.00 0.00 | ------------------------------------------------------------------------- Notes: Generate the table so that you would get valid output for a 30 year loan or a 5 year loan. Formatting in C++ is rather involved. You want to make sure that the periods (in the numbers) line up. Before you start printing, you should specify the number of decimal places to be printed. You should also specify that the numbers should be printed in fixed format. You only have to do this once. cout << setprecision(2) << fixed To print a variable \'var\', right justified, in 10 columns, use the following. cout << setw(10) << var; setw is used to specify the number of columns setprecision is used to specify the number of decimal places. fixed is used to specify that the number is NOT to be printed in scientific notation. To use the preceding formatting options, you will need the following preprocessor command at the top of your program. #include <iomanip>
Solution
#include<iostream>
 #include<iomanip>
 using namespace std;
 float interest(float p,float r)
 {
    return p*(1+r/1200)-p;
 }
 int main()
 {
    float principal,interest_rate,years,payment,tot_intr,rem_balance,tot_paid,prin_paid,tot_prin_paid;
     cout << setprecision(2) << fixed;
    cout<<\"Enter Principal_amount : \";
    cin>>principal;
    cout<<endl;
    cout<<\"Enter interest_rate : \";
    cin>>interest_rate;
    cout<<endl;
    cout<<\"Enter tenure : \";
    cin>>years;
    cout<<endl;
    cout<<\"Enter Monthly_payment : \";
    cin>>payment;
    cout<<endl;
    rem_balance=principal;
    cout<<setw(5)<<\"Month\"<<setw(15)<<\"Pay\"<<setw(15)<<\"Total Paid\"<<setw(15)<<\"Month_Intr\"<<setw(15)<<\"Principal Paid\"<<setw(15)<<\"Total_Prin_Paid\"<<setw(15)<<\"Rem_Balance\"<<endl;
     for(int i=1;i<=years*12;i++)
    {
    tot_intr=interest(rem_balance,interest_rate);
    tot_paid=tot_paid+payment;
    prin_paid=payment-tot_intr;
    tot_prin_paid+=prin_paid;
    rem_balance=principal-tot_prin_paid;
    if(i<9 || i>years*12-8)
    cout<<setw(5)<<i<<setw(15)<<payment<<setw(15)<<tot_paid<<setw(15)<<tot_intr<<setw(15)<<prin_paid<<setw(15)<<tot_prin_paid<<setw(15)<<rem_balance<<endl;
     if(i==9)
    cout<<\"------------------------------------------------------------------------------------------------\"<<endl;
  }
   
   
 }

