Homework Help

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;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <cmath>

using std::cout; using std::cin; using std::endl; using std::pow;

class Loan
{
protected:
	double loan, rate;
	short years;
	Loan() 
		: loan(0)
		, rate(0)
		, years(0)
	{
	}
public:
	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); }
};
class Mortgage : public Loan
{
public:
	Mortgage() : Loan(){}
};

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!
ur welcome
Topic archived. No new replies allowed.