Hi I am working on a project to get two classes to work with each other but I am getting
'Mortgage::fixedMonthlyPayment': illegal call of non-static member function
PLEASE HELP I am having a lot of trouble getting this thing to work.
my code is below:
Code:
//MortgageSchedule.cpp
#include <iostream>
#include <iomanip>
using namespace std;
#include <fstream>
MortgageSchedule::MortgageSchedule(Mortgage m)
{
Mortgage();
return;
}
void MortgageSchedule::setFileName(String s)
{
return;
}
void MortgageSchedule::displayOnConsole(void)
{
for(int i=1; i<= Mortgage::mortgageTerm(); i++)
{
double a = Mortgage::fixedMonthlyPayment();
Mortgage;
Total_Amount_Paid += a;
Mortgage::makeMonthlyPayment();//not saved in variable
Check_Total_Interest_Paid += Mortgage::monthlyInterest();
}//End for
cout<< setw(65) << "Full Mortgage Summary Report\n"
<< setw(60) << "----------------------------------------\n"
<< setw(10)<<"Total Amount Paid"<<setw(20)<<"Total Interest Paid\n"
<< setw(9) <<"$"<<Total_Amount_Paid
<< setw(19) <<"$"<<Mortgage::interestPaidSoFar()
<< setw(19) <<"check$"<<Check_Total_Interest_Paid;
return;
}
void MortgageSchedule::writeToFile(void)
{
return;
}
void MortgageSchedule::setPeriod(char c)
{
Choice=c;
return;
}
Code:
//MortgageSchedule.h
//Filename: MortgageSchedule.h
#ifndef MortgageSchedule_H
#define MortgageSchedule_H
#include "mortgage.h"
#include "..\INCLUDE\str.h"
class MortgageSchedule
{
public:
void setPeriod(char c);
// y yearly display
// m monthly display
// s summary display
// default: summary display
void setFileName(String s);
// Sets diskfile name for output.
void displayOnConsole(void);
// Writes the schedule to the console
// Period must be set by a previous message,
// otherwise the a default schedule is used.
void writeToFile(void);
// Same as displayToConsole
// Except results are written to a
// disk file which is set by a previous setFileName message.
// In case no previous message is sent. Output goes to "practice.txt".
String retrieveDiskFileName(void)const;
MortgageSchedule(Mortgage anyMortgage);
private:
char Choice;
double Total_Amount_Paid;
double Check_Total_Interest_Paid;
/* You do this part*/
};
#endif
this is the mortgage class---------This is what I am trying to access
Code:
// Filename: mortgage.cpp
// Abbreviate to work with Tutorial
#include "mortgage.h"
#include <math.h>
const int Mortgage::DEFAULT_TERM = 30;
const double Mortgage :: DEFAULT_LOAN = 40000.00;
const double Mortgage :: DEFAULT_RATE = 0.10;
void Mortgage::makeMonthlyPayment(void)
{
double interestDue, paymentToPrincipal;
interestDue = monthlyInterestRate * remainingLoan;
paymentToPrincipal = monthlyPayment-interestDue;
remainingLoan = remainingLoan - paymentToPrincipal;
monthlyInterestPayment = interestDue;
totalInterest += interestDue;
return;
}
double Mortgage::rate(void) const
{
return 12 * monthlyInterestRate;
}
double Mortgage::originalLoan(void) const
{
return initialLoan;
}
double Mortgage::remainingPrincipal(void) const
{
return remainingLoan;
}
double Mortgage::marketValue(void) const
{
return initialLoan - remainingLoan;
}
double Mortgage::monthlyInterest(void) const
{
return monthlyInterestPayment;
}
double Mortgage::interestPaidSoFar(void) const{
return totalInterest;
}
double Mortgage::fixedMonthlyPayment(void) const
{
return monthlyPayment;
}
int Mortgage::mortgageTerm(void) const
{
return term;
}
Mortgage::Mortgage(double principal,double yearlyInterestRate,
int lengthOfTermInYears)
{
term = lengthOfTermInYears;
initialLoan = principal;
remainingLoan = principal;
monthlyInterestRate = yearlyInterestRate/12;
monthlyPayment = this->computeMonthlyPayment();
//Interest payments commence with monthly payments.
monthlyInterestPayment = 0;
totalInterest = 0;
return;
}
Mortgage::Mortgage(void)
{
term = DEFAULT_TERM;
initialLoan = DEFAULT_LOAN;
remainingLoan = DEFAULT_LOAN;
monthlyInterestRate = DEFAULT_RATE/12;
monthlyPayment = this -> computeMonthlyPayment();
//Interest payments commence with monthly payments.
monthlyInterestPayment = 0;
totalInterest = 0;
return;
}
Mortgage:: ~Mortgage(void)
{
return;
}
double Mortgage::computeMonthlyPayment(void)
{
double temp1,temp2,temp3;
double answer;
int n = term*12;
temp1 = (1+monthlyInterestRate);
temp2 = pow(temp1,n);
temp3 = monthlyInterestRate/(temp2-1);
answer = temp3 * temp2 * initialLoan;
return answer;
}