Does anyone have the time to help with inheritance on this program?
Thank you.
#include <iostream>
#include <cmath>
using std::cout; using std::cin; using std::endl; using std::pow;
class Mortgage
{
private:
double loan, rate;
short years;
public:
Mortgage() = default;
void setLoan(double l) { loan = l; }
void setRate(double r) { rate = r; }
void setYears(short y) { years = y; }
double getMonthlyDue(double term) { return ((loan * (rate / 12) * term) / (term - 1)); }
double getTotalDue(double term) { return (getMonthlyDue(term) * years); }
};
int main()
{
Mortgage mort1;
double term, loan, rate;
int years;
cout << "Mortgage Amount: ";
while (!(cin >> loan) || loan < 0)
cout << "Loan amount cannot be negative. Enter the amount: ";
mort1.setLoan(loan);
cout << "Mortgage Interest Rate: ";
while (!(cin >> rate) || rate < 0)
cout << "Interest rate cannot be negative. Enter the amount: ";
mort1.setRate(rate);
cout << "How Many years will the loan be?: ";
while (!(cin >> years) || years < 0)
cout << "Loan period cannot be negative. Enter the amount: ";
mort1.setYears(years);
term = pow((1 + (rate / 12)), (12 * years));
int choice = 0;
while (choice != 3)
{
cout << endl;
cout << "1. Monthly Payment" << endl <<
"2. Total Payment" << endl <<
"3. Exit" << endl << endl <<
"Enter an option above: ";
cin >> choice;
if (choice == 1)
cout << "Monthly payment is " << mort1.getMonthlyDue(term) << "." << endl;
else if (choice == 2)
cout << "Total payment due is " << mort1.getTotalDue(term) << "." << endl;
}
}
Wow. Your the man! Thanks so much Eric!