In my C++ class I am working on an assignment where I am supposed to create a class that represents accounts in a bank. I am told to create a data member of type int that represents the account's balance and to provide a constructor that receives the initial balance and initializes the data member. The constructor is also supposed to validate that the initial balance is greater than or equal to zero (otherwise, set the balance to 0 and display an error message).
I am supposed to provide 3 member functions:
1) Credit - adds to current balance
2) Debit - withdraws from current balance (and ensures that the balance does not overdraw. If it does, the balance should be set to 0 and display an error message)
3) getBalance - returns the current balance
My professor provided me with main() and I am not to change its functionality.
Unfortunately, after reading through the chapter in my textbook and looking on the internet, I am still at a loss of what to do.
Keep in mind, please, that this is a graded assignment and that I am only looking for hints and tips. Please don't post any code, as I would rather figure this out for myself, with some assistance.
If anybody could point me in the right direction I would be extremely grateful.
I recommend you take a look at the snippets provided there. Looking at snippets can really help with getting an idea of what to do. :)
Also, because I'm in a nice mood, here's a place to start.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
class money
{
int balance;
public:
money();
money(int);
void Credit(int);
void Debit(int);
int getBalance();
};
money::money(int temp)
{
//Implementation goes here.
}
int money::getBalance()
{
//You get the idea.
}