-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program to display atm transaction using class.cpp
70 lines (61 loc) · 1.67 KB
/
Program to display atm transaction using class.cpp
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
#include <iostream>
using namespace std;
class ATM {
private:
int balance;
public:
ATM(int b) {
balance = b;
}
void displayBalance() {
cout << "Current Balance: " << balance << endl;
}
void withdraw(int amount) {
if (amount > balance) {
cout << "Insufficient balance." << endl;
} else {
balance -= amount;
cout << "Withdrawn: " << amount << endl;
displayBalance();
}
}
void deposit(int amount) {
balance += amount;
cout << "Deposited: " << amount << endl;
displayBalance();
}
};
int main() {
ATM account(5000);
int choice, amount;
do {
cout << "1. Display Balance" << endl;
cout << "2. Withdraw" << endl;
cout << "3. Deposit" << endl;
cout << "4. Exit" << endl;
cout << "Enter choice: ";
cin >> choice;
switch(choice) {
case 1:
account.displayBalance();
break;
case 2:
cout << "Enter amount to withdraw: ";
cin >> amount;
account.withdraw(amount);
break;
case 3:
cout << "Enter amount to deposit: ";
cin >> amount;
account.deposit(amount);
break;
case 4:
cout << "Thank you for using our ATM!" << endl;
break;
default:
cout << "Invalid choice." << endl;
break;
}
} while(choice != 4);
return 0;
}