-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbankaccount program.cpp
More file actions
135 lines (116 loc) · 3.58 KB
/
bankaccount program.cpp
File metadata and controls
135 lines (116 loc) · 3.58 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class BankAccount
{
private:
string accountHolder;
int accountNumber;
string accountType;
double balance;
public:
// Default constructor
BankAccount()
{
accountHolder = "Neha Patil";
accountNumber = 987656;
accountType = "saving";
balance = 3000;
}
// Parameterized constructor
BankAccount(string holder, int number, string type, double bal)
{
accountHolder = holder;
accountNumber = number;
accountType = type;
balance = bal;
}
// Accessor methods
string getAccountHolder()
{
return accountHolder;
}
int getAccountNumber()
{
return accountNumber;
}
string getAccountType()
{
return accountType;
}
double getBalance()
{
return balance;
}
// method for account type
void setAccountType(string newType) { accountType = newType; }
// Deposit method with validation
void deposit(double amount)
{
if (amount > 0)
{
balance += amount;
cout << "Depositing "<< amount << "..." << endl;
cout << "New Balance: "<< balance << endl;
}
else
{
cout << "Invalid deposit amount!" << endl;
}
}
// Withdraw method with validation
void withdraw(double amount)
{
if (amount > 0 && amount <= balance)
{
balance -= amount;
cout << "Withdrawing " << amount << "..." << endl;
cout << "New Balance: "<< balance << endl;
}
else
{
cout << "Invalid withdrawal amount or insufficient funds!" << endl;
}
}
// Display formatted account details
void displayAccountDetails()
{
cout << "Account Details:" << endl;
cout << "Holder: " << accountHolder << endl;
cout << "Account Number: " << accountNumber << endl;
cout << "Type: " << accountType << endl;
cout << "Balance: " << fixed << setprecision(2) << balance << endl << endl;
}
};
int main()
{
// Default constructor
BankAccount defaultAcc;
cout<<"Calling Default Constructor !"<<endl<<endl;
//calling all Accessor methods
cout<<"Account Holder :- "<<defaultAcc.getAccountHolder()<<endl;
cout<<"Account Number :- "<<defaultAcc.getAccountNumber()<<endl;
cout<<"Account Type :- "<<defaultAcc.getAccountType()<<endl;
cout<<"Available Balance :- "<<defaultAcc.getBalance()<<endl<<endl;
defaultAcc.deposit(3000);
defaultAcc.withdraw(1000);
defaultAcc.setAccountType("current");
cout<<"Updated Account Type to Current."<<endl<< endl;
defaultAcc.displayAccountDetails();
// Parameterized constructor
BankAccount userAcc("Priya Patil", 123456, "Savings", 5000.00);
cout<<endl<<endl<<"Calling Parameterized Constructor!"<<endl<<endl;
//calling all Accessor methods
cout<<"Account Holder :- "<<userAcc.getAccountHolder()<<endl;
cout<<"Account Number :- "<<userAcc.getAccountNumber()<<endl;
cout<<"Account Type :- "<<userAcc.getAccountType()<<endl;
cout<<"Available Balance :- "<<userAcc.getBalance()<<endl<<endl;
userAcc.deposit(2000.00);
userAcc.withdraw(1500.00);
userAcc.setAccountType("Current");
cout << "Updated Account Type to Current." << endl << endl;
// Display all Account Display
userAcc.displayAccountDetails();
return 0;
}