9 file OOP help

i need help with an assignment. i have to build a OOP with Base class being Account and 2 derived class savings and checkings, another class called customer
i only want to worry about savings for now and ignore customer and checkings.
i am having trouble with the adjustBalance in Savings because it is suppose to adjust the balance by applying the interest, also when i ran the program its as if the makewithdrawal(this is suppose to check if the withdrawal can be made by checking if the amount is greater than balance which i dont know how to do) in savings does not affect the balance , at the end of the program only the unaffected deposited(makeDeposit) amount is shown sorry this is so confusing Thanks before Hand


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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//Test.cpp
#include <iostream>
#include <string>
using namespace std;
#include "Account.h"
//#include "checking.h"
#include "Savings.h"
//#include "savings.h"
const int MAX = 4;
void doTransactions(Account*);

int main()
{
	Account* acctsPtr[MAX];
	char acctType;
	bool validType = true;
	char custName[10];  //Alternative:  string custName;
	char acctID[6];                //Alternative:  string acctID;
	double startBal;

	int aNum;
	for (aNum = 0; aNum < MAX && validType; aNum++)
	{
		cout << "Enter c for checking; s for savings; any other character to quit: ";
		cin >> acctType;
		acctType = tolower(acctType);

		if (acctType == 'c' || acctType == 's')
		{
			cout << "Enter customer name: ";
			cin >> custName;
			cout << "Enter account number: ";
			cin >> acctID;
			cout << "Enter account beginning balance: ";
			cin >> startBal;

		}

		switch (acctType)
		{
		/*case 'c':
		{
					char response;
					bool overdraftOk;
					cout << "Does this account have overdraft protection? ";
					cin >> response;
					overdraftOk = (tolower(response) == 'y') ? true : false;
					Customer c(custName, acctID);
					acctsPtr[aNum] = new checking(c, startBal, overdraftOk);
					doTransactions(acctsPtr[aNum]);
					acctsPtr[aNum]->adjustBalance();
					cout << "Balance after service charge (if any): " <<
						acctsPtr[aNum]->getBalance() << endl;
					break;
		}
			*/
		case 's':
		{
					double intRate;
					cout << "Enter current monthly interest rate: ";
					cin >> intRate;
					//Customer c(custName, acctID);
					acctsPtr[aNum] = new Savings(startBal, intRate); //customer inside
					doTransactions(acctsPtr[aNum]);
					acctsPtr[aNum]->adjustBalance();
					cout << "Balance after interest: " <<
						acctsPtr[aNum]->getBalance() << endl;
					break;
		}
		
		default:
			validType = false;
			aNum--;
			break;
		}
	}

	int totalAccts = aNum;
	cout << "\nAccounts:\n";
	for (int i = 0; i < totalAccts; i++)
	{
		acctsPtr[i]->view();
		cout << "\n";
	}

	for (int i = 0; i < totalAccts; i++)
		delete acctsPtr[i];

	system("pause");
	return 0;
}

void doTransactions(Account * aPtr)
{
	double depAmt, withdAmt;

	cout << "Enter total deposits: ";
	cin >> depAmt;
	aPtr->makeDeposit(depAmt);
	cout << "Balance after deposits: "
		<< aPtr->getBalance() << endl;

	cout << "Enter total withdrawals: ";
	cin >> withdAmt;
	if (aPtr->makeWithdrawal(withdAmt))
		cout << "Balance after withdrawals: "
		<< aPtr->getBalance() << endl;
	else
		cout << "Withdrawal not made -- balance too low\n"
		<< " and no overdraft protection\n";

	
}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//account.h
#ifndef ACCOUNT_h
#define ACCOUNT_H
//#include "Customer.h"
class Account
{
	float balance;
	//Customer cust;
	//savings & checking subclass
public:
	Account();
	Account(float );//customer
	virtual void makeDeposit(float);//should call derived class first therefore virtual
	virtual bool makeWithdrawal(float);//should call derived class function first therefore virtual
	float getBalance();// not on any other class
	virtual void view();//calls customer view then displays balance
	virtual void adjustBalance();//nothing overriden in the subclasses

};
#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
account.cpp
//#include "Customer.h"
#include "Account.h"
//#include "Checking.h"
#include "Savings.h"
#include <iostream>
using namespace std;

Account::Account()
{
	balance = 0.00;
	//cust=null

}
Account::Account(float userbal /*Customer c*/)
{
	balance = userbal;
	//cust = c;

}

void  Account::makeDeposit(float dep)
{
	balance = balance + dep;
}
bool Account::makeWithdrawal(float withd)
{
		balance = balance - withd;
	

	return true;

}
float Account::getBalance()
{
	return balance;//returns to driver file
}
void Account::view()
{
	//Customer:Customer(view);//call customer view 
	cout << "current balance:" << balance;// display balance

}

void Account::adjustBalance()
{
	
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Savings.h
#ifndef SAVINGS_H
#define SAVINGS_H

class Savings : public Account
{
	Account balance;
	float interest;
public:
	Savings();//invokes Account no argument
	Savings(float,/*customer,*/ float);// 3 argument invokes account 2 argument and sets interest

	void makeDeposit(float);//calls account  makeDeposit passed the float
	bool makeWithdrawal(float);//determines whether withdrawal can be made\
								calls account makeWithdrawal passed float return true otherwise false
	
	void adjustBalance();//call account updates balance by applying interest rate supplied by user
	virtual void view();//display savings account  calls account view
	
};

#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

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

Savings::Savings()
{
Savings:Account::Account();
	interest = 0.00;

}
Savings::Savings(float bal, /*customer*/float intr) 
{
Savings:Account::Account(bal);
	interest = intr;
}

void Savings::makeDeposit(float dep)
{
	Account::makeDeposit(dep);
}
bool Savings::makeWithdrawal(float withd)
{
	if (0<withd)
	{
		return true;
	}
	else
		return false;

}
void Savings::adjustBalance()
{
	


}
void Savings::view()
{
	cout << "savings account\n";
Savings:Account::view();


}

Topic archived. No new replies allowed.