compiling error with classes

This is a discussion on compiling error with classes within the C++ Programming forums, part of the General Programming Boards category; I'm getting an error with my class program. Does anyone know how to fix this? #include <iostream> using namespace std; ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    13

    compiling error with classes

    I'm getting an error with my class program. Does anyone know how to fix this?

    #include <iostream>
    using namespace std;


    //class for a bank certificate of deposit:
    class CDAccount
    {
    public:
    CDAccount(double rate_fraction, double interest, double account);
    CDAccount();
    void get_data();
    void putout();
    void calculate();
    private:
    double balance;
    double interest_rate;
    int term;//months until maturity
    };


    CDAccount account;


    int main( )
    {
    account.get_data();
    account.calculate();
    account.putout();

    return 0;
    }

    void CDAccount::get_data()
    {
    cout << "Enter account balance: $";
    cin >>account.balance;
    cout << "Enter account interest rate: ";
    cin >> account.interest_rate;
    cout << "Enter the number of months until maturity\n"
    << "(must be 12 or fewer months): ";
    cin >>account.term;
    }

    void CDAccount::calculate()
    {
    double rate_fraction, interest;
    rate_fraction = account.interest_rate/100.0;
    interest = account.balance*rate_fraction*(account.term/12.0);
    account.balance = account.balance + interest;
    }

    void CDAccount:utout()
    {


    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);

    cout << "When your CD matures in "
    << account.term << " months,\n"
    << "it will have a balance of $"
    << account.balance << endl;

    }

    /*
    --------------------Configuration: seven - Win32 Debug--------------------
    Linking...
    seven.obj : error LNK2001: unresolved external symbol "public: __thiscall CDAccount::CDAccount(void)" (??0CDAccount@@QAE@XZ)
    Debug/seven.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

    seven.exe - 2 error(s), 0 warning(s)
    */

  2. #2
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    Implement constructors for CDAccount.

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    13
    thank you. i'm suppose to use a default constructor, does that make a difference?

  4. #4
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343

    thank you. i'm suppose to use a default constructor, does that make a difference?


    If you are going to use a default constructor then you don't have to specify one, the compiler does it for you

    Uncomment
    Code:
    CDAccount(double rate_fraction, double interest, double account);
    CDAccount();
    in the class definition.

  5. #5
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    Originally posted by ripper079

    If you are going to use a default constructor then you don't have to specify one, the compiler does it for you
    I would recommend writing your own, then you know exactly whats going on every time. And sometimes you dont want all those data members set to 0
    Couldn't think of anything interesting, cool or funny - sorry.

  6. #6
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    Originally posted by endo

    I would recommend writing your own, then you know exactly whats going on every time. And sometimes you dont want all those data members set to 0
    I totaly agree, but a closer look at the member-function get_data(), initialization (made by constructor) seems redundant. I know that there is a potential risk that the object is beeing used before initialized but the first code line i main is actually an invoke to the member-function get_data(). This is a design issue that the programmer must consider.

    zeni3773
    But if you want to do it the "right" (my) way I would definitly write the implementation for
    Code:
    CDAccount(double rate_fraction, double interest, double account);
    CDAccount();
    This way you can be sure that all data-members have been properly initialized and at the same time add more flexibility to yours class.
    Last edited by ripper079; 10-14-2002 at 04:31 PM.

  7. #7
    Registered User
    Join Date
    Oct 2002
    Posts
    13
    thank you both for your help! i made a few changes to the program and it's working now!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Errors compiling classes with VC++ 6.0
    By xErath in forum C++ Programming
    Replies: 2
    Last Post: 07-02-2004, 07:58 AM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM

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