Answer to Question #320772 in C++ for Toby

Question #320772

Your task is to implement the class Loan with the following requirements:


• A member variable that will hold the annual interest rate of the loan. Its default value will be 2.5.


• A member variable that will hold the number of years for the loan. Its default value will be 1.


• A member variable that will hold the loan amount. Its default variable will be 1000.


• A default constructor.


• Another constructor that has interest rate, years, and loan amount as its parameters.


• A member function that returns the annual interest rate of this loan.


• A member function that returns the number of the years of this loan.


• A member function that returns the amount of this loan.


• A member function that sets a new annual interest rate to this loan.


• A member function that sets a new number of years to this loan.


• A member function that sets a new amount to this loan.


• A member function that returns the monthly payment of this loan.


• A member function that returns the total payment of this loan.

1
Expert's answer
2022-03-31T11:45:05-0400
#pragma once
#include <iostream>
using namespace std;

class Loan
{
private:
	double interestRate = 2.5; // Annual interest rate of the loan
	int numberOfYears = 1; // Number of years for the loan
	double loanAmount = 1000; // Loan amount

public:
	Loan() {}; 

	Loan(double _interestRate, int _numberOfYears, double _loanAmount) 
	{
		interestRate = _interestRate;
		numberOfYears = _numberOfYears;
		loanAmount = _loanAmount;
	}

	double getInterestRate()
	{
		return interestRate;
	}

	int getNumberOfYears()
	{
		return numberOfYears;
	}

	double getLoanAmount()
	{
		return loanAmount;
	}

	void setInterestRate(double _interestRate)
	{
		interestRate = _interestRate;
	}

	void setNumberOfYears(int _numberOfYears)
	{
		numberOfYears = _numberOfYears;
	}

	void setLoanAmount(double _loanAmount)
	{
		loanAmount = _loanAmount;
	}

	double getMonthlyPayment()
	{
		return loanAmount * (interestRate / (numberOfYears * 12));
	}

	double getTotalPayment()
	{
		return loanAmount * (interestRate / (numberOfYears * 12)) * (numberOfYears * 12);
	}
};

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