Welcome to Dream.In.Code
Become a C++ Expert!

Join 136,907 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,764 people online right now. Registration is fast and FREE... Join Now!




Inheritance help

 
Reply to this topicStart new topic

Inheritance help

needc++help
16 Mar, 2008 - 01:59 PM
Post #1

New D.I.C Head
*

Joined: 16 Mar, 2008
Posts: 3

I'm not really sure where to go with this one. The object of the program is to calculate the loan payment given the input of the annual interest rate, term, and amount. I know the calculation part of it is correct because I've used it before. However, I cannot incorporate it in an inheritance set up. Please help.

MY BASE CLASS IS...
CODE
#include <iostream>
#include "justin.h"
#include <math.h>
using namespace std;

void main ()
{
float Amt, AR, i, n;

cout << "Enter the amount of money borrowed ";
cin >> Amt;

cout << "Enter the annual interest rate in percentage form ";
cin >> AR;

i = AR/1200;

cout << "Enter the term in months ";
cin >> n;

Final Loan(Amt, AR, i, n);

cout << "The monthly payment of your loan is "<<Loan.calculate_loan<<endl;

cout << "The specifications you entered of the Amount, Annual Rate, and Term are "<<endl;
Loan.display_loan()<<"respectively"<<endl;
}


MY DERIVED CLASS IS...
CODE
#include <iostream>
#include <math.h>
using namespace std;

class Final
{
public:
Final();
Final(float, float, float, float);
float calculate_loan(float);
void display_loan();

private:
float Amount;
float Annual_rate;
float monthly_rate;
float term;
};

Final::Final(float AMT, float ar, float I, float N)
{
Amount = AMT;
Annual_rate = ar;
monthly_rate = I;
term = N;
}

float Final::calculate_loan(float MP)
{
return MP = (i +(i/((pow((1 + i),n))-1))) * Amt;
}

void Final::display_loan()
{
cout <<Amount<<","<<Annual_rate<<","<<term<<endl;
}

User is offlineProfile CardPM
+Quote Post

KYA
RE: Inheritance Help
17 Mar, 2008 - 12:56 AM
Post #2

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 5,003



Thanked: 118 times
Dream Kudos: 1200
My Contributions
It looks like you never create the Final object, you just say Final Loan(parameters). Does this even compile for you?
User is online!Profile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/3/08 09:51PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month