-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.cpp
More file actions
37 lines (33 loc) · 895 Bytes
/
Account.cpp
File metadata and controls
37 lines (33 loc) · 895 Bytes
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
// Interface implementation of the Account class
#include <iostream>
#include "Account.h"
using namespace std;
// class constructor
Account::Account(int initialBalance){
if (initialBalance <= 0){
balance = 0;
cerr << "Invalid intial balance. Setting to 0." << endl;
}else {
balance = initialBalance;
}
}
// function to credit the current balance
void Account::credit(int creditAmount){
if (creditAmount <= 0){
cerr << "Invalid credit amount, balance unchanged." << endl;
}else{
balance += creditAmount;
}
}
// function to debit the current balance
void Account::debit(int debitAmount){
if (debitAmount > balance){
cerr << "Debit amount exceeded the account balance." << endl;
}else {
balance -= debitAmount;
}
}
// function to get the current balance
int Account::getBalance(){
return balance;
}