C++ Classes

This is a discussion on C++ Classes within the C++ Programming forums, part of the General Programming Boards category; I need some help with C++ classes. I can not get my Monthly payments and my Total pay back to ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    5

    Question C++ Classes

    I need some help with C++ classes. I can not get my Monthly payments and my Total pay back to print using a class for calculating a mortgage payment. I am not sure what I am doing wrong.

    I have tried a couple of things, but still can not seem to make it work. Below are the most recent errors I am getting.

    Any fixes to my code to get me back on track are appreciated.


    /The type of errors

    //C:\Program Files\Microsoft Visual Studio\MyProjects\tan\Ex13_6EX13_06.cpp(104) : error C2248: 'pay' : cannot access private member declared in class 'Payment'
    // C:\Program Files\Microsoft Visual Studio\MyProjects\tan\Ex13_6\EX13_06.cpp(19) : see declaration of 'pay'
    //C:\Program Files\Microsoft Visual Studio\MyProjects\tan\Ex13_6\EX13_06.cpp(106) : error C2248: 'pay' : cannot access private member declared in class 'Payment'
    // C:\Program Files\Microsoft Visual Studio\MyProjects\tan\Ex13_6\EX13_06.cpp(19) : see declaration of 'pay'
    //C:\Program Files\Microsoft Visual Studio\MyProjects\tan\Ex13_6\EX13_06.cpp(106) : error C2297: '*' : illegal, right operand has type 'float (__thiscall Payment::*)(void)'
    //Error executing cl.exe.

    //EX13_06.obj - 3 error(s), 0 warning(s)


    #include <iostream>
    #include <iomanip>
    #include <math.h>
    using namespace std;

    class Payment
    {
    private:
    float loan;
    float rate;
    float years;
    float payment;
    float term;
    float pay;
    float tm;

    public:
    float getLoan(void);
    float getRate(void);
    float getYears(void);
    void setData(float, float, float);
    float calcTerm(void);
    float calcPayment();

    };

    // SetData copies the argument to private members
    // loan, rate, years

    void Payment::setData(float l, float r, float y)
    {
    loan = l;
    rate = r;
    years = y;
    }

    // getLoan returns the value in the private member loan amt.

    float Payment::getLoan(void)
    {
    return loan;
    }

    // getRate returns the value in the private member rate amt.

    float Payment::getRate(void)
    {
    return rate;
    }

    // getYears returns the value in the private member years.

    float Payment::getYears(void)
    {
    return years;
    }


    float Payment::calcPayment()
    {
    payment = (loan * rate / 12.0 * term) / (term - 1.0);
    return pay;

    }

    float Payment::calcTerm()
    {

    term = pow((1 + rate / 12.0), 12.0 * years);
    return tm;
    }


    void main(void)
    {

    Payment mortgage;
    float mtg_loan;
    float mtg_rate;
    float mtg_years;


    cout << "Loan amount: $";
    cin >> mtg_loan;
    cout << "Annual Interest Rate (Enter .12 for 12%): ";
    cin >> mtg_rate;
    cout << "Years of loan: ";
    cin >> mtg_years;
    mortgage.setData(mtg_loan, mtg_rate, mtg_years);
    //mortgage.setDataoth(mtg_payment);

    //cout <<mortgage.getLoan() <<endl;
    cout << "Here is your data:\n" << endl << endl;
    cout <<"Loan amount: $" <<mortgage.getLoan() <<endl;
    cout <<"Annual Interest Rate: " << mortgage.getRate() <<endl;
    cout <<"Years of loan: " <<mortgage.getYears() << endl;
    //cin >> mortgage.getYears() <<endl;
    //what I want to do
    //cout << "Monthly payment: $" << payment << endl;
    cout << "Monthly payment: $" << mortgage.pay << endl;
    //what I want to do
    ////cout << "Total Pay Back: $" << (payment*years*12) << endl;
    cout <<"Total Pay Back: $" << (mortgage.pay*mortgage.getYears*12) <<endl;



    }

  2. #2
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Dude move it to the C++ Forum and use Code Tags..........
    Good luck by the way.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  3. #3
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    done
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  4. #4
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    When you do give pay or tm a value??

  5. #5
    Registered User JasonLikesJava's Avatar
    Join Date
    Mar 2002
    Posts
    175
    He's right, pay and tm don't have values. Returning payment and term instead should work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 11:47 AM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-24-2004, 12:22 AM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 08:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 04:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21