Question
C++ Add an input function and output formatting function in accordance with the requirements below in the following code. 1. Limit the maximum Loan Amount
C++
Add an input function and output formatting function in accordance with the requirements below in the following code.
1. Limit the maximum Loan Amount to $98,000.00
2. Accept the interest rate (4.5% as 4.5), and limit the interest rate to 19% maximum
3. Limit the Loan Duration to 6 years (using whole years)
4. Validate all input values for any error (non-digit, zero or negative values, etc.)
5. Echo the inputs with titles and the formatting specified in 6 and 7
6. Add commas to the output values for thousands, and millions.
7. Add a percent sign for the interest rate
8. Left align the titles, and right align the values
9. Space everything for alignment as shown
Code that needs to be edited.
#ifndef MORTGAGE_H
#define MORTGAGE_H
class Mortgage
{
private:
double LnAmt,
AnnIntRate,
MoIntRate,
years;
int NumPmts;
double term() const;
public:
Mortgage()
{
LnAmt = AnnIntRate = MoIntRate = years = NumPmts = 0;
}
void setLoanAmt(double);
void setRate(double);
void setYears(double);
double getMonthly() const;
double getPayBack() const;
};
#endif
#include
#include
#include
#include "Mortgage.h"
using namespace std;
double Mortgage::getMonthly() const
{
if (MoIntRate == 0.0)
return LnAmt / NumPmts;
else
return (LnAmt * (MoIntRate)* term()) / (term() - 1);
}
double Mortgage::term() const
{
return pow(1 + (MoIntRate), NumPmts);
}
double Mortgage::getPayBack() const
{
return (getMonthly() * NumPmts);
}
void Mortgage::setLoanAmt(double amt)
{
if (amt < 0)
{
cout << "Invalid loan amount. ";
exit(EXIT_FAILURE);
}
LnAmt = amt;
}
void Mortgage::setRate(double rate)
{
if (rate < 0)
{
cout << "Invalid interest rate. ";
exit(EXIT_FAILURE);
}
AnnIntRate = rate;
MoIntRate = rate / 12;
}
void Mortgage::setYears(double yrs)
{
if (yrs < 0)
{
cout << "Invalid number of years. ";
exit(EXIT_FAILURE);
}
years = yrs;
NumPmts = yrs * 12;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started