Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- class Loan
- {
- private:
- double total(int i);
- double principal;
- double interestRate;
- double Balance(int i);
- double Instalment ();
- double Interest (int i);
- int numPayments;
- public:
- Loan (double amount, double interestRate, int numPayments);
- void displaySchedule(double amount, double interestRate, int numPayments);
- };
- void readData(double& principal, double& interestRate, int& numPayments)
- {
- cout <<"Principal: ";
- cin >>principal;
- cout <<"Interest rate: ";
- cin >>interestRate;
- cout <<"Number of payments: ";
- cin >>numPayments;
- cout <<endl;
- }
- Loan::Loan(double p, double ir, int np)
- {
- principal = p;
- interestRate= ir;
- numPayments= np;
- }
- double Loan::Instalment()
- {
- return principal / numPayments;
- }
- double Loan::total(int i)
- {
- return Instalment() + Interest(i);
- }
- double Loan::Balance(int i)
- {
- return principal - (i-1) * Instalment();
- }
- double Loan::Interest(int i)
- {
- return Balance(i) * (interestRate/12) / 100;
- }
- void Loan::displaySchedule(double amount, double interestRate, int numPayments)
- {
- cout.setf(ios::fixed);
- cout.precision(2);
- cout.setf(ios::showpoint);
- cout << "No."<<setw(15)<<"Balance"<<setw(15)<<"Instalment"<<setw(15)<<"Interest"<<setw(15)<<"Total payment" << endl;
- cout << "----------------------------------------------------------------"<<endl;
- for (int i=1; i<=numPayments; i++)
- {
- cout <<i<<setw(15)<< Balance(i)<<setw(15)<<Instalment()<<setw(15)<<Interest(i)<<setw(15)<<total(i)<<endl;
- }
- cout <<"----------------------------------------------------------------"<<endl;
- double total_instalment;
- double total_interest;
- for (int i=1; i <=numPayments; i++)
- {
- total_instalment += Instalment();
- total_interest += Interest(i);
- }
- cout <<setw(33q)<<total_instalment <<setw(15)<< total_interest;
- }
- int main()
- {
- double principle, interestRate;
- int numPayments;
- readData(principle, interestRate, numPayments);
- Loan myLoan(principle, interestRate, numPayments);
- myLoan.displaySchedule(principle, interestRate, numPayments);
- return 0;
- }
- /*
- afborgun = höfuðstóll / fjöldi afborgana
- instalment = principal / number of payments
- vaxtaupphæð = eftirstöðvar höfuðstóls * (vaxtaprósenta/12) / 100
- interest = remainder of principal * (interest rate/12) / 100
- eftirstöðvar höfuðstóls við greiðslu nr. x = höfuðstóll - (x-1)*afborgun
- balance = principal - (x-1) * instalment */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement