class inheritance bank account

You have been developing a BankAccount class for Parkville Bank that contains several fields and functions.

a. Create BankAccount contains only an account number and a balance.
b. Create a class named SavingsAccount that descends from BankAccount. Include
an interest rate field that is initialized to 3 percent when a SavingsAccount is
constructed.
c. Create a class named CheckingAccount that descends from BankAccount. Include
two new fields including a monthly fee and the number of checks allowed per month;
both are entered from prompts within the constructor.
d. Write a main()function to demonstrate the SavingsAccount and CheckingAccount
classes. Save the file as CheckingAndSavings.cpp.
e. Add a constructor for the SavingsAccount class that requires a double argument that
is used to set the interest rate. Create a class named CheckingWithInterest that descends from both SavingsAccount and CheckingAccount. This class provides for special interest-bearing checking accounts. When you create a CheckingWithInterest object, force the interest rate to .02, but continue to prompt for values for all the other fields. Create an array of five CheckingWithInterest accounts, prompt the user for values for each, and display the accounts. Save the file as CheckingWithInterest.cpp.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<iostream>
using namespace std;

class BankAccount
{
public:
	void setAccountNum();
	void setCurrentBal();

private:
	int accountNum;
	int currentBalance;

};

class SavingsAccount: public BankAccount
{


};


class CheckingAccount: public BankAccount
{


};


class CheckingWithInterest: public SavingsAccount, public CheckingAccount
{


};


int main()
{



}


Am i doing this correct?
So far, it looks good.
I'm actually a beginner. I don't know how to do the "Create a class named SavingsAccount that descends from BankAccount. Include
an interest rate field that is initialized to 3 percent when a SavingsAccount is
constructed. " could someone help me?
You are inheriting right. To create a constructor, just have a function with the exact same name as the class, but without a return type. For instance:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class MyRandomClass : public ClassToInheritFrom {              
public:
         MyRandomClass(int some, char* arguments) {
                 /* This is a constructor, the code here will be run when
                  * an instance of MyRandomClass is created.
                  */
         }

         ~MyRandomClass() {
                 /* This is a destructor, the code here will be run when
                  * an instance of MyRandomClass is deleted.
                  */ 
         }
}
Last edited on
You may have to use virtual inheritance here.

http://stackoverflow.com/questions/419943/virtual-inheritance
Topic archived. No new replies allowed.