BankAccount - need help with constructor and bool

do i need 2 constructors?
and can a boolean function return both true and another variable?

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
#include <iostream>

using namespace std;

class BankAccount
{
public:
    BankAccount();
    void readData();
    friend ostream& operator <<(ostream & out, BankAccount  BA );
    double update();
    bool withdraw(double Balance);
    int getNumber();
private:
    string Name;
    int Number;
    double Balance;
    double interestRate;
};
BankAccount::BankAccount()
{
    
}


void BankAccount::readData()
{
    cin >> Name >> Number >> Balance >> interestRate;
}

ostream& operator <<(ostream & out, BankAccount  BA )
{
        out << "Customer name: " << BA.Name << endl;
        out << "Customer number: " << BA.Number << endl;
        out << "Balance: " << BA.Balance << endl;
        out << "Interest rate: " << BA.interestRate << endl;
        out << endl;
        return out;
}

double BankAccount::update()
{
    Balance=Balance*interestRate/100+Balance;

    return Balance;
}

bool BankAccount::withdraw()
{

}

int BankAccount::getNumber()
{
    return Number;
}

int main()
{
	BankAccount account;
	account.readData();
	cout << account;
	account.update();
	cout << account;

	if (account.withdraw(32.5)) {
		cout << "Amount withdrawn for account " << account.getNumber() << endl;
	}
	else {
		cout << "Unable to withdraw from account " << account.getNumber() << endl;
	}

    cout << endl << account;

    return 0;
}
do i need 2 constructors?

You have one now. What is that second constructor that you are not sure of?

can a boolean function return both true and another variable?

A function can return only one object or reference. However, a function can have by reference parameters.

I'm only guessing why you do ask, so I say that there are more than one way to implement the functionality.
ahh of course pass by reference, thank you

if(head == NULL)
NodePtr temp = new IntNode(value, NULL);
head = temp;
else
NodePtr temp = new IntNode(value);
temp->link = head;
head = temp;
counter++;

if(head == NULL)
NodePtr temp = new IntNode(value, NULL);
head = temp;
else
NodePtr p = head;
while(p->link != NULL)
p = p->link;
p->link = new IntNode(value)
counter++;

if(head == NULL)
return;
else
for(NodePtr p = head; p != NULL; p = p->link){
if(p->link->data == value)
NodePtr temp = p->link;
p->link = temp->link;
delete temp;

if(node == NULL)
return;
else if(node->key == key)
remove_root(node);
else if(node->key < key)
remove(node->left, key);
else
remove(node->right, key)

if(node == NULL)
return;
else if(node->key == key)
remove_root(node);
else if(node->key < key)
remove(node->left, key);
else
remove(node->right, key);
NodePtr temp;
if(root->is_leaf())
delete root;
root = NULL;
else if(root->left == NULL)
temp = root->right;
delete root;
root = temp;
else if(root->right == NULL)
temp = root->left;
delete root;
root = temp;
else
NodePtr new_root = remove_min(root->right);
new_root->left = root->left;
new_root->right = root->right;
delete root;
root = new_root;

if(node->left == NULL)
NodePtr oldNode = node;
node = node->right;
return oldNode;
else
return remove_min(node->left);

capacity = capacity * 2;
int* newArray = new int[capacity];
for(int i = 0; i < count; ++i)
newArray[i] = array[i]
delete []array;
return newArray;
if(node == NULL)


return 0;


return(sizeHelp(node->left) + sizeHelp(node->right) + 1)

nodeptr,indent,prefix;
if(root == NULL)
return;
char letter = ' ';
if(root->is_leaf())
letter = root->letter;
cout << string(indent, ' ') << prefix << "(" << letter << " [" << root->frequency << "]";
if(root->is_leaf()) {
cout << ")" << endl;
else
cout << endl;
print_tree(root->left, indent + INDENT_SIZE, "0");
print_tree(root->right, indent + INDENT_SIZE, "1");
cout << string(indent, ' ') << ")" << endl;


if (aStack.empty()) {
topPtr = NULL;
else
topPtr = new CharStackFrame;
topPtr->data = (aStack.topPtr)->data;

newFramePtr = topPtr;
for (CharStackFramePtr originalPtr = (aStack.topPtr)->link;
originalPtr != NULL;
originalPtr = originalPtr->link)
newFramePtr->link = new CharStackFrame;
newFramePtr = newFramePtr->link;
newFramePtr->data = originalPtr->data;
newFramePtr->link = NULL;

while (!empty())
pop( );

return (topPtr == NULL);

CharStackFramePtr newFrame;
newFrame = new CharStackFrame;
newFrame->data = the_symbol;
newFrame->link = topPtr;
topPtr = newFrame;

if (empty())
throw EmptyStackException();
char result = topPtr->data;
CharStackFramePtr temp_ptr;
temp_ptr = topPtr;
topPtr = topPtr->link;
delete temp_ptr;
return result;

if (empty())
throw EmptyStackException();
return topPtr->data;

for (CharStackFramePtr iter = aStack.topPtr; iter != NULL; iter = iter->link) {
outs << (iter->data);
outs << endl;
return outs;
Last edited on
Topic archived. No new replies allowed.