Derived Class of Account Class - CDAccount

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:
 
setCDAnnaualInterestRate(Account::annualInterestRate + 0.5(duration / 3));


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?
Last edited on
please post your code so we can advice accordingly.

Thanks
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.

I'm looking at what you wrote here:
http://www.cplusplus.com/forum/beginner/224189/#msg1026208

Check out the error messages you would get with
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Account
{
   double ratePrivate = 0.1;
public:
   double ratePublic = 0.2;
protected:
   double rateProtected = 0.15;
};


class CDAccount : public Account
{
   double total;
public:
   CDAccount() { total = Account::ratePrivate + Account::ratePublic + Account::rateProtected; }
};


int main()
{
   CDAccount me;
}


Otherwise, I think we would have to see your code.
Last edited on
Topic archived. No new replies allowed.