Questions about my classes and inheritance

Hello all,

after around a week trying to figure out one of the two homeworks I was assigned I decided to try the second of my two homeworks.

This one is considerably more complicated, but the biggest difference is that I'm not looking at the code someone else provided to me, but instead am building my own code.

The way this has to work is, I have a base class 'bankaccount' which has some basic stuff every other class must inherit from. someones name, account number, and balance. Then I have 3 sub classes called something like checkingaccounts, savingsaccounts and certificate of deposit. Each one of these has some functions other classes need to inherit from.

From there I diverge a little more. with 3 types of checking accounts. one is a service charge checking account, another is a non service charge checking account. both inheriting from the checking accounts class. And finally I have a high interest rate checking account which inherits from the noservice charge checking account.

I've only done the checking account tree of this so far, but given that its the biggest, the other two trees of this project will be much simpler. So get the hardest done and out of the way, then work on the easier of the two.

............................. Bank Accounts
.................................. |
........................... Checking Account
............................... / .... \
.................. Service charge .... no service
.................. checking .......... charge checking
............................................. |
..................................... High Interest Checking

heres what I typed so far:

My base class
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
#include <iostream>
#include <string>

using namespace std;

class Bankaccount
{
	int acctnum;
	double balance;
	string fName;
	string lName;

public:
	void setacct(int accountnum);
	int getacct();

	void setbal(int ammount);
	double getbal();

	void setfirst(string firstname);
	string getfirst();
	void setlast(string lastname);
	string getlast();

	virtual void makedeposits() = 0;
	virtual void makewithdraw() = 0;
	virtual void statement() = 0;
}


Not sure why, but intellisense is saying it was expecting a semicolon before the last bracket.

And here are my checking accounts classes:

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "BankAccountFunction.h"
#include <iostream>
#include <string>

using namespace std;

class checkingAcct : public Bankaccount
{
public:
	virtual void writeCheck() = 0;
};

class serviceChargecheck : public checkingAcct
{
	double minbalance = 0;
	double serviceCharge = 2.00;
	int checkcounter = 10;
public:

	void setacct(int accountnum);
	int getacct();

	void setbal(int ammount);
	double getbal();

	void setfirst(string firstname);
	string getfirst();
	void setlast(string lastname);
	string getlast();

	void makedeposits(double depositAmount);
	void makewithdraw(double withdrawAmount);
	void statement();
	void writeCheck(int checkcounter);

	serviceChargecheck();
	~serviceChargecheck();

};

class noSerivceChargeChecking : public checkingAcct
{
	double minBalance = 100.00;
	double interest = .02;
public:

	void setacct(int accountnum);
	int getacct();

	void setbal(int ammount);
	double getbal();

	void setfirst(string firstname);
	string getfirst();
	void setlast(string lastname);
	string getlast();

	void makedeposits(double depositAmount);
	void makewithdraw(double withdrawAmount);
	void statement();
	void writeCheck(int checkcounter);

	noSerivceChargeChecking();
	~noSerivceChargeChecking();

};

class highInterestchecking : public noSerivceChargeChecking
{
	double minbalance = 200.00;
	double interest = .05;
public:

	void setacct(int accountnum);
	int getacct();

	void setbal(int ammount);
	double getbal();

	void setfirst(string firstname);
	string getfirst();
	void setlast(string lastname);
	string getlast();

	void makedeposits(double depositAmount);
	void makewithdraw(double withdrawAmount);
	void statement();
	void writeCheck(int checkcounter);

	highInterestchecking();
	~highInterestchecking();

};


Now up to this point, I thought that the lower classes inherited everything from the upper classes. but I was trying to type out the set functions for my service charge checking, and its saying I don't have access to the variables for bank account.

Is there a way I can get access to them? Or do I have to create some local variables in each class instead?
Last edited on
Topic archived. No new replies allowed.