-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChecking.cpp
More file actions
72 lines (59 loc) · 2 KB
/
Checking.cpp
File metadata and controls
72 lines (59 loc) · 2 KB
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
// Checking.cpp
#include "Checking.h"
#include <iostream>
using namespace std;
// Constructor to initialize the Checking Account
Checking::Checking(long account_number, long card, int secCode, int pinNumber, double balance)
: Account(account_number, balance), cardNo(card), securityCode(secCode), pin(pinNumber) {}
// Withdraw money from the account
void Checking::withdraw(double amount) {
cout << "Enter pin number to proceed with withdrawal: ";
int enteredPin;
cin >> enteredPin;
if (pinError(enteredPin)) {
cout << "Incorrect pin! Withdrawal declined." << endl;
return;
}
if (amount > balance) {
cout << "Insufficient funds! Withdrawal declined." << endl;
} else {
balance -= amount;
cout << "Withdrawal of $" << amount << " successful!" << endl;
}
}
// Deposit money into the account
void Checking::deposit(double amount) {
balance += amount;
cout << "Deposit of $" << amount << " successful!" << endl;
}
// Transfer money to another Checking Account
void Checking::transfer(double amount, Account& recipient) {
cout << "Enter pin number to proceed with transfer: ";
int enteredPin;
cin >> enteredPin;
if (pinError(enteredPin)) {
cout << "Incorrect pin! Transfer declined." << endl;
return;
}
if (amount > balance) {
cout << "Insufficient funds! Transfer declined." << endl;
} else {
balance -= amount;
recipient.deposit(amount); // Add money to the recipient's account
cout << "Transfer of $" << amount << " successful!" << endl;
}
}
// Check if the entered pin is correct
bool Checking::pinError(int enteredPin) const {
return enteredPin != pin;
}
// Get the balance of the account
double Checking::getBalance() const {
return balance;
}
// Print the account information
void Checking::printAccountInfo() const {
cout << "Card Number: " << cardNo << endl;
cout << "Balance: $" << balance << endl;
cout << "Interest Rate: 0.02% APY" << endl;
}