I have been Learning about Base and Derive Classes in my C++ class and on a recent assignment, my professor instructions are confusing me when creating one of the Set functions in the Derived Class source file.
"Every three months CD duration will increase the CDannualInterestRate by 0.5% from the annualInterestRate of the base class. For example: if annualInterestRate is 3%, the CDannualInterestRate will be 3.5% of a three-months CD saving account, and the CDannualInterestRate will be 4% of a six-month CD."
My Base class is called, "Account" and my Derived Class is, "CDAccount"
When asking what my professor what she ment,the only hint she gave was this:
I have tried to use this line of code within my Derived class source file (CDAccount.cpp) but I keep getting the error "Account::annualInterestRate is inaccessible" even though I included the #include "Account.h" and #include "CDAccount.h" library headers in both the Base and Derived class source and header files. I also did define "Account::annualInterestRate" function in the header file aswell. What am I doing wrong?
I'm working on the presumption that your tutor gave you a "hint". You describe this as a line of code but really its a line of psuedo-code, never intended to compile, you need to translate into your own context.
You need to think about what that hint is trying to do and code your own solution to do the same thing in your program. That probably wont result in the exact same code, but will perform the same operations.
the hint (probably deliberately) wont compile at all, "0.5(duration/3)" is obviously bad C++ both syntactically and semantically.
What that "hint" is doing is telling you what operations your program needs to perform, with that in mind you should be able to code your solution to do the same thing.
Is the access to annualInterestRate in the base class private (the default unless you tell it otherwise)? It would need to be protected (or, less ideally, public) if you want a derived class to access it.