![]() |
|
#1
|
|||
|
|||
savings account problemI am trying to write a savings account program, and i did what i thought was the right thing.
suprise suprise, when the program runs i get weird results, as if the class objects are not being initialised by the constructor, since it is giving me weirds "garbage" numbers? here are the class declaration and implementation files CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
Last edited by LuciWiz : 31-Mar-2005 at 23:20.
Reason: Correcting formating
|
|
#2
|
|||
|
|||
|
Quote:
**EDIT*** Note changes here What compiler are you using? Borland compilers give warnings: Quote:
(I thought that other compilers would also give warnings, but apparently not) Since your observation of program output makes you think the constructor is not initializing things properly, Look at your constructor: CPP / C++ / C Code:
This does nothing! (The argument savingsBalance is used as source and target of the assignment. Same for annualInterestRate.) You could do this: CPP / C++ / C Code:
or something like this: CPP / C++ / C Code:
Either will work. See the difference between these and what your constructor did? Regards, Dave Regards, Dave Last edited by davekw7x : 31-Mar-2005 at 17:36.
Reason: First was incomplete
|
|
#3
|
|||
|
|||
sorry i should have thought of thati am using visual studio 6
there are no compiler errors or warnings. just the output of the program are garbage numbers. exemple: saver1 is initialised as followes: balance = -9.25596+061 dollars blah blah blh |
|
#4
|
|||
|
|||
|
Quote:
I edited my previous post to show some possibilities. I'm sorry that I didn't say these things at first, but I somehow thought there might have been some useful compiler messages. Sorry. Try reading my edited post and see if it helps (and/or see if it makes sense). You definitely need to change your constructor Regards, Dave |
|
#5
|
|||
|
|||
again,i'm in your debt.thank you it worked fine.i saw the problem with the constructor.it was basicaly doing nothing.but it's allright now.
and another thing.i tried something else,i tried to declare annualInterestRate as a static and have get_rate function to be a static member function, but when i run the program i get this message from the compiler savingsaccount.obj : error LNK2001: unresolved external symbol "private: static double SavingsAccount::annualInterestRate" (?annualInterestRate@SavingsAccount@@0NA) Debug/savingsaccount.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. the lines i am referring to in the class declaration are: CPP / C++ / C Code:
ps: does anybody know of a better compiler than visual studio,it's eally getting on my nerves!! |
|
#6
|
|||
|
|||
|
Quote:
I don't see the point of trying to make a member function static. As for the variable: in SavingsAccount.h you have CPP / C++ / C Code:
Now, each instance of this class has its own savingsBalance, but there is only one annualInterestRate for all instances. This declaration does not actually allocate any memory for the variable. So in your SavingsAccount.cpp you have a line like this: CPP / C++ / C Code:
Now, you realize that if you change annualInterestRate for a particular object (in an initializer or any other function), it will change for all instances, right? Regards, Dave |
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem modifying an array of char in a function | ronin | C Programming Language | 10 | 28-Mar-2005 18:15 |
| windows user account | dexterwolf | CPP / C++ Forum | 1 | 04-Feb-2005 11:17 |
| Tee chart problem | Arun | CPP / C++ Forum | 0 | 01-Sep-2004 23:23 |
| Another FX 5600 problem (but with details that might shed light on this) | BobDaDuck | Computer Hardware Forum | 2 | 16-Apr-2004 07:53 |
| RE: A simple update and } problem | Dagma20 | MySQL / PHP Forum | 3 | 27-Mar-2004 16:37 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The