Inheritance question

Hey guys. I need to make a program with classes that a person would normally use for a bank account. I have the savings and checking account working (as can be seen below) but I also need to add a child class which will work as a CD (certificate of deposit) account. Basically, the class will put out a warning message if the money is withdrawn before a certain amount of time, and assess a percentage penalty (say, 10%) to the withdrawal. If someone could give me a hint/nudge in the right direction with this project, it would be greatly appreciated.

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
 //Account.h
#ifndef ACCOUNT_H
#define ACCOUNT_H

class Account
{
public:
	Account (double);
	void credit(double);
	bool debit(double); 
	
	void setBalance (double);
	double getBalance()const;
	void printBalance()const;

	



	
private:
	double balance;
};

#endif


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
//Account.cpp
#include <iostream>
using namespace std;
#include "Account.h"
Account::Account(double initialBalance)
{
	
	if(initialBalance>=0.0)
		balance=initialBalance;
	else
	{
		cout<<"Balance cannot be negative"<<endl;
			balance=0.0;
	}
}

void Account::credit(double amount)
{
	balance+=amount;
}
bool Account::debit (double amount)
{
	if (amount> balance)
	{
		cout<<"Debit is higher than account balance."<<endl;
		return false;
	}
	else
	{
		balance=-amount;
			return true;
	}
}

void Account::setBalance(double newBalance)
{
	balance=newBalance;
}

double Account::getBalance()const
{
	return balance;
}


void Account::printBalance()const
{
	cout<<"The initial balance is: " <<getBalance()<<endl;
}


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
//AccountDriver.cpp

#include <iostream>
#include "Account.h"
#include "SavingsAccount.h"
#include "CheckingAccount.h"
using namespace std;

int main()
{
	
	Account account1 (50.);
	SavingsAccount account2(2000., .05);
	CheckingAccount account3(500.,1000.);

	

	

	//cout<<"The account balance (plus interest) is: "<<account1.getBalance()+ account1.calculateInterest()<<endl;
	
	account1.printBalance();
	
	account2.printSavingsBalance();
	account2.printInterest();

	account3.credit(500);
	account3.debit(200);
	

	
	return 0;
}


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
//Possible CD header
// Create a CD account (1 yr) as a child of the account class, 
//(which will have a higher interest rate than the savings account) and
//will give the user a $ penalty for withdrawing money before a certain time period is 
//finished
//*No money can be deposited

#ifndef CD_H
#define CD_H

class CertificateOfDeposit:public Account
{
public:
	CertificateOfDeposit (double, double, double);

	
	void penalty(double);
	double calculateInterest()const;

	void print();

private:
	double fee;
	double rate;
	//double time;
};

#endif

bump?
Topic archived. No new replies allowed.