Undefined Base Class?

Been trying to figure this out, please help:

Here's the main driver:

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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <iomanip>   // set precision and column widths
#include <math.h>    // math functions
#include <exception>
#include <string>
using namespace std;

#include "AmortizationCalculatorLab04.h"
#include "Exception.h"

 const int PERIODS_PER_YEAR(12);
 const int COLUMN_WIDTH(20);
 const int ROWS_TO_PRINT(20);

void pauseDisplay();

class LoanCalculator
{
private:
   int myNumberOfPayments;
   double myLoanAmount;
   double myAnnualInterestRate;
   double myMonthlyPayment;
public:
	void getInput()
	{
		system("cls");

		cout << "Welcome to the Loan Calculator Program!" << endl << endl;

		bool inputOkay = false;

		cout << "Enter the loan amount (ex. 300,000.00):  ";
		cin >> myLoanAmount;
		inputOkay = true;   

		cout << endl;

		while ((!inputOkay) && (cin >> myLoanAmount))
		{
			try
			{
				if (myLoanAmount <= 0)
				{
				  throw ExceptionLessThanZero();
				}
				else
				{
                   inputOkay = true;
				}
			}
			catch (ExceptionLessThanZero &e)
			{
			cout << "Exception occurred: " << e.getMessage() << '\n';
                cout << "Enter the loan amount (ex. 25000.00):  ";
			}
	    }

		cout << "Enter the annual interest rate (ex. 0.06):  ";  
		cin >> myAnnualInterestRate;

		cout << endl;

		cout << "Enter the total number of monthly payments(ex. 72):  ";
		cin >> myNumberOfPayments;

		cout << endl;
	}

	double calculateMonthlyPayment()
	{
		myMonthlyPayment =
			((myAnnualInterestRate / PERIODS_PER_YEAR) * myLoanAmount) /
			(1 - pow((1 + myAnnualInterestRate/PERIODS_PER_YEAR),(-1 * myNumberOfPayments)));
		return myMonthlyPayment;
	}

	void displayResults()
	{
		cout << setprecision(2) << fixed;
		cout << "Your monthly payment is $" << myMonthlyPayment << endl << endl;
		pauseDisplay();
    }

	double getMyLoanAmount()
	{
		return myLoanAmount;
	}
	double getMyAnnualInterestRate()
	{
		return myAnnualInterestRate;
	}
	int getMyNumberOfPayments()
	{
		return myNumberOfPayments;
	}
};

int main()
{
	LoanCalculator myLoanCalculator;
	myLoanCalculator.getInput();
	myLoanCalculator.calculateMonthlyPayment();
	myLoanCalculator.displayResults();

	AmortizationCalculator myMortgage;
	cout <<myMortgage.getMortgageTerm() <<endl;

	pauseDisplay();

    double oldBalance(myLoanCalculator.getMyLoanAmount());
    double newBalance(myLoanCalculator.getMyLoanAmount());
    int timePeriod(0);
    double periodicInterestRate = myLoanCalculator.getMyAnnualInterestRate() / 12.0;
    double interestPaid(0.0);

   while(timePeriod < myLoanCalculator.getMyNumberOfPayments())
   {
      if (timePeriod % ROWS_TO_PRINT == 0)
      {
         system("cls");
         cout << setw(COLUMN_WIDTH/2) << "PERIOD";
         cout << setw(COLUMN_WIDTH) << "INTEREST_PAID($)";
         cout << setw(COLUMN_WIDTH) << "PRINCIPLE_PAID($)";
         cout << setw(COLUMN_WIDTH) << "NEW_BALANCE($)" << endl;
      }
      timePeriod++;
      interestPaid = periodicInterestRate * oldBalance;
	  newBalance = (1+periodicInterestRate)* oldBalance - myLoanCalculator.calculateMonthlyPayment();

      if (newBalance < .01)
      {
        newBalance = 0.0;
      }

      cout << setprecision(2) << fixed;
      cout << setw(COLUMN_WIDTH/2) << timePeriod;
      cout << setw(COLUMN_WIDTH) << interestPaid;
	  cout << setw(COLUMN_WIDTH) << myLoanCalculator.calculateMonthlyPayment() - interestPaid;
      cout << setw(COLUMN_WIDTH) << newBalance << endl;

      if (timePeriod % 20 == 0)
      {
         pauseDisplay();
      }

      oldBalance = newBalance;
   }

   return 0;
}

void pauseDisplay()
{
   cout << "Press <enter> to continue...";
   cin.ignore(1);
}


Here is the referenced header file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#ifndef AMORTIZATIOMCALCULATORLAB04_H
#define AMORTIZATIOMCALCULATORLAB04_H

class AmortizationCalculator: public LoanCalculator
{
public:

int getMortgageTerm()
{
MortgageTerm = myNumberOfPayments / 12;
return MortgageTerm;
}

private:
	int MortgageTerm;
};
#endif  


Keep getting these:

Error 2 error C2065: 'myNumberOfPayments' : undeclared identifier c:\users\edgar\documents\visual studio 2008\projects\lab04\lab04\amortizationcalculatorlab04.h 10

Error 1 error C2504: 'LoanCalculator' : base class undefined c:\users\edgar\documents\visual studio 2008\projects\lab04\lab04\amortizationcalculatorlab04.h 5


Thank You
You have two classes here. AmortizationCalculator and LoanCalculator. LoanCalculator is a dependency of AmortizationCalculator, and therefore must be defined first. However you're defining it after, which is what is giving you the errors.

Either move the #include "AmortizationCalculatorLab04.h" to a line below your LoanCalculator class definition, or put your LoanCalculator in its own header and #include it before you #include "AmortizationCalculatorLab04.h".
Topic archived. No new replies allowed.