Base and derived classes.

Hi,
So I figured out my problem earlier, but now my code does not seem to print anything to console when I run it.

This is my main.cpp:
1
2
3
4
5
6
7
8
9
  int main()
{
    Checking checkAcct(100, 3, .2);
    Savings saveAcct(2000, 0.01);
    checkAcct.withdraw(10);
    checkAcct.printMonthlyStatement();
    saveAcct.printMonthlyStatement();

}


This is my base class:

1
2
3
4
5
6
7
8
9
10
11
12
13
class BankAccount {
protected:
	double balance;
public:
	BankAccount(double startingBalance)
		{ balance = startingBalance; }
	virtual ~BankAccount() {}
	virtual void deposit(double amt)
		{ balance += amt; }
	virtual void withdraw(double amt)
		{ balance -= amt; }
	virtual void printMonthlyStatement() = 0; // pure virtual function
};


This is a derived 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
29
30
Savings::Savings(double amt, double intRate) : BankAccount(amt) {
    interestRate = amt * intRate;
}

Savings::~Savings()
{
    //dtor
}

void Savings::applyInterest() {
    balance += interestRate;
}

void Savings::deposit(double amt) {
    BankAccount::deposit(amt);
}   // calls deposit from base class

void Savings::withdraw(double amt) {
    if (balance <= 0) {
        exit(0);
        cout << "Your balance is negative!" << endl;
    } else {
        BankAccount::withdraw(amt);
    }
}   // checks if enough funds before calling withdraw from base class

void Savings::printMonthlyStatement() {
    cout << "Savings statement: " << endl;
    cout << "Balance after interest: " << balance;
}// prints monthly statement after calculating the interest to update the balance 


I don't really see what ht problem is, I get no compiler error but just a blank console. Even if my variables have nothing shouldn't I still atleast get the " " printed?

Thank You!
Last edited on
Topic archived. No new replies allowed.