Answer to Question #321449 in C++ for North

Question #321449

Implementing using

class Loan


Sample Run:

Enter yearly interest rate, for example 8.25: 10

Enter number of years as an integer, for example 5: 5

Enter loan amount, for example 120000.95: 300000

The monthly payment is 6374.11

The total payment is 382446.80



1
Expert's answer
2022-05-18T15:27:19-0400
#include<iostream>

using namespace std;




 class Loan{

    private:

      double rate;

      int years;

      double ammount;

    

    public:

      void enterRate(double r){

        this->rate=r;

      }

      void enterYears(int y){

        this->years=y;

      }

      void enterAmmount(double a){

        this->ammount=a;

      }

       

      double getMonthlyPayment(){

        return ammount*(1+rate/100)/years*12;

      }

      double getTotalPayment(){

        return ammount*(1+rate/100);

      }

  };




int main(){

// test

  Loan test;

  int tempi; double tempd;

  cout<<"Ammount:";

  cin>>tempd;

  test.enterAmmount(tempd);   




  cout<<"Rate:";

  cin>>tempd;

  test.enterRate(tempd);

  

  cout<<"Years:";

  cin>>tempi;

  test.enterYears(tempi);

   

  cout<<"Monthly payment is:"<<test.getMonthlyPayment()<<endl;

  cout<<"Total payment is:"<<test.getTotalPayment()<<endl;

   

  return 0;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog